function menu_block_tree in Menu Block 5.2
Same name and namespace in other branches
- 5 menu_block.module \menu_block_tree()
Returns a rendered menu tree or menu list.
Parameters
$pid: int The parent id of the menu.
$depth_limit: int The maximum depth of the returned tree, 0 for unlimited.
$expanded: boolean Whether to expand the entire menu tree.
Return value
string The rendered items of a menu.
1 call to menu_block_tree()
- theme_menu_block_tree in ./
menu_block.module - Generate the HTML for a menu tree.
File
- ./
menu_block.module, line 188 - Provides configurable blocks of menu items.
Code
function menu_block_tree($pid = 1, $depth_limit = 0, $expanded = FALSE) {
$menu = menu_get_menu();
$output = '';
if (isset($menu['visible'][$pid]) && $menu['visible'][$pid]['children']) {
$active_id = menu_get_active_item();
$count = 1;
$total_children = count($menu['visible'][$pid]['children']);
foreach ($menu['visible'][$pid]['children'] as $mid) {
// Theme the menu link
$in_active_trail = menu_in_active_trail_in_submenu($mid, $pid);
$item = menu_get_item($mid);
$item['attributes'] = array();
if (!empty($item['description'])) {
$item['attributes']['title'] = $item['description'];
}
if ($in_active_trail) {
$item['attributes']['class'] = 'active-trail';
}
while ($item['type'] & MENU_LINKS_TO_PARENT) {
// Weirdness in D5's menu system
$link_item = menu_get_item($item['pid']);
$item['path'] = $link_item['path'];
}
$link = theme('menu_block_item_link', $item);
// Theme the menu tree containing the children
$has_children = !empty($menu['visible'][$mid]['children']);
$children = '';
if ($has_children) {
$type = isset($menu['visible'][$mid]['type']) ? $menu['visible'][$mid]['type'] : FALSE;
if ($depth_limit != 1 && ($type & MENU_EXPANDED || $expanded || $in_active_trail)) {
$children = theme('menu_block_tree', $mid, $depth_limit ? $depth_limit - 1 : 0, $expanded);
}
}
// Theme the menu item
$extra_class = "menu-{$mid}";
$extra_class .= $count == 1 ? ' first' : '';
$extra_class .= $count == $total_children ? ' last' : '';
$extra_class .= $mid == $active_id || $item['path'] == '<front>' && drupal_is_front_page() ? ' active' : '';
$output .= theme('menu_block_item', $link, $has_children, $children, $in_active_trail, $extra_class);
$count++;
}
}
return $output;
}