You are here

public function ResourceIdentifierNormalizer::normalize in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/jsonapi/src/Normalizer/ResourceIdentifierNormalizer.php \Drupal\jsonapi\Normalizer\ResourceIdentifierNormalizer::normalize()

File

core/modules/jsonapi/src/Normalizer/ResourceIdentifierNormalizer.php, line 51

Class

ResourceIdentifierNormalizer
Normalizes a Relationship according to the JSON:API specification.

Namespace

Drupal\jsonapi\Normalizer

Code

public function normalize($object, $format = NULL, array $context = []) {
  assert($object instanceof ResourceIdentifier);
  $normalization = [
    'type' => $object
      ->getTypeName(),
    'id' => $object
      ->getId(),
  ];
  if ($object
    ->getMeta()) {
    $normalization['meta'] = $this->serializer
      ->normalize($object
      ->getMeta(), $format, $context);
  }
  return CacheableNormalization::permanent($normalization);
}