function responsive_menu_tree_depth_trim in Responsive and off-canvas menu 7
Same name in this branch
- 7 includes/responsive_menu.admin.inc \responsive_menu_tree_depth_trim()
- 7 includes/responsive_menu.menu.inc \responsive_menu_tree_depth_trim()
Same name and namespace in other branches
- 7.3 includes/responsive_menu.menu.inc \responsive_menu_tree_depth_trim()
- 7.2 includes/responsive_menu.menu.inc \responsive_menu_tree_depth_trim()
Prune a tree so it does not extend beyond the specified depth limit.
Parameters
$tree: array The menu tree to prune.
$depth_limit: int The maximum depth of the returned tree; must be a positive integer.
Return value
void
1 call to responsive_menu_tree_depth_trim()
- responsive_menu_tree_block_data in includes/
responsive_menu.menu.inc - Gets the data structure representing a menu tree for the given configuration.
File
- includes/
responsive_menu.menu.inc, line 200 - Functions which process the menu.
Code
function responsive_menu_tree_depth_trim(&$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) {
responsive_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;
}
}
}