You are here

function admin_menu_adjust_items in Administration menu 6

Same name and namespace in other branches
  1. 5.3 admin_menu.inc \admin_menu_adjust_items()
  2. 5 admin_menu.inc \admin_menu_adjust_items()
  3. 5.2 admin_menu.inc \admin_menu_adjust_items()

Add some hard-coded features for better user experience.

Parameters

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

array $sort: An array containing the # parts of each link - must be updated if a link is added.

Return value

An array of links that were removed from $menu_links.

1 call to admin_menu_adjust_items()
_admin_menu_rebuild_links in ./admin_menu.inc
The key function that builds the menu links whenever there is a menu rebuild.

File

./admin_menu.inc, line 315

Code

function admin_menu_adjust_items(&$menu_links, &$sort) {
  global $user;
  $links = array();
  $deleted = array();

  // Change or remove items, or add new top-level items.
  $deleted['admin/by-module'] = $menu_links['admin/by-module'];
  unset($menu_links['admin/by-module'], $sort['admin/by-module']);
  $deleted['admin/by-task'] = $menu_links['admin/by-task'];
  unset($menu_links['admin/by-task'], $sort['admin/by-task']);

  // Remove certain links to re-position them in admin_menu_admin_menu().
  foreach ($menu_links as $path => $link) {

    // Remove links below
    // - admin/content/node-type/*
    // - node/add*
    if (strpos($path, 'admin/content/node-type/') !== FALSE || strpos($path, 'node/add') !== FALSE) {
      $deleted[$path] = $link;
      unset($menu_links[$path], $sort[$path]);
    }
  }

  // Add the icon containing special links.
  $links[] = array(
    'title' => theme('admin_menu_icon'),
    'path' => '<front>',
    'weight' => -100,
    'parent_path' => '<root>',
    'options' => array(
      'extra class' => 'admin-menu-icon',
      'html' => TRUE,
    ),
  );

  // Add link to show current authenticated/anonymous users - we will add the
  // data dynamically in the _alter hook.
  $links[] = array(
    'title' => 'icon_users',
    'path' => 'user',
    'weight' => -90,
    'parent_path' => '<root>',
    'options' => array(
      'extra class' => 'admin-menu-action admin-menu-icon admin-menu-users',
      'html' => TRUE,
    ),
  );
  $links[] = array(
    'title' => 'Log out @username',
    'path' => 'logout',
    'weight' => -100,
    'parent_path' => '<root>',
    // Note: @username is dynamically replaced by default, we just invoke
    // replacement by setting the 't' key here.
    'options' => array(
      'extra class' => 'admin-menu-action admin-menu-logout',
      't' => array(),
    ),
  );
  foreach ($links as $item) {
    $path = $item['path'];
    $item = admin_menu_link_build($item);
    $menu_links[$path] = $item;
    $sort[$path] = 1;
  }
  return $deleted;
}