Skip to content
Snippets Groups Projects
Verified Commit a75df83c authored by Alex Pott's avatar Alex Pott
Browse files

Issue #2719721 by kristiaanvandeneynde, jhodgdon, BramDriesen, pameeela,...

Issue #2719721 by kristiaanvandeneynde, jhodgdon, BramDriesen, pameeela, catch, Wim Leers, Berdir, alexpott, neclimdul, acbramley, benjy, cilefen, mxr576, rothlive, andrewmacpherson: BreadcrumbBuilder::applies() mismatch with cacheability metadata
parent 82a5a701
No related branches found
No related tags found
23 merge requests!11131[10.4.x-only-DO-NOT-MERGE]: Issue ##2842525 Ajax attached to Views exposed filter form does not trigger callbacks,!9470[10.3.x-only-DO-NOT-MERGE]: #3331771 Fix file_get_contents(): Passing null to parameter,!8736Update the Documention As per the Function uses.,!8528Issue #3456871 by Tim Bozeman: Support NULL services,!8513Issue #3453786: DefaultSelection should document why values for target_bundles NULL and [] behave as they do,!3878Removed unused condition head title for views,!3818Issue #2140179: $entity->original gets stale between updates,!3742Issue #3328429: Create item list field formatter for displaying ordered and unordered lists,!3731Claro: role=button on status report items,!3651Issue #3347736: Create new SDC component for Olivero (header-search),!3355Issue #3209129: Scrolling problems when adding a block via layout builder,!3154Fixes #2987987 - CSRF token validation broken on routes with optional parameters.,!3133core/modules/system/css/components/hidden.module.css,!2964Issue #2865710 : Dependencies from only one instance of a widget are used in display modes,!2812Issue #3312049: [Followup] Fix Drupal.Commenting.FunctionComment.MissingReturnType returns for NULL,!2378Issue #2875033: Optimize joins and table selection in SQL entity query implementation,!2062Issue #3246454: Add weekly granularity to views date sort,!10223132456: Fix issue where views instances are emptied before an ajax request is complete,!877Issue #2708101: Default value for link text is not saved,!617Issue #3043725: Provide a Entity Handler for user cancelation,!579Issue #2230909: Simple decimals fail to pass validation,!560Move callback classRemove outside of the loop,!555Issue #3202493
Pipeline #218688 canceled
......@@ -14,16 +14,28 @@ interface BreadcrumbBuilderInterface {
*
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The current route match.
* phpcs:disable Drupal.Commenting
* @todo Uncomment new method parameters before drupal:12.0.0, see
* https://www.drupal.org/project/drupal/issues/3459277.
*
* @param \Drupal\Core\Cache\CacheableMetadata $cacheable_metadata
* The cacheable metadata to add to if your check varies by or depends
* on something. Anything you specify here does not have to be repeated in
* the build() method as it will be merged in automatically.
* phpcs:enable
*
* @return bool
* TRUE if this builder should be used or FALSE to let other builders
* decide.
*/
public function applies(RouteMatchInterface $route_match);
public function applies(RouteMatchInterface $route_match /* , CacheableMetadata $cacheable_metadata */);
/**
* Builds the breadcrumb.
*
* There is no need to add any cacheable metadata that was already added in
* applies() as that will be automatically added for you.
*
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The current route match.
*
......
......@@ -2,6 +2,7 @@
namespace Drupal\Core\Breadcrumb;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Routing\RouteMatchInterface;
......@@ -62,7 +63,7 @@ public function addBuilder(BreadcrumbBuilderInterface $builder, $priority) {
/**
* {@inheritdoc}
*/
public function applies(RouteMatchInterface $route_match) {
public function applies(RouteMatchInterface $route_match, ?CacheableMetadata $cacheable_metadata = NULL) {
return TRUE;
}
......@@ -70,12 +71,13 @@ public function applies(RouteMatchInterface $route_match) {
* {@inheritdoc}
*/
public function build(RouteMatchInterface $route_match) {
$cacheable_metadata = new CacheableMetadata();
$breadcrumb = new Breadcrumb();
$context = ['builder' => NULL];
// Call the build method of registered breadcrumb builders,
// until one of them returns an array.
foreach ($this->getSortedBuilders() as $builder) {
if (!$builder->applies($route_match)) {
if (!$builder->applies($route_match, $cacheable_metadata)) {
// The builder does not apply, so we continue with the other builders.
continue;
}
......@@ -84,6 +86,7 @@ public function build(RouteMatchInterface $route_match) {
if ($breadcrumb instanceof Breadcrumb) {
$context['builder'] = $builder;
$breadcrumb->addCacheableDependency($cacheable_metadata);
break;
}
else {
......
......@@ -4,6 +4,7 @@
use Drupal\Core\Breadcrumb\BreadcrumbBuilderInterface;
use Drupal\Core\Breadcrumb\Breadcrumb;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Link;
use Drupal\Core\Routing\RouteMatchInterface;
......@@ -35,7 +36,10 @@ public function __construct(EntityTypeManagerInterface $entity_type_manager) {
/**
* {@inheritdoc}
*/
public function applies(RouteMatchInterface $route_match) {
public function applies(RouteMatchInterface $route_match, ?CacheableMetadata $cacheable_metadata = NULL) {
// @todo Remove null safe operator in Drupal 12.0.0, see
// https://www.drupal.org/project/drupal/issues/3459277.
$cacheable_metadata?->addCacheContexts(['route']);
return $route_match->getRouteName() == 'comment.reply' && $route_match->getParameter('entity');
}
......@@ -44,6 +48,8 @@ public function applies(RouteMatchInterface $route_match) {
*/
public function build(RouteMatchInterface $route_match) {
$breadcrumb = new Breadcrumb();
// @todo Remove in Drupal 12.0.0, will be added from ::applies(). See
// https://www.drupal.org/project/drupal/issues/3459277
$breadcrumb->addCacheContexts(['route']);
$breadcrumb->addLink(Link::createFromRoute($this->t('Home'), '<front>'));
......
......@@ -4,6 +4,7 @@
use Drupal\Core\Breadcrumb\Breadcrumb;
use Drupal\Core\Breadcrumb\BreadcrumbBuilderInterface;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Link;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
......@@ -19,7 +20,10 @@ class HelpBreadcrumbBuilder implements BreadcrumbBuilderInterface {
/**
* {@inheritdoc}
*/
public function applies(RouteMatchInterface $route_match) {
public function applies(RouteMatchInterface $route_match, ?CacheableMetadata $cacheable_metadata = NULL) {
// @todo Remove null safe operator in Drupal 12.0.0, see
// https://www.drupal.org/project/drupal/issues/3459277.
$cacheable_metadata?->addCacheContexts(['route']);
return $route_match->getRouteName() == 'help.help_topic';
}
......
......@@ -6,6 +6,7 @@
use Drupal\Core\Access\AccessManagerInterface;
use Drupal\Core\Breadcrumb\Breadcrumb;
use Drupal\Core\Breadcrumb\BreadcrumbBuilderInterface;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Controller\TitleResolverInterface;
use Drupal\Core\Link;
......@@ -134,7 +135,7 @@ public function __construct(RequestContext $context, AccessManagerInterface $acc
/**
* {@inheritdoc}
*/
public function applies(RouteMatchInterface $route_match) {
public function applies(RouteMatchInterface $route_match, ?CacheableMetadata $cacheable_metadata = NULL) {
return TRUE;
}
......
......@@ -4,6 +4,7 @@
use Drupal\Core\Breadcrumb\BreadcrumbBuilderInterface;
use Drupal\Core\Breadcrumb\Breadcrumb;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Entity\EntityRepositoryInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Link;
......@@ -46,7 +47,10 @@ public function __construct(EntityTypeManagerInterface $entity_type_manager, Ent
/**
* {@inheritdoc}
*/
public function applies(RouteMatchInterface $route_match) {
public function applies(RouteMatchInterface $route_match, ?CacheableMetadata $cacheable_metadata = NULL) {
// @todo Remove null safe operator in Drupal 12.0.0, see
// https://www.drupal.org/project/drupal/issues/3459277.
$cacheable_metadata?->addCacheContexts(['route']);
return $route_match->getRouteName() == 'entity.taxonomy_term.canonical'
&& $route_match->getParameter('taxonomy_term') instanceof TermInterface;
}
......@@ -74,8 +78,8 @@ public function build(RouteMatchInterface $route_match) {
$breadcrumb->addLink(Link::createFromRoute($term->getName(), 'entity.taxonomy_term.canonical', ['taxonomy_term' => $term->id()]));
}
// This breadcrumb builder is based on a route parameter, and hence it
// depends on the 'route' cache context.
// @todo Remove in Drupal 12.0.0, will be added from ::applies(). See
// https://www.drupal.org/project/drupal/issues/3459277
$breadcrumb->addCacheContexts(['route']);
return $breadcrumb;
......
......@@ -171,11 +171,11 @@ public function testAnonymous(): void {
$recorded_queries = $performance_data->getQueries();
$this->assertSame($expected_queries, $recorded_queries);
$this->assertSame(12, $performance_data->getQueryCount());
$this->assertSame(76, $performance_data->getCacheGetCount());
$this->assertSame(15, $performance_data->getCacheSetCount());
$this->assertSame(78, $performance_data->getCacheGetCount());
$this->assertSame(16, $performance_data->getCacheSetCount());
$this->assertSame(0, $performance_data->getCacheDeleteCount());
$this->assertSame(21, $performance_data->getCacheTagChecksumCount());
$this->assertSame(33, $performance_data->getCacheTagIsValidCount());
$this->assertSame(22, $performance_data->getCacheTagChecksumCount());
$this->assertSame(32, $performance_data->getCacheTagIsValidCount());
$this->assertSame(0, $performance_data->getCacheTagInvalidationCount());
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment