Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / core / modules / serialization / src / Normalizer / NormalizerBase.php
index 5e829f65e701a0b7b3f2c2a24713fbe1cc0e9691..8779b1a1b62f803790ca087e6440588aeef58da0 100644 (file)
@@ -2,13 +2,13 @@
 
 namespace Drupal\serialization\Normalizer;
 
-use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
+use Drupal\Core\Cache\CacheableDependencyInterface;
 use Symfony\Component\Serializer\Normalizer\SerializerAwareNormalizer;
 
 /**
  * Base class for Normalizers.
  */
-abstract class NormalizerBase extends SerializerAwareNormalizer implements NormalizerInterface {
+abstract class NormalizerBase extends SerializerAwareNormalizer implements CacheableNormalizerInterface {
 
   /**
    * The interface or class that this Normalizer supports.
@@ -81,4 +81,18 @@ abstract class NormalizerBase extends SerializerAwareNormalizer implements Norma
     return in_array($format, (array) $this->format, TRUE);
   }
 
+  /**
+   * Adds cacheability if applicable.
+   *
+   * @param array $context
+   *   Context options for the normalizer.
+   * @param $data
+   *   The data that might have cacheability information.
+   */
+  protected function addCacheableDependency(array $context, $data) {
+    if ($data instanceof CacheableDependencyInterface && isset($context[static::SERIALIZATION_CONTEXT_CACHEABILITY])) {
+      $context[static::SERIALIZATION_CONTEXT_CACHEABILITY]->addCacheableDependency($data);
+    }
+  }
+
 }