function CacheableNormalization::aggregate

Same name in other branches
  1. 9 core/modules/jsonapi/src/Normalizer/Value/CacheableNormalization.php \Drupal\jsonapi\Normalizer\Value\CacheableNormalization::aggregate()
  2. 8.9.x core/modules/jsonapi/src/Normalizer/Value/CacheableNormalization.php \Drupal\jsonapi\Normalizer\Value\CacheableNormalization::aggregate()
  3. 10 core/modules/jsonapi/src/Normalizer/Value/CacheableNormalization.php \Drupal\jsonapi\Normalizer\Value\CacheableNormalization::aggregate()

Collects an array of CacheableNormalizations into a single instance.

Parameters

\Drupal\jsonapi\Normalizer\Value\CacheableNormalization[] $cacheable_normalizations: An array of CacheableNormalizations.

Return value

static A new CacheableNormalization. Each input value's cacheability will be merged into the return value's cacheability. The return value's normalization will be an array of the input's normalizations. This method does *not* behave like array_merge() or NestedArray::mergeDeep().

6 calls to CacheableNormalization::aggregate()
DataNormalizer::normalize in core/modules/jsonapi/src/Normalizer/DataNormalizer.php
EntityReferenceFieldNormalizer::normalize in core/modules/jsonapi/src/Normalizer/EntityReferenceFieldNormalizer.php
FieldNormalizer::normalize in core/modules/jsonapi/src/Normalizer/FieldNormalizer.php
JsonApiDocumentTopLevelNormalizer::normalizeOmissionsLinks in core/modules/jsonapi/src/Normalizer/JsonApiDocumentTopLevelNormalizer.php
Normalizes omitted data into a set of omission links.
LinkCollectionNormalizer::normalize in core/modules/jsonapi/src/Normalizer/LinkCollectionNormalizer.php

... See full list

File

core/modules/jsonapi/src/Normalizer/Value/CacheableNormalization.php, line 106

Class

CacheableNormalization
Use to store normalized data and its cacheability.

Namespace

Drupal\jsonapi\Normalizer\Value

Code

public static function aggregate(array $cacheable_normalizations) {
    assert(Inspector::assertAllObjects($cacheable_normalizations, CacheableNormalization::class));
    return new static(array_reduce($cacheable_normalizations, function (CacheableMetadata $merged, CacheableNormalization $item) {
        return $merged->addCacheableDependency($item);
    }, new CacheableMetadata()), array_reduce(array_keys($cacheable_normalizations), function ($merged, $key) use ($cacheable_normalizations) {
        if (!$cacheable_normalizations[$key] instanceof CacheableOmission) {
            $merged[$key] = $cacheable_normalizations[$key]->getNormalization();
        }
        return $merged;
    }, []));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.