protected static function LinkCollectionNormalizer::addLinkRels in Consumer Image Styles 4.x
Same name and namespace in other branches
- 8.3 src/Normalizer/LinkCollectionNormalizer.php \Drupal\consumer_image_styles\Normalizer\LinkCollectionNormalizer::addLinkRels()
Adds the derivative link relation type to the normalized link collection.
Parameters
\Drupal\jsonapi\Normalizer\Value\CacheableNormalization $cacheable_normalization: The cacheable normalization to which link relations need to be added.
\Drupal\jsonapi\JsonApiResource\LinkCollection $link_collection: The un-normalized link collection.
Return value
\Drupal\jsonapi\Normalizer\Value\CacheableNormalization The links normalization with meta.rel added.
File
- src/
Normalizer/ LinkCollectionNormalizer.php, line 183
Class
- LinkCollectionNormalizer
- Custom normalizer that add the derivatives to image entities.
Namespace
Drupal\consumer_image_styles\NormalizerCode
protected static function addLinkRels(CacheableNormalization $cacheable_normalization, LinkCollection $link_collection) {
$normalization = $cacheable_normalization
->getNormalization();
foreach ($normalization as $key => &$normalized_link) {
$links = iterator_to_array($link_collection);
if (isset($links[$key])) {
$normalized_link['meta']['rel'] = array_reduce($links[$key], function (array $relations, Link $link) {
$relations[] = $link
->getLinkRelationType();
return array_unique($relations);
}, []);
}
}
return new CacheableNormalization($cacheable_normalization, $normalization);
}