function _menu_tree_prune_active_tree in Menu Block 6.2
Same name and namespace in other branches
- 7.3 menu_block.follow.inc \_menu_tree_prune_active_tree()
- 7.2 menu_block.follow.inc \_menu_tree_prune_active_tree()
Prune a tree so that it begins at the active menu item.
Parameters
$tree: array The menu tree to prune.
$level: string The level which the tree will be pruned to: 'active' or 'child'.
Return value
void
1 call to _menu_tree_prune_active_tree()
- menu_tree_prune_active_tree in ./
menu_block.module - Prune a tree so that it begins at the active menu item.
File
- ./
menu_block.follow.inc, line 17 - Provides active menu item pruning.
Code
function _menu_tree_prune_active_tree(&$tree, $level) {
do {
$found_active_trail = FALSE;
// Examine each element at this level for the active trail.
foreach (array_keys($tree) as $key) {
if ($tree[$key]['link']['in_active_trail']) {
$found_active_trail = TRUE;
// If the active trail item has children, examine them.
if ($tree[$key]['below']) {
// If we are pruning to the active menu item's level, check if this
// is the active menu item by checking its children.
if ($level == 'active') {
foreach (array_keys($tree[$key]['below']) as $child_key) {
if ($tree[$key]['below'][$child_key]['link']['in_active_trail']) {
// Get the title for the pruned tree.
menu_block_set_title($tree[$key]['link']);
$tree = $tree[$key]['below'];
// Continue in the pruned tree.
break 2;
}
}
// If we've found the active item, we're done.
break 2;
}
// Set the title for the pruned tree.
menu_block_set_title($tree[$key]['link']);
// If we are pruning to the children of the active menu item, just
// prune the tree to the children of the item in the active trail.
$tree = $tree[$key]['below'];
// Continue in the pruned tree.
break;
}
else {
if ($level == 'child') {
$tree = array();
}
break 2;
}
}
}
} while ($found_active_trail);
}