Skip to content
Snippets Groups Projects

Issue #3500483: add cache contexts in applies()

Open Malcolm Young requested to merge issue/easy_breadcrumb-3500483:3500483 into 2.x
1 file
+ 9
1
Compare changes
  • Side-by-side
  • Inline
@@ -11,6 +11,7 @@ use Drupal\Core\Access\AccessManagerInterface;
@@ -11,6 +11,7 @@ use Drupal\Core\Access\AccessManagerInterface;
use Drupal\Core\Breadcrumb\Breadcrumb;
use Drupal\Core\Breadcrumb\Breadcrumb;
use Drupal\Core\Breadcrumb\BreadcrumbBuilderInterface;
use Drupal\Core\Breadcrumb\BreadcrumbBuilderInterface;
use Drupal\Core\Cache\CacheableDependencyInterface;
use Drupal\Core\Cache\CacheableDependencyInterface;
 
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Controller\TitleResolverInterface;
use Drupal\Core\Controller\TitleResolverInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityInterface;
@@ -244,7 +245,12 @@ class EasyBreadcrumbBuilder implements BreadcrumbBuilderInterface {
@@ -244,7 +245,12 @@ class EasyBreadcrumbBuilder implements BreadcrumbBuilderInterface {
/**
/**
* {@inheritdoc}
* {@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', 'url.path', 'languages']);
 
$applies_admin_routes = $this->config->get(EasyBreadcrumbConstants::APPLIES_ADMIN_ROUTES);
$applies_admin_routes = $this->config->get(EasyBreadcrumbConstants::APPLIES_ADMIN_ROUTES);
// If never set before ensure Applies to administration pages is on.
// If never set before ensure Applies to administration pages is on.
@@ -447,6 +453,8 @@ class EasyBreadcrumbBuilder implements BreadcrumbBuilderInterface {
@@ -447,6 +453,8 @@ class EasyBreadcrumbBuilder implements BreadcrumbBuilderInterface {
}
}
// Expire cache by languages and config changes.
// Expire cache by languages and config changes.
 
// @todo Remove in Drupal 12.0.0, will be added from ::applies(). See
 
// https://www.drupal.org/project/drupal/issues/3459277
$breadcrumb->addCacheContexts(['route', 'url.path', 'languages']);
$breadcrumb->addCacheContexts(['route', 'url.path', 'languages']);
// Expire cache context for config changes.
// Expire cache context for config changes.
Loading