.../Field/FieldFormatter/EntityReferenceFormatterBase.php | 2 +- .../Field/FieldFormatter/EntityReferenceLabelFormatter.php | 4 ---- .../system/src/Tests/Entity/EntityViewBuilderTest.php | 14 +++++++------- 3 files changed, 8 insertions(+), 12 deletions(-) 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 cac7341..3e7f31d 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/EntityReferenceFormatterBase.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/EntityReferenceFormatterBase.php @@ -71,7 +71,7 @@ protected function getEntitiesToView(array &$build, EntityReferenceFieldItemList // Check entity access if needed. $access = $this->defaultAccess($item); if (!$access->isAllowed()) { - $access = $this->defaultAccess($item)->orIf($entity->access('view', NULL, TRUE)); + $access = $access->orIf($entity->access('view', NULL, TRUE)); } $access_cacheability = BubbleableMetadata::createFromAccessResult($access); if ($access->isAllowed()) { diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/EntityReferenceLabelFormatter.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/EntityReferenceLabelFormatter.php index abc5858..b719965 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/EntityReferenceLabelFormatter.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/EntityReferenceLabelFormatter.php @@ -11,7 +11,6 @@ use Drupal\Core\Entity\Exception\UndefinedLinkTemplateException; use Drupal\Core\Field\FieldItemListInterface; use Drupal\Core\Form\FormStateInterface; -use Drupal\Core\TypedData\TranslatableInterface; /** * Plugin implementation of the 'entity reference label' formatter. @@ -103,9 +102,6 @@ public function viewElements(FieldItemListInterface $items) { $elements[$delta] = array('#markup' => SafeMarkup::checkPlain($label)); } - if ($entity instanceof TranslatableInterface && $entity->isTranslatable()) { - $elements[$delta]['#cache']['contexts'][] = 'language'; - } $elements[$delta]['#cache']['tags'] = $entity->getCacheTags(); $this->setAccessCacheability($elements[$delta], $entity); } diff --git a/core/modules/system/src/Tests/Entity/EntityViewBuilderTest.php b/core/modules/system/src/Tests/Entity/EntityViewBuilderTest.php index 6e87d2d..dd6b226 100644 --- a/core/modules/system/src/Tests/Entity/EntityViewBuilderTest.php +++ b/core/modules/system/src/Tests/Entity/EntityViewBuilderTest.php @@ -58,12 +58,12 @@ public function testEntityViewBuilderCache() { // Test that new entities (before they are saved for the first time) do not // generate a cache entry. $build = $this->container->get('entity.manager')->getViewBuilder('entity_test')->view($entity_test, 'full'); - $this->assertTrue(isset($build['#cache']) && array_keys($build['#cache']) == ['tags', 'contexts'], 'The render array element of new (unsaved) entities is not cached, but does have cache tags set.'); + $this->assertTrue(isset($build['#cache']) && array_keys($build['#cache']) == ['tags'], 'The render array element of new (unsaved) entities is not cached, but does have cache tags set.'); // Get a fully built entity view render array. $entity_test->save(); $build = $this->container->get('entity.manager')->getViewBuilder('entity_test')->view($entity_test, 'full'); - $cid_parts = array_merge($build['#cache']['keys'], $cache_contexts->convertTokensToKeys(Cache::mergeContexts($build['#cache']['contexts'], ['languages:' . LanguageInterface::TYPE_INTERFACE, 'theme']))); + $cid_parts = array_merge($build['#cache']['keys'], $cache_contexts->convertTokensToKeys(['languages:' . LanguageInterface::TYPE_INTERFACE, 'theme'])); $cid = implode(':', $cid_parts); $bin = $build['#cache']['bin']; @@ -113,7 +113,7 @@ public function testEntityViewBuilderCacheWithReferences() { // Get a fully built entity view render array for the referenced entity. $build = $this->container->get('entity.manager')->getViewBuilder('entity_test')->view($entity_test_reference, 'full'); - $cid_parts = array_merge($build['#cache']['keys'], $cache_contexts->convertTokensToKeys(Cache::mergeContexts($build['#cache']['contexts'], ['languages:' . LanguageInterface::TYPE_INTERFACE, 'theme']))); + $cid_parts = array_merge($build['#cache']['keys'], $cache_contexts->convertTokensToKeys(['languages:' . LanguageInterface::TYPE_INTERFACE, 'theme'])); $cid_reference = implode(':', $cid_parts); $bin_reference = $build['#cache']['bin']; @@ -132,7 +132,7 @@ public function testEntityViewBuilderCacheWithReferences() { // Get a fully built entity view render array. $build = $this->container->get('entity.manager')->getViewBuilder('entity_test')->view($entity_test, 'full'); - $cid_parts = array_merge($build['#cache']['keys'], $cache_contexts->convertTokensToKeys(Cache::mergeContexts($build['#cache']['contexts'], ['languages:' . LanguageInterface::TYPE_INTERFACE, 'theme']))); + $cid_parts = array_merge($build['#cache']['keys'], $cache_contexts->convertTokensToKeys(['languages:' . LanguageInterface::TYPE_INTERFACE, 'theme'])); $cid = implode(':', $cid_parts); $bin = $build['#cache']['bin']; @@ -163,17 +163,17 @@ public function testEntityViewBuilderCacheToggling() { // Test a view mode in default conditions: render caching is enabled for // the entity type and the view mode. $build = $this->container->get('entity.manager')->getViewBuilder('entity_test')->view($entity_test, 'full'); - $this->assertTrue(isset($build['#cache']) && array_keys($build['#cache']) == ['tags', 'contexts', 'keys', 'bin'] , 'A view mode with render cache enabled has the correct output (cache tags, keys, contexts and bin).'); + $this->assertTrue(isset($build['#cache']) && array_keys($build['#cache']) == ['tags', 'keys', 'bin'] , 'A view mode with render cache enabled has the correct output (cache tags, keys, and bin).'); // Test that a view mode can opt out of render caching. $build = $this->container->get('entity.manager')->getViewBuilder('entity_test')->view($entity_test, 'test'); - $this->assertTrue(isset($build['#cache']) && array_keys($build['#cache']) == ['tags', 'contexts'], 'A view mode with render cache disabled has the correct output (only cache tags).'); + $this->assertTrue(isset($build['#cache']) && array_keys($build['#cache']) == ['tags'], 'A view mode with render cache disabled has the correct output (only cache tags).'); // Test that an entity type can opt out of render caching completely. $entity_test_no_cache = $this->createTestEntity('entity_test_label'); $entity_test_no_cache->save(); $build = $this->container->get('entity.manager')->getViewBuilder('entity_test_label')->view($entity_test_no_cache, 'full'); - $this->assertTrue(isset($build['#cache']) && array_keys($build['#cache']) == ['tags', 'contexts'], 'An entity type can opt out of render caching regardless of view mode configuration, but always has cache tags set.'); + $this->assertTrue(isset($build['#cache']) && array_keys($build['#cache']) == ['tags'], 'An entity type can opt out of render caching regardless of view mode configuration, but always has cache tags set.'); } /**