Permalink
Browse files

MDL-35654 theme_anomaly: Added custom menu renderer to aid RTL stylin…

…g of menu
  • Loading branch information...
lazydaisy committed Sep 28, 2012
1 parent 9273bd1 commit 14a695f6077a2fc9fe6b36143eb6ecfae0ef230a
View
@@ -7,7 +7,7 @@
$THEME->name = 'anomaly';
-$THEME->sheets = array('base', 'general', 'browser','dock');
+$THEME->sheets = array('base', 'general', 'browser', 'dock', 'menu');
/// This variable is an array containing the names of all the
/// stylesheet files you want included in this theme, and in what order
////////////////////////////////////////////////////////////////////////////////
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -81,4 +81,89 @@ function block(block_contents $bc, $region) {
return $output;
}
+ /**
+ * Renders a custom menu object (located in outputcomponents.php)
+ *
+ * The custom menu this method override the render_custom_menu function
+ * in outputrenderers.php
+ * @staticvar int $menucount
+ * @param custom_menu $menu
+ * @return string
+ */
+ protected function render_custom_menu(custom_menu $menu) {
+
+ // If the menu has no children return an empty string
+ if (!$menu->has_children()) {
+ return '';
+ }
+
+ // Add a login or logout link
+ if (isloggedin()) {
+ $branchlabel = get_string('logout');
+ $branchurl = new moodle_url('/login/logout.php');
+ } else {
+ $branchlabel = get_string('login');
+ $branchurl = new moodle_url('/login/index.php');
+ }
+ $branch = $menu->add($branchlabel, $branchurl, $branchlabel, -1);
+
+ // Initialise this custom menu
+ $content = html_writer::start_tag('ul', array('class'=>'dropdown dropdown-horizontal'));
+ // Render each child
+ foreach ($menu->get_children() as $item) {
+ $content .= $this->render_custom_menu_item($item);
+ }
+ // Close the open tags
+ $content .= html_writer::end_tag('ul');
+ // Return the custom menu
+ return $content;
+ }
+
+ /**
+ * Renders a custom menu node as part of a submenu
+ *
+ * The custom menu this method override the render_custom_menu_item function
+ * in outputrenderers.php
+ *
+ * @see render_custom_menu()
+ *
+ * @staticvar int $submenucount
+ * @param custom_menu_item $menunode
+ * @return string
+ */
+ protected function render_custom_menu_item(custom_menu_item $menunode) {
+ // Required to ensure we get unique trackable id's
+ static $submenucount = 0;
+ $content = html_writer::start_tag('li');
+ if ($menunode->has_children()) {
+ // If the child has menus render it as a sub menu
+ $submenucount++;
+ if ($menunode->get_url() !== null) {
+ $url = $menunode->get_url();
+ } else {
+ $url = '#cm_submenu_'.$submenucount;
+ }
+ $content .= html_writer::start_tag('span', array('class'=>'customitem'));
+ $content .= html_writer::link($url, $menunode->get_text(), array('title'=>$menunode->get_title()));
+ $content .= html_writer::end_tag('span');
+ $content .= html_writer::start_tag('ul');
+ foreach ($menunode->get_children() as $menunode) {
+ $content .= $this->render_custom_menu_item($menunode);
+ }
+ $content .= html_writer::end_tag('ul');
+ } else {
+ // The node doesn't have children so produce a final menuitem
+
+ if ($menunode->get_url() !== null) {
+ $url = $menunode->get_url();
+ } else {
+ $url = '#';
+ }
+ $content .= html_writer::link($url, $menunode->get_text(), array('title'=>$menunode->get_title()));
+ }
+ $content .= html_writer::end_tag('li');
+ // Return the sub menu
+ return $content;
+ }
+
}
Oops, something went wrong.

0 comments on commit 14a695f

Please sign in to comment.