function TypedDataNormalizer::getNormalizationSchema
Same name and namespace in other branches
- 11.x core/modules/serialization/src/Normalizer/TypedDataNormalizer.php \Drupal\serialization\Normalizer\TypedDataNormalizer::getNormalizationSchema()
Overrides SchematicNormalizerTrait::getNormalizationSchema
File
-
core/
modules/ serialization/ src/ Normalizer/ TypedDataNormalizer.php, line 42
Class
- TypedDataNormalizer
- Normalizes typed data objects into strings or arrays.
Namespace
Drupal\serialization\NormalizerCode
protected function getNormalizationSchema(mixed $object, array $context = []) : array {
assert($object instanceof TypedDataInterface);
$value = $object->getValue();
$nullable = !$object->getDataDefinition()
->isRequired();
// Match the special-cased logic in ::normalize().
if (is_object($value) && method_exists($value, '__toString')) {
return $nullable ? [
'oneOf' => [
'string',
'null',
],
] : [
'type' => 'string',
];
}
return $this->getJsonSchemaForMethod($object, 'getValue', [
'$comment' => static::generateNoSchemaAvailableMessage($object),
], $nullable);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.