You are here

function admin_menu_menu in Administration menu 5.3

Same name and namespace in other branches
  1. 8.3 admin_menu.module \admin_menu_menu()
  2. 5 admin_menu.module \admin_menu_menu()
  3. 5.2 admin_menu.module \admin_menu_menu()
  4. 6.3 admin_menu.module \admin_menu_menu()
  5. 6 admin_menu.module \admin_menu_menu()
  6. 7.3 admin_menu.module \admin_menu_menu()

Implementation of hook_menu().

We can't move this into admin_menu_footer(), because PHP-only based themes like chameleon load and output scripts and stylesheets in front of theme_closure(), so we ensure Admin menu's styles and scripts are loaded on all pages via hook_menu().

File

./admin_menu.module, line 44
Render an administrative menu as a dropdown menu at the top of the window.

Code

function admin_menu_menu($may_cache) {
  $items = array();
  if ($may_cache) {

    // AJAX callback.
    $items[] = array(
      'path' => 'js/admin_menu/cache',
      'callback' => 'admin_menu_js_cache',
      'access' => user_access('access administration menu'),
      'type' => MENU_CALLBACK,
    );

    // Module settings.
    $items[] = array(
      'path' => 'admin/settings/admin_menu',
      'title' => t('Administration menu'),
      'description' => t('Adjust administration menu settings.'),
      'callback' => 'drupal_get_form',
      'callback arguments' => array(
        'admin_menu_theme_settings',
      ),
      'access' => user_access('administer site configuration'),
    );

    // Menu link callbacks.
    $items[] = array(
      'path' => 'admin_menu/toggle-modules',
      'callback' => 'admin_menu_toggle_modules',
      'access' => user_access('administer site configuration'),
      'type' => MENU_CALLBACK,
    );
    admin_menu_clear_cache();
    return $items;
  }
  if (!user_access('access administration menu') || admin_menu_suppress(FALSE)) {
    return $items;
  }

  // Performance: Skip this entirely for AJAX requests.
  if (strpos($_GET['q'], 'js/') === 0) {
    return $items;
  }
  global $user, $locale;
  $path = drupal_get_path('module', 'admin_menu');
  drupal_add_css($path . '/admin_menu.css', 'module', 'all', FALSE);
  if ($user->uid == 1) {
    drupal_add_css($path . '/admin_menu.uid1.css', 'module', 'all', FALSE);
  }

  // Performance: Defer execution.
  drupal_add_js($path . '/admin_menu.js', 'module', 'header', TRUE);

  // Destination query strings are applied via JS.
  // @see drupal_get_destination()
  $url_path = isset($_GET['q']) ? $_GET['q'] : '';
  $url_query = drupal_query_string_encode($_GET, array(
    'q',
  ));
  if ($url_query != '') {
    $url_path .= '?' . $url_query;
  }
  $settings['destination'] = 'destination=' . urlencode($url_path);

  // Hash for client-side HTTP/AJAX caching.
  $cid = 'admin_menu:' . $user->uid . ':' . $locale;
  if (!empty($_COOKIE['has_js']) && ($hash = admin_menu_cache_get($cid))) {
    $settings['hash'] = $hash;

    // The base path to use for cache requests depends on whether clean URLs
    // are enabled, whether Drupal runs in a sub-directory, and on the language
    // system configuration. url() already provides us the proper path and also
    // invokes potentially existing custom_url_rewrite() functions, which may
    // add further required components to the URL to provide context. Due to
    // those components, and since url('') returns only base_path() when clean
    // URLs are disabled, we need to use a replacement token as path.  Yuck.
    $settings['basePath'] = url('admin_menu');
  }
  $replacements = module_invoke_all('admin_menu_replacements');
  if (!empty($replacements)) {
    $settings['replacements'] = $replacements;
  }
  if ($setting = variable_get('admin_menu_margin_top', 1)) {
    $settings['margin_top'] = $setting;
  }
  if ($setting = variable_get('admin_menu_position_fixed', 0)) {
    $settings['position_fixed'] = $setting;
  }
  if ($setting = variable_get('admin_menu_tweak_tabs', 0)) {
    $settings['tweak_tabs'] = $setting;
  }
  if ($_GET['q'] == 'admin/build/menu' && variable_get('admin_menu_tweak_menu', 0)) {
    drupal_add_js($path . '/admin_menu.menu.js');
    drupal_add_js('misc/collapse.js');
  }
  if ($_GET['q'] == 'admin/build/modules' || strpos($_GET['q'], 'admin/build/modules/list') === 0) {
    $settings['tweak_modules'] = variable_get('admin_menu_tweak_modules', 0);
  }
  drupal_add_js(array(
    'admin_menu' => $settings,
  ), 'setting');
  if ($_GET['q'] == 'admin/settings/admin_menu' || $_GET['q'] == 'admin/settings/clean-urls' || $_GET['q'] == 'admin/settings/devel') {
    require_once $path . '/admin_menu.inc';
  }
  return $items;
}