Skip to content

Commit

Permalink
MDL-35654 theme_anomaly: Added custom menu renderer to aid RTL stylin…
Browse files Browse the repository at this point in the history
…g of menu
  • Loading branch information
Mary Evans committed Sep 28, 2012
1 parent 9273bd1 commit 14a695f
Show file tree
Hide file tree
Showing 8 changed files with 307 additions and 159 deletions.
2 changes: 1 addition & 1 deletion theme/anomaly/config.php
Expand Up @@ -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
////////////////////////////////////////////////////////////////////////////////
Expand Down
Binary file added theme/anomaly/pix/menu/nav-arrow-left.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added theme/anomaly/pix/menu/nav-arrow-right.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added theme/anomaly/pix/menu/nav-arrowover-left.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added theme/anomaly/pix/menu/nav-arrowover-right.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
85 changes: 85 additions & 0 deletions theme/anomaly/renderers.php
Expand Up @@ -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;
}

}

0 comments on commit 14a695f

Please sign in to comment.