function menu_tree_add_active_path in Menu Block 7.2
Same name and namespace in other branches
- 6.2 menu_block.module \menu_tree_add_active_path()
- 7.3 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
array $tree: The menu tree.
1 call to menu_tree_add_active_path()
- menu_tree_block_data in ./
menu_block.module - Gets the data structure representing a menu tree for the given configuration.
File
- ./
menu_block.module, line 622 - Provides configurable blocks of menu items.
Code
function menu_tree_add_active_path(array &$tree) {
// Return if there are no menu items.
if (!$tree) {
return;
}
// 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 ($tree_with_trail as $key => &$value) {
if ($tree_with_trail[$key]['link']['in_active_trail'] && isset($subtree_pointer[$key])) {
// 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]);
}
}
}
}