diff --cc core/lib/Drupal/Core/Access/AccessResult.php index 6188b34,8c370dc..0000000 --- a/core/lib/Drupal/Core/Access/AccessResult.php +++ b/core/lib/Drupal/Core/Access/AccessResult.php @@@ -354,13 -409,13 +365,13 @@@ abstract class AccessResult implements } elseif ($this->isAllowed() || $other->isAllowed()) { $result = static::allowed(); - if (!$this->isAllowed() || ($this->getCacheMaxAge() === 0 && $other->isAllowed())) { - if (!$this->isAllowed() || (!$this->isCacheable() && $other->isAllowed()) || ($this->isCacheable() && $other instanceof CacheableInterface && $other->isCacheable())) { ++ if (!$this->isAllowed() || ($this->getCacheMaxAge() === 0 && $other->isAllowed()) || ($this->getCacheMaxAge() !== 0 && $other instanceof CacheableDependencyInterface && $other->getCacheMaxAge() !== 0)) { $merge_other = TRUE; } } else { $result = static::neutral(); - if (!$this->isNeutral() || ($this->getCacheMaxAge() === 0 && $other->isNeutral())) { - if (!$this->isNeutral() || (!$this->isCacheable() && $other->isNeutral()) || ($this->isCacheable() && $other instanceof CacheableInterface && $other->isCacheable())) { ++ if (!$this->isNeutral() || ($this->getCacheMaxAge() === 0 && $other->isNeutral()) || ($this->getCacheMaxAge() !== 0 && $other instanceof CacheableDependencyInterface && $other->getCacheMaxAge() !== 0)) { $merge_other = TRUE; } } diff --cc core/lib/Drupal/Core/Entity/EntityViewBuilder.php index 13a7b50,5fc4db7..0000000 --- a/core/lib/Drupal/Core/Entity/EntityViewBuilder.php +++ b/core/lib/Drupal/Core/Entity/EntityViewBuilder.php diff --cc core/lib/Drupal/Core/Render/BubbleableMetadata.php index c4852a9,ccf11fd..0000000 --- a/core/lib/Drupal/Core/Render/BubbleableMetadata.php +++ b/core/lib/Drupal/Core/Render/BubbleableMetadata.php @@@ -8,8 -8,9 +8,9 @@@ namespace Drupal\Core\Render; use Drupal\Component\Utility\NestedArray; + use Drupal\Core\Access\AccessResultInterface; use Drupal\Core\Cache\Cache; -use Drupal\Core\Cache\CacheableInterface; +use Drupal\Core\Cache\CacheableDependencyInterface; /** * Value object used for bubbleable rendering metadata. @@@ -125,6 -130,22 +126,26 @@@ class BubbleableMetadata implements Cac } /** - * Creates a bubbleable metadata object from a cacheable object. ++ * Creates a bubbleable metadata object from an access result. + * - * @param \Drupal\Core\Cache\CacheableInterface $object - * A cacheable object. ++ * @param \Drupal\Core\Access\AccessResultInterface $access_result ++ * An access result. + * + * @return static + */ - public static function createFromCacheableObject(CacheableInterface $object) { ++ public static function createFromAccessResult(AccessResultInterface $access_result) { ++ if ($access_result instanceof CacheableDependencyInterface) { ++ return static::createFromObject($access_result); ++ } ++ ++ // Any AccessResultInterface object that doesn't implement ++ // CacheableDependencyInterface must be assumed to be uncacheable. + $meta = new static(); - $meta->contexts = $object->getCacheContexts(); - $meta->tags = $object->getCacheTags(); - $meta->maxAge = $object->getCacheMaxAge(); ++ $meta->maxAge = 0; + return $meta; + } + + /** * Gets cache tags. * * @return string[] diff --cc core/modules/system/src/Tests/Entity/EntityViewBuilderTest.php index e44299b,dd6b226..0000000 --- a/core/modules/system/src/Tests/Entity/EntityViewBuilderTest.php +++ b/core/modules/system/src/Tests/Entity/EntityViewBuilderTest.php core/tests/Drupal/Tests/Core/Access/AccessResultTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/tests/Drupal/Tests/Core/Access/AccessResultTest.php b/core/tests/Drupal/Tests/Core/Access/AccessResultTest.php index d9ab9d0..77d5e13 100644 --- a/core/tests/Drupal/Tests/Core/Access/AccessResultTest.php +++ b/core/tests/Drupal/Tests/Core/Access/AccessResultTest.php @@ -808,15 +808,15 @@ public function testAndOrCacheabilityPropagation(AccessResultInterface $first, $ public function testOrIfCacheabilityMerging() { $merge_both_directions = function(AccessResult $a, AccessResult $b) { // A globally cacheable access result. - $a->setCacheable(TRUE); + $a->setCacheMaxAge(3600); // Another access result that is cacheable per permissions. - $b->setCacheable(TRUE)->cachePerPermissions(); + $b->setCacheMaxAge(86400)->cachePerPermissions(); $r1 = $a->orIf($b); - $this->assertTrue($r1->isCacheable()); + $this->assertTrue($r1->getCacheMaxAge() !== 0); $this->assertSame(['user.permissions'], $r1->getCacheContexts()); $r2 = $b->orIf($a); - $this->assertTrue($r2->isCacheable()); + $this->assertTrue($r2->getCacheMaxAge() !== 0); $this->assertSame(['user.permissions'], $r2->getCacheContexts()); };