_menu_append_contextual_items

Versions
4.6 – 5
_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.

Code

includes/menu.inc, line 911

<?php
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) {
    if (array_key_exists($item['path'], $_menu['path index'])) {
      // The menu item already exists, so just add appropriate callback information.
      $mid = $_menu['path index'][$item['path']];

      $_menu['items'][$mid]['access'] = $item['access'];
      $_menu['items'][$mid]['callback'] = $item['callback'];
      $_menu['items'][$mid]['callback arguments'] = $item['callback arguments'];
    }
    else {
      if (!array_key_exists('path', $item)) {
        $item['path'] = '';
      }
      if (!array_key_exists('type', $item)) {
        $item['type'] = MENU_NORMAL_ITEM;
      }
      if (!array_key_exists('weight', $item)) {
        $item['weight'] = 0;
      }
      $_menu['items'][$temp_mid] = $item;
      $_menu['path index'][$item['path']] = $temp_mid;
      $new_items[$temp_mid] = $item;
      $temp_mid--;
    }
  }

  // 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 && !array_key_exists($pid, $_menu['visible'])) {
        $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');
    }
  }
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.