public function normalize($field_item,
$format = NULL, array
$context =
[]): array|string|int|float|bool|\ArrayObject|NULL
{ assert($field_item instanceof FieldItemInterface
);
/** @var \Drupal\Core\TypedData\TypedDataInterface $property */
$values =
[];
$context[CacheableNormalizerInterface::SERIALIZATION_CONTEXT_CACHEABILITY
] =
new CacheableMetadata();
if (!
empty($field_item->
getProperties(TRUE
))) { // We normalize each individual value, so each can do their own casting,
// if needed.
$field_properties = TypedDataInternalPropertiesHelper::
getNonInternalProperties($field_item);
foreach ($field_properties as $property_name =>
$property) { $values[$property_name] =
$this->serializer->
normalize($property,
$format,
$context);
} // Flatten if there is only a single property to normalize.
$flatten =
count($field_properties) === 1 &&
$field_item::
mainPropertyName() !== NULL;
$values =
static::
rasterizeValueRecursive($flatten ?
reset($values) :
$values);
} else { $values =
$field_item->
getValue();
} $normalization =
new CacheableNormalization(