core/lib/Drupal/Core/Access/AccessResultInterface.php | 4 +++- core/lib/Drupal/Core/Entity/Entity/EntityViewDisplay.php | 6 ++---- core/lib/Drupal/Core/Entity/EntityDisplayBase.php | 9 +++++++++ .../image/src/Plugin/Field/FieldFormatter/ImageFormatterBase.php | 5 +---- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/core/lib/Drupal/Core/Access/AccessResultInterface.php b/core/lib/Drupal/Core/Access/AccessResultInterface.php index 14bb204..6822436 100644 --- a/core/lib/Drupal/Core/Access/AccessResultInterface.php +++ b/core/lib/Drupal/Core/Access/AccessResultInterface.php @@ -7,6 +7,8 @@ namespace Drupal\Core\Access; +use Drupal\Core\Cache\CacheableDependencyInterface; + /** * Interface for access result value objects. * @@ -23,7 +25,7 @@ * would never enter the else-statement and hence introduce a critical security * issue. */ -interface AccessResultInterface { +interface AccessResultInterface extends CacheableDependencyInterface { /** * Checks whether this access result indicates access is explicitly allowed. diff --git a/core/lib/Drupal/Core/Entity/Entity/EntityViewDisplay.php b/core/lib/Drupal/Core/Entity/Entity/EntityViewDisplay.php index accdd92..444f591 100644 --- a/core/lib/Drupal/Core/Entity/Entity/EntityViewDisplay.php +++ b/core/lib/Drupal/Core/Entity/Entity/EntityViewDisplay.php @@ -8,6 +8,7 @@ namespace Drupal\Core\Entity\Entity; use Drupal\Component\Utility\NestedArray; +use Drupal\Core\Cache\CacheableDependencyInterface; use Drupal\Core\Entity\Display\EntityViewDisplayInterface; use Drupal\Core\Entity\EntityDisplayPluginCollection; use Drupal\Core\Entity\EntityStorageInterface; @@ -246,10 +247,7 @@ public function buildMultiple(array $entities) { $build_list[$id][$name] = $formatter->view($items); } // Apply the field access cacheability metadata to the render array. - // @todo Use RendererInterface::addDependency() when https://www.drupal.org/node/2444231 lands - BubbleableMetadata::createFromRenderArray($build_list[$id][$name]) - ->merge(BubbleableMetadata::createFromAccessResult($field_access)) - ->applyTo($build_list[$id][$name]); + $this->renderer->addDependency($build_list[$id][$name], $field_access); } } } diff --git a/core/lib/Drupal/Core/Entity/EntityDisplayBase.php b/core/lib/Drupal/Core/Entity/EntityDisplayBase.php index 96fa0de..ce1740f 100644 --- a/core/lib/Drupal/Core/Entity/EntityDisplayBase.php +++ b/core/lib/Drupal/Core/Entity/EntityDisplayBase.php @@ -115,6 +115,13 @@ protected $pluginManager; /** + * The renderer. + * + * @var \Drupal\Core\Render\RendererInterface + */ + protected $renderer; + + /** * {@inheritdoc} */ public function __construct(array $values, $entity_type) { @@ -126,6 +133,8 @@ public function __construct(array $values, $entity_type) { throw new \InvalidArgumentException('EntityDisplay entities can only handle fieldable entity types.'); } + $this->renderer = \Drupal::service('renderer'); + // A plugin manager and a context type needs to be set by extending classes. if (!isset($this->pluginManager)) { throw new \RuntimeException('Missing plugin manager.'); diff --git a/core/modules/image/src/Plugin/Field/FieldFormatter/ImageFormatterBase.php b/core/modules/image/src/Plugin/Field/FieldFormatter/ImageFormatterBase.php index dad8275..e637307 100644 --- a/core/modules/image/src/Plugin/Field/FieldFormatter/ImageFormatterBase.php +++ b/core/modules/image/src/Plugin/Field/FieldFormatter/ImageFormatterBase.php @@ -50,10 +50,7 @@ protected function getEntitiesToView(array &$build, EntityReferenceFieldItemList // Add the fallback image's cache tags to the render array, so that if // the fallback image is modified, all render cached fields displaying // the fallback image are updated. - // @todo Use RendererInterface::addDependency() when https://www.drupal.org/node/2444231 lands - BubbleableMetadata::createFromRenderArray($build) - ->merge(new BubbleableMetadata([], $file->getCacheTags())) - ->applyTo($build); + \Drupal::service('renderer')->addDependency($build, $file); } }