function _dhtml_menu_subtree in DHTML Menu 7
Same name and namespace in other branches
- 8 dhtml_menu.theme.inc \_dhtml_menu_subtree()
- 6.4 dhtml_menu.theme.inc \_dhtml_menu_subtree()
- 6.3 dhtml_menu.module \_dhtml_menu_subtree()
Traverses the menu tree and returns the sub-tree of the item indicated by the parameter.
Parameters
$menu_name: The internal name of the menu.
$mlid: The menu link ID.
Return value
The tree below the menu item, as a renderable array, or an empty array.
1 call to _dhtml_menu_subtree()
- dhtml_menu_preprocess_menu_link in ./
dhtml_menu.theme.inc - Preprocessor for menu_link. Adds the required HTML attributes and loads subtrees if necessary.
File
- ./
dhtml_menu.theme.inc, line 85 - dhtml_menu.theme.inc All functions related to generating the menu markup.
Code
function _dhtml_menu_subtree($menu_name, $mlid) {
static $index = array();
static $indexed = array();
// This looks expensive, but menu_tree_all_data uses static caching.
$tree = menu_tree_all_data($menu_name);
// Index the menu tree to find ancestor paths for each item.
if (!isset($indexed[$menu_name])) {
$index += _dhtml_menu_index($tree);
$indexed[$menu_name] = TRUE;
}
// If the menu tree does not contain this item, stop.
if (!isset($index[$mlid])) {
return array();
}
// Traverse the tree using the ancestor path.
foreach ($index[$mlid]['parents'] as $id) {
$key = $index[$id]['key'];
if (isset($tree[$key])) {
$tree = $tree[$key]['below'];
}
else {
return array();
}
}
// Go one level further to go below the current item.
$key = $index[$mlid]['key'];
return isset($tree[$key]) ? menu_tree_output($tree[$key]['below']) : array();
}