You are here

function admin_menu_js_cache in Administration menu 8.3

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

Menu callback; Output administration menu for HTTP caching via AJAX request.

See also

admin_menu_deliver()

2 string references to 'admin_menu_js_cache'
admin_menu_js in ./admin_menu.module
Implements hook_js().
admin_menu_menu in ./admin_menu.module
Implements hook_menu().

File

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

Code

function admin_menu_js_cache() {
  global $conf;

  // Suppress Devel module.
  $GLOBALS['devel_shutdown'] = FALSE;

  // Enforce page caching.
  $conf['system.performance']['cache'] = 1;
  drupal_page_is_cacheable(TRUE);

  // If we have a cache, serve it.
  // @see _drupal_bootstrap_page_cache()
  $cache = drupal_page_get_cache();
  if (is_object($cache)) {
    header('X-Drupal-Cache: HIT');

    // Restore the metadata cached with the page.
    _current_path($cache->data['path']);
    date_default_timezone_set(drupal_get_user_timezone());
    drupal_serve_page_from_cache($cache);

    // We are done.
    exit;
  }

  // Otherwise, create a new page response (that will be cached).
  header('X-Drupal-Cache: MISS');

  // The Expires HTTP header is the heart of the client-side HTTP caching. The
  // additional server-side page cache only takes effect when the client
  // accesses the callback URL again (e.g., after clearing the browser cache or
  // when force-reloading a Drupal page).
  $max_age = 3600 * 24 * 365;
  drupal_add_http_header('Expires', gmdate(DATE_RFC1123, \Drupal::time()
    ->getRequestTime() + $max_age));
  drupal_add_http_header('Cache-Control', 'private, max-age=' . $max_age);

  // Retrieve and return the rendered menu.
  $content = admin_menu_output();
  return new Response($content);
}