1.7.x admin_bar.module admin_bar_preprocess_page(&$variables)
1.10.x admin_bar.module admin_bar_preprocess_page(&$variables)
1.8.x admin_bar.module admin_bar_preprocess_page(&$variables)
1.9.x admin_bar.module admin_bar_preprocess_page(&$variables)

Implements hook_preprocess_page().

File

modules/admin_bar/admin_bar.module, line 173
Render an administrative bar as a dropdown menu at the top of the window.

Code

function admin_bar_preprocess_page(&$variables) {
  if (!user_access('access administration bar') || admin_bar_suppress(FALSE)) {
    return;
  }

  // Performance: Skip this entirely for AJAX requests.
  if (!backdrop_is_html()) {
    return;
  }

  // For the status report page, generate the admin bar from scratch to refresh
  // the site status indicator.
  if (strpos($_GET['q'], 'admin/reports/status') === 0) {
    cache('admin_bar')->flush();
  }

  global $user, $language;
  $path = backdrop_get_path('module', 'admin_bar');

  $options = array('every_page' => TRUE);

  backdrop_add_css($path . '/css/admin_bar.css', $options);
  backdrop_add_js($path . '/js/admin_bar.js', $options);

  // Add current path to support menu item highlighting.
  $args = explode('/', $_GET['q']);
  if ($args[0] == 'admin' && !empty($args[1])) {
    $settings['activeTrail'] = url($args[0] . '/' . $args[1]);
  }
  elseif (backdrop_is_front_page()) {
    $settings['activeTrail'] = url('<front>');
  }

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

  // Determine whether we need to show all components and disable all caches.
  $complete = FALSE;

  // If we have a cached menu for the current user, only output the hash for the
  // client-side HTTP cache callback URL.
  $cid = 'admin_bar:' . $user->uid . ':' . session_id() . ':' . $language->langcode;
  if (!$complete && ($hash = admin_bar_cache_get($cid))) {
    $settings['hash'] = $hash;

    // The base path to use for cache requests depends on whether clean URLs
    // are enabled, whether Backdrop runs in a sub-directory, and on the locale
    // 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_bar');
  }
  // Otherwise, add the full menu to the page.
  else {
    module_load_include('inc', 'admin_bar');
    $variables['page_bottom'] .= admin_bar_output($complete);
  }

  $replacements = module_invoke_all('admin_bar_replacements', $complete);
  if (!empty($replacements)) {
    $settings['replacements'] = $replacements;
  }

  $config = config('admin_bar.settings');
  if ($setting = $config->get('margin_top')) {
    $settings['margin_top'] = $setting;
  }
  if ($setting = $config->get('position_fixed')) {
    $settings['position_fixed'] = $setting;
  }

  backdrop_add_js(array('admin_bar' => $settings), 'setting');
}