function Serializer::normalize

Same name and namespace in other branches
  1. 10 core/modules/jsonapi/src/Serializer/Serializer.php \Drupal\jsonapi\Serializer\Serializer::normalize()
  2. 11.x core/modules/jsonapi/src/Serializer/Serializer.php \Drupal\jsonapi\Serializer\Serializer::normalize()
  3. 9 core/modules/jsonapi/src/Serializer/Serializer.php \Drupal\jsonapi\Serializer\Serializer::normalize()
  4. 8.9.x core/modules/jsonapi/src/Serializer/Serializer.php \Drupal\jsonapi\Serializer\Serializer::normalize()

Normalizes data into a set of arrays/scalars.

Parameters

mixed $data: Data to normalize.

string|null $format: Format the normalization result will be encoded as.

array<string, mixed> $context: Context options for the normalizer.

Return value

array|string|int|float|bool|\ArrayObject<mixed, mixed>|null \ArrayObject is used to make sure an empty object is encoded as an object not an array.

File

core/modules/jsonapi/src/Serializer/Serializer.php, line 75

Class

Serializer
Overrides the Symfony serializer to cordon off our incompatible normalizers.

Namespace

Drupal\jsonapi\Serializer

Code

public function normalize($data, $format = NULL, array $context = []) : array|string|int|float|bool|\ArrayObject|null {
  if ($this->selfSupportsNormalization($data, $format, $context)) {
    return parent::normalize($data, $format, $context);
  }
  if ($this->fallbackNormalizer
    ->supportsNormalization($data, $format, $context)) {
    return $this->fallbackNormalizer
      ->normalize($data, $format, $context);
  }
  return parent::normalize($data, $format, $context);
}

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