You are here

function _custom_breadcrumbs_menu_subtree in Custom Breadcrumbs 6.2

Same name and namespace in other branches
  1. 7.2 custom_breadcrumbs.module \_custom_breadcrumbs_menu_subtree()

Traverses the menu tree and returns the sub-tree of the item indicated by the parameter.

Parameters

$stack: An array of menu item links that are nested in each other in the tree.

Return value

The items below the lowest item in the stack.

1 call to _custom_breadcrumbs_menu_subtree()
custom_breadcrumbs_theme_menu_item in ./custom_breadcrumbs.module

File

./custom_breadcrumbs.module, line 1021
Provide custom breadcrumbs for node-type pages and base functionality for submodules to add custom breadcrumbs for other types of pages.

Code

function _custom_breadcrumbs_menu_subtree($item) {
  static $index = array();
  static $indexed = array();

  // This looks expensive, but menu_tree_all_data uses static caching.
  $tree = menu_tree_all_data($item['menu_name']);
  if (!isset($indexed[$item['menu_name']])) {
    $index += _custom_breadcrumbs_menu_index($tree);
    $indexed[$item['menu_name']] = TRUE;
  }

  // Traverse the tree.
  foreach ($index[$item['mlid']]['parents'] as $mlid) {
    $key = $index[$mlid]['key'];
    if (!isset($tree[$key])) {
      return array();
    }
    $tree = $tree[$key]['below'];
  }
  $key = $index[$item['mlid']]['key'];
  return isset($tree[$key]) ? $tree[$key]['below'] : array();
}