function _menu_find_parents in Drupal 5
Same name and namespace in other branches
- 4 includes/menu.inc \_menu_find_parents()
Establish parent-child relationships.
2 calls to _menu_find_parents()
- _menu_append_contextual_items in includes/
menu.inc - Account for menu items that are only defined at certain paths, so will not be cached.
- _menu_build in includes/
menu.inc - Build the menu by querying both modules and the database.
File
- includes/
menu.inc, line 1298 - API for the Drupal menu system.
Code
function _menu_find_parents(&$items) {
global $_menu;
foreach ($items as $mid => $item) {
if (!isset($item['pid'])) {
// Parent's location has not been customized, so figure it out using the path.
$parent = $item['path'];
if ($parent) {
do {
$parent = substr($parent, 0, strrpos($parent, '/'));
} while ($parent && !isset($_menu['path index'][$parent]));
}
$pid = $parent ? $_menu['path index'][$parent] : 1;
$_menu['items'][$mid]['pid'] = $pid;
}
else {
$pid = $item['pid'];
}
// Don't make root a child of itself.
if ($mid) {
if (isset($_menu['items'][$pid])) {
$_menu['items'][$pid]['children'][] = $mid;
}
else {
// If parent is missing, it is a menu item that used to be defined
// but is no longer. Default to a root-level "Navigation" menu item.
$_menu['items'][1]['children'][] = $mid;
}
}
}
}