1 admin_bar.module admin_bar_preprocess_page(&$variables)

Implements hook_preprocess_page().

File

core/modules/admin_bar/admin_bar.module, line 188
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_js($path . '/js/admin_bar.js', $options);
  backdrop_add_css($path . '/css/admin_bar.css', $options);
  $options['media'] = 'print';
  backdrop_add_css($path . '/css/admin_bar-print.css', $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;
  }

  // Send whether this is an admin page to JS for back to site functionality.
  $settings['current_path_is_admin'] = FALSE;
  $current_path = current_path();
  if (path_is_admin($current_path)) {
    $settings['current_path_is_admin'] = TRUE;
  }

  $components = $config->get('components');
  if (in_array('admin_bar.back_to_site_link', $components)) {
    $settings['back_to_site_link'] = TRUE;
  }
  backdrop_add_js(array('admin_bar' => $settings), 'setting');
}