diff --git a/core/lib/Drupal/Core/Access/AccessResult.php b/core/lib/Drupal/Core/Access/AccessResult.php index 8c370dc..a5b748d 100644 --- a/core/lib/Drupal/Core/Access/AccessResult.php +++ b/core/lib/Drupal/Core/Access/AccessResult.php @@ -409,13 +409,14 @@ public function orIf(AccessResultInterface $other) { } elseif ($this->isAllowed() || $other->isAllowed()) { $result = static::allowed(); - if (!$this->isAllowed() || (!$this->isCacheable() && $other->isAllowed()) || ($this->isCacheable() && $other instanceof CacheableInterface && $other->isCacheable())) { + $bothCacheable = $this->isCacheable() && $other instanceof CacheableInterface && $other->isCacheable(); + if (!$this->isAllowed() || (!$this->isCacheable() && $other->isAllowed()) || $bothCacheable) { $merge_other = TRUE; } } else { $result = static::neutral(); - if (!$this->isNeutral() || (!$this->isCacheable() && $other->isNeutral()) || ($this->isCacheable() && $other instanceof CacheableInterface && $other->isCacheable())) { + if (!$this->isNeutral() || (!$this->isCacheable() && $other->isNeutral()) || $bothCacheable) { $merge_other = TRUE; } } diff --git a/core/lib/Drupal/Core/Entity/Entity/EntityViewDisplay.php b/core/lib/Drupal/Core/Entity/Entity/EntityViewDisplay.php index bed6f24..dfe423b 100644 --- a/core/lib/Drupal/Core/Entity/Entity/EntityViewDisplay.php +++ b/core/lib/Drupal/Core/Entity/Entity/EntityViewDisplay.php @@ -238,17 +238,19 @@ public function buildMultiple(array $entities) { // Then let the formatter build the output for each entity. foreach ($entities as $id => $entity) { + $output = []; $items = $grouped_items[$id]; /** @var \Drupal\Core\Access\AccessResultInterface $field_access */ $field_access = $items->access('view', NULL, TRUE); - $build_list[$id][$name] = []; + $meta = BubbleableMetadata::createFromAccessResult($field_access); if ($field_access->isAllowed()) { - $build_list[$id][$name] = $formatter->view($items); + $output = $formatter->view($items); + $meta = BubbleableMetadata::createFromRenderArray($output) + ->merge($meta); } - // Apply the field access cacheability metadata to the render array. - BubbleableMetadata::createFromRenderArray($build_list[$id][$name]) - ->merge(BubbleableMetadata::createFromAccessResult($field_access)) - ->applyTo($build_list[$id][$name]); + $meta->applyTo($output); + + $build_list[$id][$name] = $output; } } } diff --git a/core/lib/Drupal/Core/Field/FormatterBase.php b/core/lib/Drupal/Core/Field/FormatterBase.php index 51e19e3..5ad0d81 100644 --- a/core/lib/Drupal/Core/Field/FormatterBase.php +++ b/core/lib/Drupal/Core/Field/FormatterBase.php @@ -104,9 +104,9 @@ public function view(FieldItemListInterface $items) { $addition = array_merge($info, $elements); } - // Otherwise, we're probably dealing with access cacheability metadata only. - // Just set the properties so that the necessary cache contexts and tags are - // bubbled. + // Otherwise, we are probably dealing with access and cacheability metadata + // only. Just set the properties so that the necessary cache contexts and + // tags are bubbled. elseif ($elements) { $addition = $elements; }