core/core.services.yml | 22 +++++++++++----------- .../Core/Cache/MenuActiveTrailCacheContext.php | 2 +- .../Drupal/Core/Menu/MenuActiveTrailInterface.php | 5 +++-- core/modules/comment/comment.module | 2 +- .../system/src/Plugin/Block/SystemMenuBlock.php | 2 +- .../Tests/Cache/PageCacheTagsIntegrationTest.php | 8 ++++---- 6 files changed, 21 insertions(+), 20 deletions(-) diff --git a/core/core.services.yml b/core/core.services.yml index 1b60663..2eb4b93 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -21,6 +21,17 @@ services: arguments: ['@request_stack'] tags: - { name: cache.context } + cache_context.url.pager: + class: Drupal\Core\Cache\PagerCacheContext + arguments: ['@request_stack'] + tags: + - { name: cache.context} + cache_context.url.menu_active_trail: + class: Drupal\Core\Cache\MenuActiveTrailCacheContext + calls: + - [setContainer, ['@service_container']] + tags: + - { name: cache.context} cache_factory: class: Drupal\Core\Cache\CacheFactory @@ -30,11 +41,6 @@ services: cache_contexts: class: Drupal\Core\Cache\CacheContexts arguments: ['@service_container', '%cache_contexts%' ] - cache_context.pager: - class: Drupal\Core\Cache\PagerCacheContext - arguments: ['@request_stack'] - tags: - - { name: cache.context} cache_context.language: class: Drupal\Core\Cache\LanguageCacheContext arguments: ['@language_manager'] @@ -49,12 +55,6 @@ services: class: Drupal\Core\Cache\TimeZoneCacheContext tags: - { name: cache.context} - cache_context.menu.active_trail: - class: Drupal\Core\Cache\MenuActiveTrailCacheContext - calls: - - [setContainer, ['@service_container']] - tags: - - { name: cache.context} cache_tags.invalidator: parent: container.trait class: Drupal\Core\Cache\CacheTagsInvalidator diff --git a/core/lib/Drupal/Core/Cache/MenuActiveTrailCacheContext.php b/core/lib/Drupal/Core/Cache/MenuActiveTrailCacheContext.php index 7c41bee..7f0e226 100644 --- a/core/lib/Drupal/Core/Cache/MenuActiveTrailCacheContext.php +++ b/core/lib/Drupal/Core/Cache/MenuActiveTrailCacheContext.php @@ -27,7 +27,7 @@ public static function getLabel() { /** * {@inheritdoc} */ - public function getContext($menu_name) { + public function getContext($menu_name = NULL) { $active_trail = $this->container->get('menu.active_trail') ->getActiveTrailIds($menu_name); return 'menu_trail.' . $menu_name . '|' . implode('|', $active_trail); diff --git a/core/lib/Drupal/Core/Menu/MenuActiveTrailInterface.php b/core/lib/Drupal/Core/Menu/MenuActiveTrailInterface.php index 49f4e99..be32e64 100644 --- a/core/lib/Drupal/Core/Menu/MenuActiveTrailInterface.php +++ b/core/lib/Drupal/Core/Menu/MenuActiveTrailInterface.php @@ -18,8 +18,9 @@ /** * Gets the active trail IDs of the specified menu tree. * - * @param string $menu_name - * The menu name of the requested tree. + * @param string|NULL $menu_name + * (optional) The menu name of the requested tree. If omitted, all menu + * trees will be searched. * * @return array * An array containing the active trail: a list of plugin IDs. diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index 695018c..d4c2415 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -208,7 +208,7 @@ function comment_entity_build_defaults_alter(array &$build, EntityInterface $ent foreach ($entity->getFieldDefinitions() as $field_name => $definition) { if ($definition->getType() === 'comment' && ($display_options = $display->getComponent($field_name))) { $pager_id = $display_options['settings']['pager_id']; - $build['#cache']['contexts'][] = 'pager:' . $pager_id; + $build['#cache']['contexts'][] = 'url.pager:' . $pager_id; } } } diff --git a/core/modules/system/src/Plugin/Block/SystemMenuBlock.php b/core/modules/system/src/Plugin/Block/SystemMenuBlock.php index c07fba2..0d9ab37 100644 --- a/core/modules/system/src/Plugin/Block/SystemMenuBlock.php +++ b/core/modules/system/src/Plugin/Block/SystemMenuBlock.php @@ -201,7 +201,7 @@ protected function getRequiredCacheContexts() { $menu_name = $this->getDerivativeId(); return [ 'user.roles', - 'menu.active_trail:' . $menu_name, + 'url.menu_active_trail:' . $menu_name, ]; } diff --git a/core/modules/system/src/Tests/Cache/PageCacheTagsIntegrationTest.php b/core/modules/system/src/Tests/Cache/PageCacheTagsIntegrationTest.php index b56a6ba..3fb4ea6 100644 --- a/core/modules/system/src/Tests/Cache/PageCacheTagsIntegrationTest.php +++ b/core/modules/system/src/Tests/Cache/PageCacheTagsIntegrationTest.php @@ -72,10 +72,10 @@ function testPageCacheTags() { $cache_contexts = [ 'language', - 'menu.active_trail:account', - 'menu.active_trail:footer', - 'menu.active_trail:main', - 'menu.active_trail:tools', + 'url.menu_active_trail:account', + 'url.menu_active_trail:footer', + 'url.menu_active_trail:main', + 'url.menu_active_trail:tools', 'theme', 'timezone', 'user.roles',