You are here

function menu_bean_tree_add_active_path in Menu Bean 7

Add the active trail indicators into the tree.

The data returned by menu_tree_page_data() has link['in_active_trail'] set to TRUE for each menu item in the active trail. The data returned from menu_tree_all_data() does not contain the active trail indicators. This is a helper function that adds it back in.

From menu_block

Parameters

$tree: array The menu tree.

Return value

void void

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

File

./menu_bean.module, line 148
Bean Plugin definition

Code

function menu_bean_tree_add_active_path($tree) {

  // Grab any menu item to find the menu_name for this tree.
  $menu_item = current($tree);
  $tree_with_trail = menu_tree_page_data($menu_item['link']['menu_name']);

  // To traverse the original tree down the active trail, we use a pointer.
  $subtree_pointer =& $tree;

  // Find each key in the active trail.
  while ($tree_with_trail) {
    foreach ($tree_with_trail as $key => &$value) {
      if ($tree_with_trail[$key]['link']['in_active_trail']) {

        // Set the active trail info in the original tree.
        $subtree_pointer[$key]['link']['in_active_trail'] = TRUE;

        // Continue in the subtree, if it exists.
        $tree_with_trail =& $tree_with_trail[$key]['below'];
        $subtree_pointer =& $subtree_pointer[$key]['below'];
        break;
      }
      else {
        unset($tree_with_trail[$key]);
      }
    }
  }
}