You are here

function admin_menu_init in Administration menu 6.3

Same name and namespace in other branches
  1. 6 admin_menu.module \admin_menu_init()
  2. 7.3 admin_menu.module \admin_menu_init()

Implements hook_init().

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_init().

File

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

Code

function admin_menu_init() {

  // Re-enable breadcrumbs on administrative pages by setting 'admin_menu' as
  // the active menu name. Also applies to users without access to the
  // Administration menu as they should also get properly working breadcrumbs on
  // administrative pages.
  // @see admin_menu_menu_alter()
  if (arg(0) == 'admin') {
    menu_set_active_menu_name('admin_menu');
  }
  if (!user_access('access administration menu') || admin_menu_suppress(FALSE)) {
    return;
  }

  // Performance: Skip this entirely for AJAX requests.
  if (strpos($_GET['q'], 'js/') === 0) {
    return;
  }
  global $user, $language;
  $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);
  }

  // Previous versions used the 'defer' attribute to increase browser rendering
  // performance. At least starting with Firefox 3.6, deferred .js files are
  // loaded, but Drupal.behaviors are not contained in the DOM when drupal.js
  // executes Drupal.attachBehaviors().
  drupal_add_js($path . '/admin_menu.js');

  // Destination query strings are applied via JS.
  $settings['destination'] = drupal_get_destination();

  // Hash for client-side HTTP/AJAX caching.
  $cid = 'admin_menu:' . $user->uid . ':' . session_id() . ':' . $language->language;
  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/modules' || strpos($_GET['q'], 'admin/build/modules/list') === 0) {
    $settings['tweak_modules'] = variable_get('admin_menu_tweak_modules', 0);
  }
  if ($_GET['q'] == 'admin/user/permissions') {
    $settings['tweak_permissions'] = variable_get('admin_menu_tweak_permissions', 0);
  }
  drupal_add_js(array(
    'admin_menu' => $settings,
  ), 'setting');
}