You are here

function menu_parent_options in Drupal 4

Same name and namespace in other branches
  1. 5 modules/menu/menu.module \menu_parent_options()
  2. 6 modules/menu/menu.module \menu_parent_options()
  3. 7 modules/menu/menu.module \menu_parent_options()

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.

2 calls to 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.

File

modules/menu.module, line 732
Allows administrators to customize the site navigation menu.

Code

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