function TypedDataNormalizer::doNormalize

Same name and namespace in other branches
  1. 11.x core/modules/serialization/src/Normalizer/TypedDataNormalizer.php \Drupal\serialization\Normalizer\TypedDataNormalizer::doNormalize()

Normalizes data into a set of arrays/scalars.

Parameters

object $object: 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.

Overrides SchematicNormalizerTrait::doNormalize

File

core/modules/serialization/src/Normalizer/TypedDataNormalizer.php, line 29

Class

TypedDataNormalizer
Normalizes typed data objects into strings or arrays.

Namespace

Drupal\serialization\Normalizer

Code

public function doNormalize($object, $format = NULL, array $context = []) : array|string|int|float|bool|\ArrayObject|null {
  $this->addCacheableDependency($context, $object);
  $value = $object->getValue();
  // Support for stringable value objects: avoid numerous custom normalizers.
  if (is_object($value) && method_exists($value, '__toString')) {
    $value = (string) $value;
  }
  return $value;
}

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