function JsonApiDocumentTopLevelNormalizer::normalizeErrorDocument

Same name in other branches
  1. 8.9.x core/modules/jsonapi/src/Normalizer/JsonApiDocumentTopLevelNormalizer.php \Drupal\jsonapi\Normalizer\JsonApiDocumentTopLevelNormalizer::normalizeErrorDocument()
  2. 10 core/modules/jsonapi/src/Normalizer/JsonApiDocumentTopLevelNormalizer.php \Drupal\jsonapi\Normalizer\JsonApiDocumentTopLevelNormalizer::normalizeErrorDocument()
  3. 11.x core/modules/jsonapi/src/Normalizer/JsonApiDocumentTopLevelNormalizer.php \Drupal\jsonapi\Normalizer\JsonApiDocumentTopLevelNormalizer::normalizeErrorDocument()

Normalizes an error collection.

@todo: refactor this to use CacheableNormalization::aggregate in https://www.drupal.org/project/drupal/issues/3036284.

Parameters

\Drupal\jsonapi\JsonApiResource\JsonApiDocumentTopLevel $document: The document to normalize.

string $format: The normalization format.

array $context: The normalization context.

Return value

\Drupal\jsonapi\Normalizer\Value\CacheableNormalization The normalized document.

1 call to JsonApiDocumentTopLevelNormalizer::normalizeErrorDocument()
JsonApiDocumentTopLevelNormalizer::normalize in core/modules/jsonapi/src/Normalizer/JsonApiDocumentTopLevelNormalizer.php

File

core/modules/jsonapi/src/Normalizer/JsonApiDocumentTopLevelNormalizer.php, line 224

Class

JsonApiDocumentTopLevelNormalizer
Normalizes the top-level document according to the JSON:API specification.

Namespace

Drupal\jsonapi\Normalizer

Code

protected function normalizeErrorDocument(JsonApiDocumentTopLevel $document, $format, array $context = []) {
    $normalized_values = array_map(function (HttpExceptionInterface $exception) use ($format, $context) {
        return $this->serializer
            ->normalize($exception, $format, $context);
    }, (array) $document->getData()
        ->getIterator());
    $cacheability = new CacheableMetadata();
    $errors = [];
    foreach ($normalized_values as $normalized_error) {
        $cacheability->addCacheableDependency($normalized_error);
        $errors = array_merge($errors, $normalized_error->getNormalization());
    }
    return new CacheableNormalization($cacheability, $errors);
}

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