function menu_tree_depth_trim in Menu Block 7.3
Same name and namespace in other branches
- 6.2 menu_block.module \menu_tree_depth_trim()
- 7.2 menu_block.module \menu_tree_depth_trim()
Prune a tree so it does not extend beyond the specified depth limit.
Parameters
array $tree: The menu tree to prune.
int $depth_limit: The maximum depth of the returned tree; must be a positive integer.
1 call to menu_tree_depth_trim()
- 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 753 - Provides configurable blocks of menu items.
Code
function menu_tree_depth_trim(array &$tree, $depth_limit) {
// Prevent invalid input from returning a trimmed tree.
if ($depth_limit < 1) {
return;
}
// Examine each element at this level to find any possible children.
foreach ($tree as $key => &$value) {
if ($tree[$key]['below']) {
if ($depth_limit > 1) {
menu_tree_depth_trim($tree[$key]['below'], $depth_limit - 1);
}
else {
// Remove the children items.
$tree[$key]['below'] = FALSE;
}
}
if ($depth_limit == 1 && $tree[$key]['link']['has_children']) {
// Turn off the menu styling that shows there were children.
$tree[$key]['link']['has_children'] = FALSE;
$tree[$key]['link']['leaf_has_children'] = TRUE;
}
}
}