function menu_tree_add_active_path in Menu Block 6.2
Same name and namespace in other branches
- 7.3 menu_block.module \menu_tree_add_active_path()
- 7.2 menu_block.module \menu_tree_add_active_path()
Add the active trail indicators into the tree.
The data returned by menu_tree_page_data() has link['in_active_trail'] set to TRUE for each menu item in the active trail. The data returned from menu_tree_all_data() does not contain the active trail indicators. This is a helper function that adds it back in.
Parameters
$tree: array The menu tree.
Return value
void
1 call to menu_tree_add_active_path()
- menu_tree_build in ./
menu_block.module - Build a menu tree based on the provided configuration.
File
- ./
menu_block.module, line 430 - Provides configurable blocks of menu items.
Code
function menu_tree_add_active_path(&$tree) {
// Grab any menu item to find the menu_name for this tree.
$menu_item = current($tree);
$tree_with_trail = menu_tree_page_data($menu_item['link']['menu_name']);
// To traverse the original tree down the active trail, we use a pointer.
$subtree_pointer =& $tree;
// Find each key in the active trail.
while ($tree_with_trail) {
foreach (array_keys($tree_with_trail) as $key) {
if ($tree_with_trail[$key]['link']['in_active_trail']) {
// Set the active trail info in the original tree.
$subtree_pointer[$key]['link']['in_active_trail'] = TRUE;
// Continue in the subtree, if it exists.
$tree_with_trail =& $tree_with_trail[$key]['below'];
$subtree_pointer =& $subtree_pointer[$key]['below'];
break;
}
else {
unset($tree_with_trail[$key]);
}
}
}
}