class FieldNormalizer extends NormalizerBase
implements DenormalizerInterface
{ /**
* {@inheritdoc}
*/
public function normalize($field,
$format = NULL, array
$context =
[]): array|string|int|float|bool|\ArrayObject|NULL
{ /** @var \Drupal\Core\Field\FieldItemListInterface $field */
$normalized_items =
$this->
normalizeFieldItems($field,
$format,
$context);
assert($context['resource_object'
] instanceof ResourceObject
);
return $context['resource_object'
]->
getResourceType()->
getFieldByInternalName($field->
getName())->
hasOne() ?
array_shift($normalized_items) ?: CacheableNormalization::
permanent(NULL
) : CacheableNormalization::
aggregate($normalized_items);
} /**
* {@inheritdoc}
*/
public function denormalize($data,
$class,
$format = NULL, array
$context =
[]): mixed
{ $field_definition =
$context['field_definition'
];