You are here

function _menu_append_contextual_items in Drupal 5

Same name and namespace in other branches
  1. 4 includes/menu.inc \_menu_append_contextual_items()

Account for menu items that are only defined at certain paths, so will not be cached.

We don't support the full range of menu item options for these menu items. We don't support MENU_VISIBLE_IF_HAS_CHILDREN, and we require parent items to be declared before their children.

1 call to _menu_append_contextual_items()
menu_get_menu in includes/menu.inc
Return the menu data structure.

File

includes/menu.inc, line 1220
API for the Drupal menu system.

Code

function _menu_append_contextual_items() {
  global $_menu;

  // Build a sequential list of all menu items.
  $menu_item_list = module_invoke_all('menu', FALSE);

  // Menu items not in the DB get temporary negative IDs.
  $temp_mid = min(array_keys($_menu['items'])) - 1;
  $new_items = array();
  foreach ($menu_item_list as $item) {

    // Protect against D6 style access
    if (isset($item['access']) && is_array($item['access']) && count($item['access']) == 1 && isset($item['access'][0]) && is_string($item['access'][0])) {
      $item['access'] = FALSE;
    }
    if (isset($item['callback'])) {
      $_menu['callbacks'][$item['path']] = array(
        'callback' => $item['callback'],
      );
      if (isset($item['callback arguments'])) {
        $_menu['callbacks'][$item['path']]['callback arguments'] = $item['callback arguments'];
        unset($item['callback arguments']);
      }
      unset($item['callback']);
    }
    if (!isset($_menu['path index'][$item['path']])) {
      if (!isset($item['path'])) {
        $item['path'] = '';
      }
      if (!isset($item['type'])) {
        $item['type'] = MENU_NORMAL_ITEM;
      }
      if (!isset($item['weight'])) {
        $item['weight'] = 0;
      }
      $_menu['items'][$temp_mid] = $item;
      $_menu['path index'][$item['path']] = $temp_mid;
      $new_items[$temp_mid] = $item;
      $temp_mid--;
    }
    else {
      $mid = $_menu['path index'][$item['path']];
      if ($_menu['items'][$mid]['type'] & MENU_CREATED_BY_ADMIN) {
        $_menu['items'][$mid]['access'] = $item['access'];
        if (isset($_menu['items'][$mid]['callback'])) {
          $_menu['items'][$mid]['callback'] = $item['callback'];
        }
        if (isset($_menu['items'][$mid]['callback arguments'])) {
          $_menu['items'][$mid]['callback arguments'] = $item['callback arguments'];
        }
      }
      if ($item['type'] & MENU_LOCAL_TASK && !($_menu['items'][$mid]['type'] & MENU_LOCAL_TASK)) {

        // A local task is in the menu table and the path is already present
        $_menu['items'][$mid]['type'] = MENU_LOCAL_TASK;
        $new_items[$mid] = $item;
      }
    }
  }

  // Establish parent-child relationships.
  _menu_find_parents($new_items);

  // Add new items to the visible tree if necessary.
  foreach ($new_items as $mid => $item) {
    $item = $_menu['items'][$mid];
    if ($item['type'] & MENU_VISIBLE_IN_TREE && _menu_item_is_accessible($mid)) {
      $pid = $item['pid'];
      while ($pid && !isset($_menu['visible'][$pid])) {
        $pid = $_menu['items'][$pid]['pid'];
      }
      $_menu['visible'][$mid] = array(
        'title' => $item['title'],
        'path' => $item['path'],
        'pid' => $pid,
      );
      $_menu['visible'][$pid]['children'][] = $mid;
      usort($_menu['visible'][$pid]['children'], '_menu_sort');
    }
  }
}