diff --git a/core/lib/Drupal/Core/Plugin/Context/Context.php b/core/lib/Drupal/Core/Plugin/Context/Context.php index 0f8bbbf..8253a5d 100644 --- a/core/lib/Drupal/Core/Plugin/Context/Context.php +++ b/core/lib/Drupal/Core/Plugin/Context/Context.php @@ -70,10 +70,8 @@ public function getContextValue() { */ public function setContextValue($value) { if ($value instanceof CacheableDependencyInterface) { - $this->setCacheableMetadata(CacheableMetadata::createFromObject($value)); - } - else { - $this->setCacheableMetadata(new CacheableMetadata()); + $this->getCacheableMetadata() + ->merge(CacheableMetadata::createFromObject($value)); } if ($value instanceof TypedDataInterface) { return $this->setContextData($value); @@ -140,6 +138,9 @@ public function setCacheableMetadata(CacheableMetadata $cache) { * {@inheritdoc} */ public function getCacheableMetadata() { + if (!$this->cache) { + $this->cache = new CacheableMetadata(); + } return $this->cache; } diff --git a/core/lib/Drupal/Core/Plugin/Context/ContextInterface.php b/core/lib/Drupal/Core/Plugin/Context/ContextInterface.php index 71859ca..dcda262 100644 --- a/core/lib/Drupal/Core/Plugin/Context/ContextInterface.php +++ b/core/lib/Drupal/Core/Plugin/Context/ContextInterface.php @@ -33,7 +33,6 @@ public function getContextData(); */ public function setContextData(TypedDataInterface $data); - /** * Set the CacheableMetadata for this context. *