You are here

protected function LevelSetting::menu_bean_tree_prune_tree in Menu Bean 7

Prune a tree so that it begins at the specified level.

Mostly from menu_block

Parameters

$tree array: array The menu tree to prune.

$level: int The level of the original tree that will start the pruned tree.

1 call to LevelSetting::menu_bean_tree_prune_tree()
LevelSetting::alterTree in lib/Drupal/menu_bean/Setting/LevelSetting.php
Alters the menu tree

File

lib/Drupal/menu_bean/Setting/LevelSetting.php, line 65
Level Plugin class

Class

LevelSetting

Namespace

Drupal\menu_bean\Setting

Code

protected function menu_bean_tree_prune_tree(array &$tree, $level) {

  // Trim the upper levels down to the one desired.
  for ($i = 1; $i < $level; $i++) {
    $found_active_trail = FALSE;

    // Examine each element at this level for the active trail.
    foreach ($tree as $key => &$value) {
      if ($tree[$key]['link']['in_active_trail']) {

        // Get the title for the pruned tree.

        //menu_block_set_title($tree[$key]['link']);

        // Prune the tree to the children of the item in the active trail.
        $tree = $tree[$key]['below'] ? $tree[$key]['below'] : array();
        $found_active_trail = TRUE;
        break;
      }
    }

    // If we don't find the active trail, the active item isn't in the tree we want.
    if (!$found_active_trail) {
      $tree = array();
      break;
    }
  }
}