| Versions | |
|---|---|
| 4.7 – 5 | menu_parent_options( |
| 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.
$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.
An array of menu titles keyed on the mid.
modules/
<?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 ($parent_item['children']) {
usort($parent_item['children'], '_menu_sort');
foreach ($parent_item['children'] as $child) {
$options += menu_parent_options($mid, $child, $depth);
}
}
return $options;
}
?>