You are here

function _admin_menu_rebuild_links in Administration menu 6

The key function that builds the menu links whenever there is a menu rebuild.

1 call to _admin_menu_rebuild_links()
admin_menu_exit in ./admin_menu.module
Implementation of hook_exit().

File

./admin_menu.inc, line 6

Code

function _admin_menu_rebuild_links() {
  $menu = NULL;

  // Since it's possible this core function might change, check
  // that it exists. We do this instead of calling menu_router_build()
  // since that may trigger another menu rebuild that is not protected
  // by the lock API.
  if (function_exists('_menu_router_cache')) {

    // Get the newly rebuilt menu.
    $menu = _menu_router_cache();
  }
  else {
    $menu = menu_router_build();
  }
  if (!$menu) {

    // Something went wrong. Don't risk triggering another menu rebuild.
    return;
  }

  // Add normal and suggested items as links.
  $menu_links = array();
  foreach ($menu as $path => $item) {

    // Exclude menu callbacks, include items below admin/* and node/add/*.
    if ($item['type'] != MENU_CALLBACK && ($item['_parts'][0] == 'admin' && count($item['_parts']) > 1 || strpos($path, 'node/add') === 0)) {

      // TODO: handle local tasks with wildcards
      if (!strpos($path, '%')) {
        $item = admin_menu_link_build($item);
        $menu_links[$path] = $item;
        $sort[$path] = $item['_number_parts'];
      }
    }
  }
  $deleted = admin_menu_adjust_items($menu_links, $sort);
  if ($menu_links) {

    // Make sure no child comes before its parent.
    array_multisort($sort, SORT_NUMERIC, $menu_links);
    foreach ($menu_links as $item) {
      admin_menu_link_save($item);
    }
  }

  // Allow modules to add more links. If you want to alter links saved by
  // admin_menu, use hook_menu_link_alter() and look for
  // $item['module'] == 'admin_menu'
  $links = array();
  foreach (module_implements('admin_menu') as $module) {
    $function = $module . '_admin_menu';
    $links = array_merge_recursive($links, $function($deleted));
  }
  foreach ($links as $item) {
    admin_menu_link_save($item);
  }
}