You are here

function admin_menu_build in Administration menu 5.3

Same name and namespace in other branches
  1. 5.2 admin_menu.inc \admin_menu_build()

Rebuild administration menu links.

This is invoked whenever the menu is rebuilt.

Parameters

$_admin_menu: An array containing the complete administration menu structure, passed by reference.

$mid_admin: The menu item id to use for the administration menu.

See also

admin_menu_output()

1 call to admin_menu_build()
admin_menu_get_menu in ./admin_menu.module
Return administration menu from cache or rebuild it.

File

./admin_menu.inc, line 21
Menu build functions for Administration menu.

Code

function admin_menu_build(&$_admin_menu) {
  global $_menu;
  $_admin_menu = array();

  // Get item id of /q=admin, which we suppose to be the root for admin menu.
  $mid_admin = $_menu['path index']['admin'];

  // Fix access permissions for root (category) menu items in Drupal core.
  foreach ($_menu['items'][$mid_admin]['children'] as $pid) {

    // Nothing to do, if item is accessible or contains no children.
    if (!isset($_menu['items'][$pid]['access']) || $_menu['items'][$pid]['access'] != FALSE || !isset($_menu['items'][$pid]['children'])) {
      continue;
    }

    // Make parent accessible if there is any accessible second level child.
    $is_accessible = FALSE;
    foreach ($_menu['items'][$pid]['children'] as $child) {
      if ($_menu['items'][$child]['access'] == TRUE) {
        $is_accessible = TRUE;
      }
    }
    if ($is_accessible) {

      // Since we are overriding system.module's real access values and many
      // modules simply depend on its ill access permissions ('administer site
      // configuration'), we assign not TRUE, but the integer 1 instead, so
      // _admin_menu_get_children() is able to properly inherit access
      // permissions for sub-items that do not define access.
      $_menu['items'][$pid]['access'] = 1;
    }
  }

  // Copy admin menu items into a new menu tree.
  $_admin_menu['index'] = $_menu['path index'];
  $_admin_menu[$mid_admin] = $_menu['items'][$mid_admin];
  admin_menu_item_url($_admin_menu, $mid_admin);
  _admin_menu_get_children($_admin_menu, $_admin_menu[$mid_admin]);

  // Sort items.
  usort($_admin_menu[$mid_admin]['children'], '_admin_menu_sort');

  // Adjust some menu items for better user experience.
  admin_menu_adjust_items($_admin_menu);

  // Allow other modules to integrate with admin_menu.
  foreach (module_implements('admin_menu') as $module) {
    $function = $module . '_admin_menu';
    $function($_admin_menu, TRUE);
  }
}