diff --git a/core/lib/Drupal/Core/Access/AccessResult.php b/core/lib/Drupal/Core/Access/AccessResult.php index 23de421..24d5051 100644 --- a/core/lib/Drupal/Core/Access/AccessResult.php +++ b/core/lib/Drupal/Core/Access/AccessResult.php @@ -339,6 +339,7 @@ public function cacheUntilConfigurationChanges(ConfigBase $configuration) { * {@inheritdoc} */ public function orIf(AccessResultInterface $other) { + $merge_other = FALSE; // $other's cacheability metadata is merged if $merge_other gets set to TRUE // and this happens in three cases: // 1. $other's access result is the one that determines the combined access @@ -356,7 +357,6 @@ public function orIf(AccessResultInterface $other) { // which means that even if a user of a different role logs in, the // cached access result will be used, even though for that other role, B // is forbidden! - $merge_other = FALSE; if ($this->isForbidden() || $other->isForbidden()) { $result = static::forbidden(); if (!$this->isForbidden() || ($this->getCacheMaxAge() === 0 && $other->isForbidden())) { diff --git a/core/lib/Drupal/Core/Entity/Entity/EntityViewDisplay.php b/core/lib/Drupal/Core/Entity/Entity/EntityViewDisplay.php index 441a501..6712fb5 100644 --- a/core/lib/Drupal/Core/Entity/Entity/EntityViewDisplay.php +++ b/core/lib/Drupal/Core/Entity/Entity/EntityViewDisplay.php @@ -240,10 +240,7 @@ public function buildMultiple(array $entities) { $items = $grouped_items[$id]; /** @var \Drupal\Core\Access\AccessResultInterface $field_access */ $field_access = $items->access('view', NULL, TRUE); - $build_list[$id][$name] = []; - if ($field_access->isAllowed()) { - $build_list[$id][$name] = $formatter->view($items); - } + $build_list[$id][$name] = $field_access->isAllowed() ? $formatter->view($items) : []; // Apply the field access cacheability metadata to the render array. $this->renderer->addDependency($build_list[$id][$name], $field_access); } diff --git a/core/lib/Drupal/Core/Field/FormatterBase.php b/core/lib/Drupal/Core/Field/FormatterBase.php index fa064ba..0a1b2ce 100644 --- a/core/lib/Drupal/Core/Field/FormatterBase.php +++ b/core/lib/Drupal/Core/Field/FormatterBase.php @@ -77,12 +77,10 @@ public function __construct($plugin_id, $plugin_definition, FieldDefinitionInter * {@inheritdoc} */ public function view(FieldItemListInterface $items) { - $addition = array(); - $elements = $this->viewElements($items); // If there are actual renderable children, use #theme => field. - if (count($elements) !== count(Element::properties($elements))) { + if (Element::properties($elements)) { $entity = $items->getEntity(); $entity_type = $entity->getEntityTypeId(); $field_name = $this->fieldDefinition->getName(); @@ -102,16 +100,10 @@ public function view(FieldItemListInterface $items) { '#formatter' => $this->getPluginId(), ); - $addition = array_merge($info, $elements); - } - // Otherwise, we are dealing with access cacheability metadata only (i.e. - // only the #cache property is set). Pass this, so that the necessary cache - // contexts and tags are bubbled. - elseif ($elements) { - $addition = $elements; + $elements = array_merge($info, $elements); } - return $addition; + return $elements; } /** diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/EntityReferenceFormatterBase.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/EntityReferenceFormatterBase.php index da534f9..a593322 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/EntityReferenceFormatterBase.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/EntityReferenceFormatterBase.php @@ -47,7 +47,7 @@ protected function getEntitiesToView(EntityReferenceFieldItemListInterface $item $parent_entity_langcode = $items->getEntity()->language()->getId(); foreach ($items as $delta => $item) { // Ignore items where no entity could be loaded in prepareView(). - if (!empty($item->_loaded)) { + if (!empty($item->_accessCacheability)) { /** @var \Drupal\Core\Entity\EntityInterface $entity */ $entity = $item->entity; @@ -77,7 +77,7 @@ protected function getEntitiesToView(EntityReferenceFieldItemListInterface $item * @see ::getEntitiestoView() */ public function view(FieldItemListInterface $items) { - $addition = parent::view($items); + $elements = parent::view($items); $field_level_access_cacheability = new BubbleableMetadata(); @@ -88,10 +88,10 @@ public function view(FieldItemListInterface $items) { foreach ($items as $delta => $item) { // Ignore items where no entity could be loaded in prepareView(). if (!empty($item->_loaded)) { - if (isset($addition[$delta])) { - BubbleableMetadata::createFromRenderArray($addition[$delta]) + if (isset($elements[$delta])) { + BubbleableMetadata::createFromRenderArray($elements[$delta]) ->merge($item->_accessCacheability) - ->applyTo($addition[$delta]); + ->applyTo($elements[$delta]); } else { $field_level_access_cacheability = $field_level_access_cacheability->merge($item->_accessCacheability); @@ -102,14 +102,14 @@ public function view(FieldItemListInterface $items) { // Apply the cacheability metadata for the inaccessible entities and the // entities for which the corresponding render subtree could not be found. // This causes the field to be rendered (and cached) according to the cache - // contexts by which the access results vary, to ensure only uses with + // contexts by which the access results vary, to ensure only users with // access to this field can view it. It also tags this field with the cache // tags on which the access results depend, to ensure users that cannot view // this field at the moment will gain access once any of those cache tags // are invalidated. - $field_level_access_cacheability->applyTo($addition); + $field_level_access_cacheability->applyTo($elements); - return $addition; + return $elements; } /** diff --git a/core/modules/file/src/Plugin/Field/FieldFormatter/RSSEnclosureFormatter.php b/core/modules/file/src/Plugin/Field/FieldFormatter/RSSEnclosureFormatter.php index 0a7b98f..2706e2f 100644 --- a/core/modules/file/src/Plugin/Field/FieldFormatter/RSSEnclosureFormatter.php +++ b/core/modules/file/src/Plugin/Field/FieldFormatter/RSSEnclosureFormatter.php @@ -26,7 +26,6 @@ class RSSEnclosureFormatter extends FileFormatterBase { * {@inheritdoc} */ public function viewElements(FieldItemListInterface $items) { - $elements = []; $entity = $items->getEntity(); // Add the first file as an enclosure to the RSS item. RSS allows only one // enclosure per item. See: http://en.wikipedia.org/wiki/RSS_enclosure @@ -40,7 +39,7 @@ public function viewElements(FieldItemListInterface $items) { ), ); } - return $elements; + return []; } }