1 system.menu.inc system_menu_tree_depth_trim(array &$tree, $depth_limit)

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.

File

core/modules/system/system.menu.inc, line 445
Menu block configuration form and display.

Code

function system_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) {
        system_menu_tree_depth_trim($tree[$key]['below'], $depth_limit - 1);
      }
      else {
        // Remove the children items.
        $tree[$key]['below'] = FALSE;
      }
    }
  }
}