You are here

function admin_menu_adjust_items in Administration menu 5.2

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. 6 admin_menu.inc \admin_menu_adjust_items()

Add some hard-coded features for better user experience.

Parameters

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

1 call to admin_menu_adjust_items()
admin_menu_build in ./admin_menu.inc
Build the administration menu tree.

File

./admin_menu.inc, line 118
Cached builder functions for Drupal Administration Menu.

Code

function admin_menu_adjust_items(&$_admin_menu) {
  global $_menu, $user, $base_url;

  // Add the icon containing special links.
  $mid_admin = $_admin_menu['index']['admin'];
  $mid_icon = admin_menu_add_item($_admin_menu, $mid_admin, array(
    'title' => theme('admin_menu_icon'),
    'path' => drupal_get_normal_path(variable_get('site_frontpage', 'node')),
    'weight' => -100,
    'class' => 'admin-menu-icon',
  ));
  $_admin_menu['index']['admin_menu_icon'] = $mid_icon;

  // Add 'administer' item to the icon menu.
  $mid_icon_admin = admin_menu_add_item($_admin_menu, $mid_icon, array(
    'title' => t('Administer'),
    'path' => 'admin',
    'weight' => 10,
  ));

  // ...and reset 'administer' menu item id in path index.
  $_admin_menu['index']['admin'] = $mid_admin;

  // Move 'By module' item if accessible, or remove it.
  $mid_bymodule = $_admin_menu['index']['admin/by-module'];
  if (user_access('administer site configuration')) {
    admin_menu_move_item($_admin_menu, $mid_bymodule, $mid_icon_admin);
  }
  else {
    admin_menu_remove_item($_admin_menu, 'admin/by-module');
  }

  // Remove 'By task' menu item.
  admin_menu_remove_item($_admin_menu, 'admin/by-task');

  // Add system update links.
  admin_menu_add_item($_admin_menu, $mid_icon, array(
    'title' => t('Run cron'),
    'path' => 'admin/logs/status/run-cron',
    'weight' => 50,
    'query' => drupal_get_destination(),
  ));
  if ($user->uid == 1) {
    admin_menu_add_item($_admin_menu, $mid_icon, array(
      'title' => t('Run updates'),
      'path' => $base_url . '/update.php',
      'weight' => 50,
    ));
  }

  // Add developer modules toggle link.
  if (user_access('administer site configuration')) {
    $mid_icon = $_admin_menu['index']['admin_menu_icon'];
    $current_state = variable_get('admin_menu_devel_modules_enabled', NULL);
    admin_menu_add_item($_admin_menu, $mid_icon, array(
      'title' => isset($current_state) ? t('Enable developer modules') : t('Disable developer modules'),
      'path' => 'admin_menu/toggle-modules',
      'weight' => 88,
    ));
  }

  // Add links to drupal.org.
  if (user_access('display drupal links')) {
    $mid_drupal = admin_menu_add_item($_admin_menu, $mid_icon, array(
      'title' => t('Drupal.org'),
      'path' => 'http://drupal.org',
      'weight' => 100,
    ));
    admin_menu_add_item($_admin_menu, $mid_drupal, array(
      'title' => t('Drupal issue queue'),
      'path' => 'http://drupal.org/project/issues/drupal',
    ));

    // Add links to project issue queues.
    $projects = array();
    foreach (module_list(FALSE, FALSE, TRUE) as $module) {
      $info = _module_parse_info_file(drupal_get_path('module', $module) . '/' . $module . '.info');
      if (!isset($info['project']) || isset($info['project']) && ($info['project'] == 'drupal' || isset($projects[$info['project']]))) {
        continue;
      }
      $projects[$info['project']] = 1;
      $url = 'http://drupal.org/project/issues/' . $info['project'];

      // Filtering project versions via query string is not yet supported.
      // @see http://drupal.org/node/97569
      // $url .= !empty($info['version']) ? '/'. $info['version'] : '';
      admin_menu_add_item($_admin_menu, $mid_drupal, array(
        'title' => t('@title issue queue', array(
          '@title' => $info['name'],
        )),
        'path' => $url,
      ));
    }
  }

  // Add logout item.
  if ($user->uid > 0) {
    $mid_logout = $_menu['path index']['logout'];
    admin_menu_add_item($_admin_menu, $mid_admin, array(
      'title' => t('Logout @name', array(
        '@name' => $user->name,
      )),
      'path' => $_menu['items'][$mid_logout]['path'],
      'weight' => -100,
      'class' => 'admin-menu-action admin-menu-logout',
    ));
  }

  // Add 'Create <content_type>' menu items to Content management > Content.
  // If an user does not have 'administer nodes' permission, we need to copy
  // the 'Create content' item from the Navigation menu into 'Content
  // management' and append node/add/* items there instead.
  if (!user_access('administer nodes')) {
    $mid_content_management = $_admin_menu['index']['admin/content'];
    $mid_node_add = $_menu['path index']['node/add'];
    $create_content = $_menu['items'][$mid_node_add];
    $create_content['weight'] = 0;
    $mid_content = admin_menu_add_item($_admin_menu, $mid_content_management, $create_content);
  }
  else {
    $mid_content = $_admin_menu['index']['admin/content/node'];
  }
  $mid_node_add = $_menu['path index']['node/add'];
  admin_menu_copy_items($_admin_menu, $mid_node_add, $mid_content, t('Add !title'));

  // Add 'Edit <content_type>' menu items to Content management > Content types.
  if (module_exists('content') && user_access('administer content types')) {
    $mid_content_types = $_admin_menu['index']['admin/content/types'];
    $types = node_get_types();
    $names = node_get_types('names');
    foreach ($names as $key => $name) {
      $type = $types[$key];
      if (function_exists($type->module . '_form')) {
        admin_menu_add_item($_admin_menu, $mid_content_types, array(
          'title' => t('Edit !name', array(
            '!name' => $name,
          )),
          'path' => 'admin/content/types/' . str_replace('_', '-', $type->type) . '/fields',
          'weight' => -5,
        ));
      }
    }
  }

  // Add 'Edit <view>' menu items to Site building > Views.
  if (module_exists('views') && user_access('administer views')) {
    $mid_views_list = $_admin_menu['index']['admin/build/views/list'];
    $_admin_menu[$mid_views_list]['weight'] = -10;
    $mid_views = $_admin_menu['index']['admin/build/views'];
    $result = db_query("SELECT name FROM {view_view} ORDER BY name");
    while ($view = db_fetch_object($result)) {
      admin_menu_add_item($_admin_menu, $mid_views, array(
        'title' => t('Edit !name', array(
          '!name' => $view->name,
        )),
        'path' => "admin/build/views/{$view->name}/edit",
        'weight' => -5,
      ));
    }
  }

  // Add 'Edit <panel>' menu items to Panels.
  $modules = array(
    'panels_page' => array(
      'path' => 'admin/panels/panel-page/!name/edit/content',
      'parent' => 'admin/panels/panel-page',
      'perm' => 'create panel-pages',
    ),
    'panels_mini' => array(
      'path' => 'admin/panels/panel-mini/!name/edit/content',
      'parent' => 'admin/panels/panel-mini',
      'perm' => 'create mini panels',
    ),
    'panels_views' => array(
      'path' => 'admin/panels/views/edit/!name',
      'parent' => 'admin/panels/views',
      'perm' => 'administer panel views',
    ),
  );
  foreach ($modules as $module => $attribs) {
    if (user_access($attribs['perm'])) {
      $mid_panels = $_admin_menu['index'][$attribs['parent']];
      foreach ((array) module_invoke($module, 'load_all') as $panel) {
        if (empty($panel->disabled)) {
          admin_menu_add_item($_admin_menu, $mid_panels, array(
            'title' => t('Edit !name', array(
              '!name' => $panel->name,
            )),
            'path' => strtr($attribs['path'], array(
              '!name' => $panel->name,
            )),
            'weight' => -5,
          ));
        }
      }
    }
  }
}