You are here

public function TypedDataNormalizer::normalize in Drupal 8

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

File

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

Class

TypedDataNormalizer
Converts typed data objects to arrays.

Namespace

Drupal\serialization\Normalizer

Code

public function normalize($object, $format = NULL, array $context = []) {
  $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;
}