menu_parent_options
- Versions
- 4.6 – 5
menu_parent_options($mid,$pid= 0,$depth= 0)- 6 – 7
menu_parent_options($menus, $item)
Return a list of menu items that are valid possible parents for the given menu item. The list excludes the given item and its children.
Parameters
$mid The menu item id for which to generate a list of parents. If $mid == 0 then the complete tree is returned.
$pid The menu item id of the menu item at which to start the tree. If $pid > 0 then this item will be included in the tree.
$depth The current depth in the tree - used when recursing to indent the tree.
Return value
An array of menu titles keyed on the mid.
Code
modules/menu/menu.module, line 740
<?php
function menu_parent_options($mid, $pid = 0, $depth = 0) {
$options = array();
if (!($parent_item = menu_get_item($pid))) {
return $options;
}
// Exclude $mid and its children from the list unless $mid is 0.
if ($mid && $mid == $pid) {
return $options;
}
// Add the current $pid to the list.
if ($pid > 0 && ($parent_item['type'] & (MENU_MODIFIABLE_BY_ADMIN | MENU_IS_ROOT))) {
$title = ' '. $parent_item['title'];
for ($i = 0; $i < $depth; $i++) {
$title = '--'. $title;
}
if (!($parent_item['type'] & MENU_VISIBLE_IN_TREE)) {
$title .= ' ('. t('disabled') .')';
}
$options[$pid] = $title;
$depth ++;
}
// Add children of $pid to the list recursively.
if (isset($parent_item['children'])) {
usort($parent_item['children'], '_menu_sort');
foreach ($parent_item['children'] as $child) {
$options += menu_parent_options($mid, $child, $depth);
}
}
return $options;
}
?>Login or register to post comments 