You are here

function admin_menu_admin_menu in Administration menu 6

Same name and namespace in other branches
  1. 5.3 admin_menu.module \admin_menu_admin_menu()
  2. 5.2 admin_menu.module \admin_menu_admin_menu()

Implementation of hook_admin_menu().

Parameters

&$deleted: Array of links under admin/* that were removed by admin_menu_adjust_items(). If one of these links is added back, it should be removed from the array.

File

./admin_menu.inc, line 124

Code

function admin_menu_admin_menu(&$deleted) {
  $links = array();
  $icon_path = '<front>';

  // Add link to manually run cron.
  $links[] = array(
    'title' => 'Run cron',
    'path' => 'admin/reports/status/run-cron',
    'weight' => 50,
    'parent_path' => $icon_path,
  );

  // Add link to run update.php.
  $links[] = array(
    'title' => 'Run updates',
    'path' => 'update.php',
    'weight' => 50,
    'parent_path' => $icon_path,
    'options' => array(
      'external' => TRUE,
    ),
  );

  // Move 'By module' item into Site configuration.
  if (isset($deleted['admin/by-module'])) {
    $deleted['admin/by-module']['parent_path'] = 'admin/settings';
    $deleted['admin/by-module']['weight'] = -10;
    $links[] = $deleted['admin/by-module'];
    unset($deleted['admin/by-module']);
  }

  // Add link to drupal.org.
  $links[] = array(
    'title' => 'Drupal.org',
    'path' => 'http://drupal.org',
    'weight' => 100,
    'parent_path' => $icon_path,
  );

  // Add links to project issue queues.
  $links[] = array(
    'title' => 'Drupal issue queue',
    'path' => 'http://drupal.org/project/issues/drupal',
    'weight' => -10,
    'parent_path' => 'http://drupal.org',
  );
  $projects = array();
  foreach (module_list(FALSE, FALSE, TRUE) as $module) {
    $info = drupal_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'] : '';
    $links[] = array(
      'title' => check_plain($info['name']) . ' issue queue',
      'path' => $url,
      'parent_path' => 'http://drupal.org',
    );
  }

  // Add 'Create <content-type>' items to Content management menu.
  if (isset($deleted['node/add'])) {
    $deleted['node/add']['parent_path'] = 'admin/content';
    $deleted['node/add']['weight'] = 0;
    $links[] = $deleted['node/add'];
    unset($deleted['node/add']);
  }
  foreach ($deleted as $path => $item) {
    if (strpos($path, 'node/add') !== FALSE) {
      $links[] = $deleted[$path];
      unset($deleted[$path]);
    }
  }

  // Make sure longer paths are after shorter ones
  ksort($deleted);
  foreach (node_get_types('types', NULL, TRUE) as $type) {
    $type_url_str = str_replace('_', '-', $type->type);
    $type_path = 'admin/content/node-type/' . $type_url_str;
    $links[$type_path] = array(
      'title' => 'Edit !content-type',
      'path' => $type_path,
      'parent_path' => 'admin/content/types',
      'options' => array(
        't' => array(
          '!content-type' => $type->name,
        ),
      ),
    );
    unset($deleted[$type_path . '/edit']);

    // CCK and other modules adding to node types handled here.
    foreach ($deleted as $path => $item) {

      // Precise test needed to account for multiple content-types having the
      // same prefix in their name.
      if ($path === $type_path || strpos($path, $type_path . '/') === 0) {

        // Logically, parent path can never go shorter than $type_path.
        $i = $item['_number_parts'] - 1;
        do {
          $parent_path = implode('/', array_slice($item['_parts'], 0, $i));
          --$i;
        } while (!isset($links[$parent_path]) && $i);
        $item['parent_path'] = $parent_path;
        $links[$path] = $item;
        unset($deleted[$path]);
      }
    }
  }

  // Add clear-cache.
  $links[] = array(
    'title' => 'Flush all caches',
    'path' => 'admin_menu/flush-cache',
    'query' => 'destination',
    'weight' => 20,
    'parent_path' => $icon_path,
  );
  $caches = array(
    'admin_menu' => 'Administration menu',
    'cache' => 'Cache tables',
    'menu' => 'Menu',
    'requisites' => 'Page requisites',
    'theme' => 'Theme registry',
  );
  foreach ($caches as $name => $title) {
    $links[] = array(
      'title' => $title,
      'path' => 'admin_menu/flush-cache/' . $name,
      'query' => 'destination',
      'parent_path' => 'admin_menu/flush-cache',
    );
  }

  // Add devel module links
  if (module_exists('devel')) {

    // Add variable editor.
    $links[] = array(
      'title' => 'Variable editor',
      'path' => 'devel/variable',
      'weight' => 20,
      'parent_path' => $icon_path,
    );

    // Add switch_user items.
    if ($devel_user_links = module_invoke('devel', 'switch_user_list')) {
      foreach ($devel_user_links as $link) {
        if (is_array($link)) {
          $links[] = array(
            'title' => $link['title'],
            'description' => $link['attributes']['title'],
            'path' => $link['href'],
            'options' => array(
              'query' => $link['query'],
              'html' => !empty($link['html']),
            ),
            'parent_path' => 'logout',
          );
        }
        elseif (preg_match('!href="' . base_path() . '([^\\?]+)\\?([^"]+)" title="([^"]+)">((<em>)?[^<]+(</em>)?)!', $link, $match)) {
          $links[] = array(
            'title' => $match[4],
            'description' => $match[3],
            'path' => urldecode($match[1]),
            'weight' => 20,
            'query' => 'destination',
            'parent_path' => 'logout',
            'options' => array(
              'html' => TRUE,
            ),
          );
        }
      }
    }
  }

  // Add developer modules toggle link.
  $saved_state = variable_get('admin_menu_devel_modules_enabled', NULL);
  $links[] = array(
    'title' => isset($saved_state) ? t('Enable developer modules') : t('Disable developer modules'),
    'path' => 'admin_menu/toggle-modules',
    'weight' => 88,
    'parent_path' => $icon_path,
    'options' => array(
      'query' => 'destination',
    ),
  );
  return $links;
}