menu_parent_options

  1. drupal
    1. 4.7
    2. 5 menu.module
    3. 6 menu.module
    4. 7 menu.module
Versions
4.7 – 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.

▾ 3 functions call menu_parent_options()

menu_edit_item_form in modules/menu.module
Present the menu item editing form.
menu_form_alter in modules/menu.module
Implementation of hook_form_alter(). Add menu item fields to the node form.
menu_parent_options in modules/menu.module
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.

Code

modules/menu.module, line 733

<?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;
}
?>