function responsive_menu_tree_output in Responsive and off-canvas menu 7
Same name and namespace in other branches
- 7.3 includes/responsive_menu.menu.inc \responsive_menu_tree_output()
- 7.2 includes/responsive_menu.menu.inc \responsive_menu_tree_output()
Returns a renderable menu tree.
This is a copy of menu_tree_output() with parts stripped away.
Parameters
array $tree: A data structure representing the tree as returned from menu_tree_data.
string $menu_name: The menu name of the menu being rendered.
Return value
string The rendered HTML of that data structure.
2 calls to responsive_menu_tree_output()
- responsive_menu_page_build in ./
responsive_menu.module - Implements hook_page_build().
- responsive_menu_tree_build in includes/
responsive_menu.menu.inc - Build a menu tree based.
File
- includes/
responsive_menu.menu.inc, line 45 - Functions which process the menu.
Code
function responsive_menu_tree_output(&$tree, $menu_name) {
$build = array();
$items = array();
// Create context if no config was provided.
$config['delta'] = 0;
$config['menu_name'] = $menu_name;
// Pull out just the menu links we are going to render so that we
// get an accurate count for the first/last classes.
foreach ($tree as $key => &$value) {
if ($tree[$key]['link']['access'] && !$tree[$key]['link']['hidden']) {
$items[] = $tree[$key];
}
}
$router_item = menu_get_item();
$num_items = count($items);
foreach ($items as $i => &$data) {
$class = array();
if ($i == 0) {
$class[] = 'first';
}
if ($i == $num_items - 1) {
$class[] = 'last';
}
// Set a class for the <li>-tag. Since $data['below'] may contain local
// tasks, only set 'expanded' class if the link also has children within
// the current menu.
if ($data['link']['has_children'] && $data['below']) {
$class[] = 'expanded';
}
elseif ($data['link']['has_children']) {
$class[] = 'collapsed';
}
else {
$class[] = 'leaf';
}
if (!empty($data['link']['leaf_has_children'])) {
$class[] = 'has-children';
}
// Set a class if the link is in the active trail.
if ($data['link']['in_active_trail']) {
$class[] = 'active-trail';
$data['link']['localized_options']['attributes']['class'][] = 'active-trail';
}
// Determine whether this item should be shown as a fly-left flyout.
if ($data['below']) {
// Try to load the variable for this menu item to see whether to add the class.
if (variable_get('responsive_menu_flyleft_mlid:' . $data['link']['mlid'], FALSE)) {
$class[] = 'fly-left';
}
}
if ($data['link']['href'] == $_GET['q'] || $data['link']['href'] == '<front>' && drupal_is_front_page()) {
$class[] = 'active';
}
// Set a menu link ID class.
$class[] = 'menu-mlid-' . $data['link']['mlid'];
// Normally, l() compares the href of every link with $_GET['q'] and sets
// the active class accordingly. But local tasks do not appear in menu
// trees, so if the current path is a local task, and this link is its
// tab root, then we have to set the class manually.
if ($data['link']['href'] == $router_item['tab_root_href'] && $data['link']['href'] != $_GET['q']) {
$data['link']['localized_options']['attributes']['class'][] = 'active';
}
// Define the theme function for the menu link element.
$element['#theme'] = array(
'responsive_menu_link',
);
$element['#attributes']['class'] = $class;
$element['#title'] = $data['link']['title'];
$element['#href'] = $data['link']['href'];
$element['#localized_options'] = !empty($data['link']['localized_options']) ? $data['link']['localized_options'] : array();
$element['#below'] = $data['below'] ? responsive_menu_tree_output($data['below'], $config) : $data['below'];
$element['#original_link'] = $data['link'];
$element['#bid'] = array(
'module' => 'responsive_menu',
'delta' => $config['delta'],
);
// Index using the link's unique mlid.
$build[$data['link']['mlid']] = $element;
}
if ($build) {
// Make sure drupal_render() does not re-order the links.
$build['#sorted'] = TRUE;
// Add the theme wrapper for outer markup.
// Allow menu-specific theme overrides.
$build['#theme_wrappers'][] = array(
'responsive_menu_tree',
);
}
return $build;
}