You are here

public function HttpExceptionNormalizer::normalize in JSON:API 8

Same name and namespace in other branches
  1. 8.2 src/Normalizer/HttpExceptionNormalizer.php \Drupal\jsonapi\Normalizer\HttpExceptionNormalizer::normalize()

File

src/Normalizer/HttpExceptionNormalizer.php, line 50

Class

HttpExceptionNormalizer
Normalizes an HttpException in compliance with the JSON API specification.

Namespace

Drupal\jsonapi\Normalizer

Code

public function normalize($object, $format = NULL, array $context = []) {
  $errors = $this
    ->buildErrorObjects($object);
  $errors = array_map(function ($error) {

    // @todo Either this should not use FieldItemNormalizerValue, or FieldItemNormalizerValue needs to be renamed to not be semantically coupled to "fields".
    return new FieldItemNormalizerValue([
      $error,
    ], new CacheableMetadata());
  }, $errors);

  // @todo The access result, cardinality and property type make no sense for HTTP exceptions, but it's because HttpExceptionNormalizerValue inappropriately subclasses FieldNormalizerValue
  return new HttpExceptionNormalizerValue(AccessResult::allowed(), $errors, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED, 'attributes');
}