diff --git a/core/modules/system/src/Cache/Context/PathBreadcrumbCacheContext.php b/core/modules/system/src/Cache/Context/PathBreadcrumbCacheContext.php index ae3dcd7..60481f9 100644 --- a/core/modules/system/src/Cache/Context/PathBreadcrumbCacheContext.php +++ b/core/modules/system/src/Cache/Context/PathBreadcrumbCacheContext.php @@ -4,7 +4,6 @@ use Drupal\Core\Cache\CacheableMetadata; use Drupal\Core\Cache\Context\CacheContextInterface; -use Symfony\Component\DependencyInjection\ContainerAware; use Symfony\Component\HttpFoundation\RequestStack; /** @@ -29,8 +28,6 @@ class PathBreadcrumbCacheContext implements CacheContextInterface { * * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack * The request stack. - * @param \Drupal\Core\Routing\RouteMatchInterface $route_match - * The route match. */ public function __construct(RequestStack $request_stack) { $this->requestStack = $request_stack; @@ -47,18 +44,13 @@ public static function getLabel() { * {@inheritdoc} */ public function getContext() { + // The path-based breadcrumb builder does not show the title of the current + // page in the breadcrumb, therefore there's no need to take the last part + // of the path into account when caching. $request = $this->requestStack->getCurrentRequest(); - if ($exception = $request->attributes->get('exception')) { - if ($exception->getStatusCode() == 404) { - // If we're on a 404, the last part of the path cannot match a route, - // otherwise we wouldn't be on a 404, so remove it from the cache - // context. - $path_elements = explode('/', trim($request->getPathInfo(), '/')); - array_pop($path_elements); - return implode('/', $path_elements); - } - } - return $request->getBasePath() . $request->getPathInfo(); + $path_elements = explode('/', trim($request->getPathInfo(), '/')); + array_pop($path_elements); + return implode('/', $path_elements); } /** diff --git a/core/modules/system/src/PathBasedBreadcrumbBuilder.php b/core/modules/system/src/PathBasedBreadcrumbBuilder.php index 060f1b1..f148b45 100644 --- a/core/modules/system/src/PathBasedBreadcrumbBuilder.php +++ b/core/modules/system/src/PathBasedBreadcrumbBuilder.php @@ -136,9 +136,8 @@ public function build(RouteMatchInterface $route_match) { // /user is just a redirect, so skip it. // @todo Find a better way to deal with /user. $exclude['/user'] = TRUE; - // Because this breadcrumb builder is entirely path-based, vary by the - // 'url.path' cache context. - $breadcrumb->addCacheContexts(['url.path']); + // Add the url.breadcrumb cache context. + $breadcrumb->addCacheContexts(['url.breadcrumb']); while (count($path_elements) > 1) { array_pop($path_elements); // Copy the path elements for up-casting. diff --git a/core/modules/system/system.services.yml b/core/modules/system/system.services.yml index c70889d..f82997e 100644 --- a/core/modules/system/system.services.yml +++ b/core/modules/system/system.services.yml @@ -7,6 +7,11 @@ services: class: Drupal\system\Access\DbUpdateAccessCheck tags: - { name: access_check, applies_to: _access_system_update } + cache_context.url.breadcrumb: + class: Drupal\system\Cache\Context\PathBreadcrumbCacheContext + arguments: ['@request_stack'] + tags: + - { name: cache.context } system.manager: class: Drupal\system\SystemManager arguments: ['@module_handler', '@entity.manager', '@request_stack', '@menu.link_tree', '@menu.active_trail']