diff --git a/src/Normalizer/JsonApiDocumentTopLevelNormalizer.php b/src/Normalizer/JsonApiDocumentTopLevelNormalizer.php index 1669583..c5b3021 100644 --- a/src/Normalizer/JsonApiDocumentTopLevelNormalizer.php +++ b/src/Normalizer/JsonApiDocumentTopLevelNormalizer.php @@ -2,7 +2,6 @@ namespace Drupal\jsonapi\Normalizer; -use Drupal\Component\Assertion\Inspector; use Drupal\Component\Plugin\Exception\PluginNotFoundException; use Drupal\Component\Utility\Crypt; use Drupal\Component\Utility\NestedArray; @@ -346,7 +345,7 @@ class JsonApiDocumentTopLevelNormalizer extends NormalizerBase implements Denorm $normalizer_values = array_merge($normalizer_values, $omissions); } - $links = $this->serializer->normalize($document->getLinks()); + $links = $this->serializer->normalize($document->getLinks(), $format, $context); $rasterized['links'] = $links->getNormalization(); $cacheability->addCacheableDependency($links); diff --git a/src/Normalizer/LinkCollectionNormalizer.php b/src/Normalizer/LinkCollectionNormalizer.php index 9a6d7d1..56479cb 100644 --- a/src/Normalizer/LinkCollectionNormalizer.php +++ b/src/Normalizer/LinkCollectionNormalizer.php @@ -3,10 +3,9 @@ namespace Drupal\jsonapi\Normalizer; use Drupal\Component\Utility\Crypt; -use Drupal\Core\Cache\CacheableMetadata; use Drupal\jsonapi\JsonApiResource\LinkCollection; use Drupal\jsonapi\JsonApiResource\Link; -use Drupal\jsonapi\Normalizer\Value\NormalizedValue; +use Drupal\jsonapi\Normalizer\Value\CacheableNormalization; /** * Normalizes a LinkCollection object. @@ -65,31 +64,17 @@ class LinkCollectionNormalizer extends NormalizerBase { public function normalize($object, $format = NULL, array $context = []) { assert($object instanceof LinkCollection); $normalized = []; - $cacheability = new CacheableMetadata(); /* @var \Drupal\jsonapi\JsonApiResource\Link $link */ foreach ($object as $key => $links) { $is_multiple = count($links) > 1; foreach ($links as $link) { - /* @var \Drupal\jsonapi\Normalizer\Value\NormalizedValue $normalized_link */ $link_key = $is_multiple ? sprintf('%s:%s', $key, $this->hashByHref($link)) : $key; - $normalized_link = $this->normalizeLink($link); - $cacheability->addCacheableDependency($normalized_link); - $normalized[$link_key] = $normalized_link->rasterizeValue(); + $attributes = $link->getTargetAttributes(); + $normalization = array_merge(['href' => $link->getHref()], !empty($attributes) ? ['meta' => $attributes] : []); + $normalized[$link_key] = new CacheableNormalization($link, $normalization); } } - return new NormalizedValue($cacheability, $normalized); - } - - /** - * {@inheritdoc} - */ - protected function normalizeLink(Link $link) { - /* @var \Drupal\jsonapi\JsonApiResource\Link $object */ - $normalized = ['href' => $link->getHref()]; - if (!empty($attributes = $link->getTargetAttributes())) { - $normalized['meta'] += $attributes; - } - return new NormalizedValue($link, $normalized); + return CacheableNormalization::aggregate($normalized); } /** diff --git a/src/Normalizer/Value/NormalizedValue.php b/src/Normalizer/Value/NormalizedValue.php deleted file mode 100644 index 46ebebb..0000000 --- a/src/Normalizer/Value/NormalizedValue.php +++ /dev/null @@ -1,51 +0,0 @@ -value = $value; - $this->setCacheability($cacheability); - } - - /** - * {@inheritdoc} - */ - public function rasterizeValue() { - return $this->value; - } - - /** - * {@inheritdoc} - */ - public function rasterizeIncludes() { - return []; - } - -}