Merge branch '23178-29' of git://github.com/samhemelryk/moodle
authorEloy Lafuente (stronk7) <stronk7@moodle.org>
Tue, 2 Dec 2014 23:06:46 +0000 (00:06 +0100)
committerDan Poltawski <dan@moodle.com>
Thu, 4 Dec 2014 12:14:28 +0000 (12:14 +0000)
blocks/site_main_menu/block_site_main_menu.php
blocks/site_main_menu/styles.css

index a84e3d1..e28c75b 100644 (file)
@@ -56,26 +56,36 @@ class block_site_main_menu extends block_list {
         if (!$isediting) {
             $modinfo = get_fast_modinfo($course);
             if (!empty($modinfo->sections[0])) {
-                $options = array('overflowdiv'=>true);
                 foreach($modinfo->sections[0] as $cmid) {
                     $cm = $modinfo->cms[$cmid];
                     if (!$cm->uservisible) {
                         continue;
                     }
 
-                    $content = $cm->get_formatted_content(array('overflowdiv' => true, 'noclean' => true));
-                    $instancename = $cm->get_formatted_name();
-
-                    if (!($url = $cm->url)) {
-                        $this->content->items[] = $content;
-                        $this->content->icons[] = '';
+                    if ($cm->indent > 0) {
+                        $indent = '<div class="mod-indent mod-indent-'.$cm->indent.'"></div>';
                     } else {
-                        $linkcss = $cm->visible ? '' : ' class="dimmed" ';
-                        //Accessibility: incidental image - should be empty Alt text
+                        $indent = '';
+                    }
+
+                    if (!empty($cm->url)) {
+                        $attrs = array();
+                        $attrs['title'] = $cm->modfullname;
+                        $attrs['class'] = $cm->extraclasses . ' activity-action';
+                        if ($cm->onclick) {
+                            $attrs['id'] = html_writer::random_id('onclick');
+                            $OUTPUT->add_action_handler(new component_action('click', $cm->onclick), $attrs['id']);
+                        }
+                        if (!$cm->visible) {
+                            $attrs['class'] .= ' dimmed';
+                        }
                         $icon = '<img src="' . $cm->get_icon_url() . '" class="icon" alt="" />';
-                        $this->content->items[] = '<a title="'.$cm->modplural.'" '.$linkcss.' '.$cm->extra.
-                                ' href="' . $url . '">' . $icon . $instancename . '</a>';
+                        $content = html_writer::link($cm->url, $icon . $cm->get_formatted_name(), $attrs);
+                    } else {
+                        $content = $cm->get_formatted_content(array('overflowdiv' => true, 'noclean' => true));
                     }
+
+                    $this->content->items[] = $indent.html_writer::div($content, 'main-menu-content');
                 }
             }
             return $this->content;
@@ -112,7 +122,7 @@ class block_site_main_menu extends block_list {
                     continue;
                 }
                 if (!$ismoving) {
-                    $actions = course_get_cm_edit_actions($mod, -1);
+                    $actions = course_get_cm_edit_actions($mod, $mod->indent);
 
                     // Prepend list of actions with the 'move' action.
                     $actions = array('move' => new action_menu_link_primary(
@@ -137,19 +147,31 @@ class block_site_main_menu extends block_list {
                             '<img style="height:16px; width:80px; border:0px" src="'.$OUTPUT->pix_url('movehere') . '" alt="'.$strmovehere.'" /></a>';
                         $this->content->icons[] = '';
                     }
-                    $content = $mod->get_formatted_content(array('overflowdiv' => true, 'noclean' => true));
-                    $instancename = $mod->get_formatted_name();
-                    $linkcss = $mod->visible ? '' : ' class="dimmed" ';
-
-                    if (!($url = $mod->url)) {
-                        $this->content->items[] = $content . $editbuttons;
-                        $this->content->icons[] = '';
+                    if ($mod->indent > 0) {
+                        $indent = '<div class="mod-indent mod-indent-'.$mod->indent.'"></div>';
+                    } else {
+                        $indent = '';
+                    }
+                    $url = $mod->url;
+                    if (!$url) {
+                        $content = $mod->get_formatted_content(array('overflowdiv' => true, 'noclean' => true));
                     } else {
                         //Accessibility: incidental image - should be empty Alt text
+                        $attrs = array();
+                        $attrs['title'] = $mod->modfullname;
+                        $attrs['class'] = $mod->extraclasses . ' activity-action';
+                        if ($mod->onclick) {
+                            $attrs['id'] = html_writer::random_id('onclick');
+                            $OUTPUT->add_action_handler(new component_action('click', $mod->onclick), $attrs['id']);
+                        }
+                        if (!$mod->visible) {
+                            $attrs['class'] .= ' dimmed';
+                        }
+
                         $icon = '<img src="' . $mod->get_icon_url() . '" class="icon" alt="" />';
-                        $this->content->items[] = '<a title="' . $mod->modfullname . '" ' . $linkcss . ' ' . $mod->extra .
-                            ' href="' . $url . '">' . $icon . $instancename . '</a>' . $editbuttons;
+                        $content = html_writer::link($url, $icon . $mod->get_formatted_name(), $attrs);
                     }
+                    $this->content->items[] = $indent.html_writer::div($content . $editbuttons, 'main-menu-content');
                 }
             }
         }
index dd8f92f..0e15ab7 100644 (file)
@@ -5,3 +5,6 @@
 .block_site_main_menu li .buttons a img{ vertical-align: text-bottom;}
 .block_site_main_menu .footer { margin-top: 1em; }
 .block_site_main_menu .section_add_menus noscript div { display: inline;}
+.block_site_main_menu .mod-indent,
+.block_site_main_menu .main-menu-content { display: table-cell; }
+.block_site_main_menu .main-menu-content > .activity-action { display: block; }