diff -u b/core/modules/toolbar/js/toolbar.js b/core/modules/toolbar/js/toolbar.js --- b/core/modules/toolbar/js/toolbar.js +++ b/core/modules/toolbar/js/toolbar.js @@ -63,7 +63,6 @@ // readers. $messages = $(Drupal.theme('toolbarMessageBox')).appendTo($toolbar); // Store the trays in a scoped variable. - $trays = $toolbar.find('.tray'); $trays // Add the tray orientation toggles. diff -u b/core/modules/toolbar/toolbar.module b/core/modules/toolbar/toolbar.module --- b/core/modules/toolbar/toolbar.module +++ b/core/modules/toolbar/toolbar.module @@ -26,20 +26,6 @@ } /** - * Implements hook_menu(). - */ -function toolbar_menu() { - $items['toolbar/subtrees/%'] = array( - 'page callback' => 'toolbar_subtrees_jsonp', - 'page arguments' => array(2), - 'access callback' => '_toolbar_subtrees_access', - 'access arguments' => array(2), - 'type' => MENU_CALLBACK, - ); - return $items; -} - -/** * Implements hook_permission(). */ function toolbar_permission() { @@ -73,6 +59,20 @@ } /** + * Implements hook_menu(). + */ +function toolbar_menu() { + $items['toolbar/subtrees/%'] = array( + 'page callback' => 'toolbar_subtrees_jsonp', + 'page arguments' => array(2), + 'access callback' => '_toolbar_subtrees_access', + 'access arguments' => array(2), + 'type' => MENU_CALLBACK, + ); + return $items; +} + +/** * Implements hook_element_info(). */ function toolbar_element_info() { @@ -126,19 +126,65 @@ } /** - * Implements hook_system_info_alter(). + * Access callback: Returns if the user has access to the rendered subtree requested by the hash. * - * Indicate that the 'page_top' region (in which the toolbar will be displayed) - * is an overlay supplemental region that should be refreshed whenever its - * content is updated. + * @see toolbar_menu(). + */ +function _toolbar_subtrees_access($hash) { + return user_access('access toolbar') && ($hash == _toolbar_get_subtree_hash()); +} + +/** + * Page callback: Returns the rendered subtree of each top-level toolbar link. * - * This information is provided for any module that might need to use it, not - * just the core Overlay module. + * @see toolbar_menu(). */ -function toolbar_system_info_alter(&$info, $file, $type) { - if ($type == 'theme') { - $info['overlay_supplemental_regions'][] = 'page_top'; +function toolbar_subtrees_jsonp($hash) { + _toolbar_initialize_page_cache(); + $subtrees = toolbar_get_rendered_subtrees(); + $response = new JsonResponse($subtrees); + $response->setCallback('Drupal.toolbar.setSubtrees'); + return $response; +} + +/** + * Use Drupal's page cache for toolbar/subtrees/*, even for authenticated users. + * + * This gets invoked after full bootstrap, so must duplicate some of what's + * done by _drupal_bootstrap_page_cache(). + * + * @todo Replace this hack with something better integrated with DrupalKernel + * once Drupal's page caching itself is properly integrated. + */ +function _toolbar_initialize_page_cache() { + $GLOBALS['conf']['system.performance']['cache']['page']['enabled'] = TRUE; + 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. + $_GET['q'] = $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, REQUEST_TIME + $max_age)); + drupal_add_http_header('Cache-Control', 'private, max-age=' . $max_age); } /** @@ -375,0 +422,16 @@ +/** + * Implements hook_system_info_alter(). + * + * Indicate that the 'page_top' region (in which the toolbar will be displayed) + * is an overlay supplemental region that should be refreshed whenever its + * content is updated. + * + * This information is provided for any module that might need to use it, not + * just the core Overlay module. + */ +function toolbar_system_info_alter(&$info, $file, $type) { + if ($type == 'theme') { + $info['overlay_supplemental_regions'][] = 'page_top'; + } +} + @@ -490,28 +552,6 @@ } /** - * Access callback: Returns if the user has access to the rendered subtree requested by the hash. - * - * @see toolbar_menu(). - */ -function _toolbar_subtrees_access($hash) { - return user_access('access toolbar') && ($hash == _toolbar_get_subtree_hash()); -} - -/** - * Page callback: Returns the rendered subtree of each top-level toolbar link. - * - * @see toolbar_menu(). - */ -function toolbar_subtrees_jsonp($hash) { - _toolbar_initialize_page_cache(); - $subtrees = toolbar_get_rendered_subtrees(); - $response = new JsonResponse($subtrees); - $response->setCallback('Drupal.toolbar.setSubtrees'); - return $response; -} - -/** * Returns the rendered subtree of each top-level toolbar link. */ function toolbar_get_rendered_subtrees() { @@ -545,63 +585,6 @@ } /** - * Returns the hash of the per-user rendered toolbar subtrees. - */ -function _toolbar_get_subtree_hash() { - global $user; - $cid = $user->uid . ':' . language(LANGUAGE_TYPE_INTERFACE)->langcode; - if ($cache = cache('toolbar')->get($cid)) { - $hash = $cache->data; - } - else { - $subtrees = toolbar_get_rendered_subtrees(); - $hash = drupal_hash_base64(serialize($subtrees)); - cache('toolbar')->set($cid, $hash); - } - return $hash; -} - -/** - * Use Drupal's page cache for toolbar/subtrees/*, even for authenticated users. - * - * This gets invoked after full bootstrap, so must duplicate some of what's - * done by _drupal_bootstrap_page_cache(). - * - * @todo Replace this hack with something better integrated with DrupalKernel - * once Drupal's page caching itself is properly integrated. - */ -function _toolbar_initialize_page_cache() { - $GLOBALS['conf']['system.performance']['cache']['page']['enabled'] = TRUE; - 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. - $_GET['q'] = $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, REQUEST_TIME + $max_age)); - drupal_add_http_header('Cache-Control', 'private, max-age=' . $max_age); -} - -/** * Checks whether an item is in the active trail. * * Useful when using a menu generated by menu_tree_all_data() which does @@ -682,0 +666,17 @@ + +/** + * Returns the hash of the per-user rendered toolbar subtrees. + */ +function _toolbar_get_subtree_hash() { + global $user; + $cid = $user->uid . ':' . language(LANGUAGE_TYPE_INTERFACE)->langcode; + if ($cache = cache('toolbar')->get($cid)) { + $hash = $cache->data; + } + else { + $subtrees = toolbar_get_rendered_subtrees(); + $hash = drupal_hash_base64(serialize($subtrees)); + cache('toolbar')->set($cid, $hash); + } + return $hash; +}