public function normalize($field,
$format = NULL, array
$context =
[]): array|string|int|float|bool|\ArrayObject|NULL
{ assert($field instanceof EntityReferenceFieldItemListInterface
);
// Build the relationship object based on the Entity Reference and normalize
// that object instead.
$resource_identifiers =
array_filter(ResourceIdentifier::
toResourceIdentifiers($field->
filterEmptyItems()),
function DResourceIdentifierInterface
$resource_identifier) { return !
$resource_identifier->
getResourceType()->
isInternal();
});
$normalized_items = CacheableNormalization::
aggregate($this->serializer->
normalize($resource_identifiers,
$format,
$context));
assert($context['resource_object'
] instanceof ResourceObject
);
$resource_relationship =
$context['resource_object'
]->
getResourceType()->
getFieldByInternalName($field->
getName());
assert($resource_relationship instanceof ResourceTypeRelationship
);
$link_cacheability =
new CacheableMetadata();
$links =
array_map(function DUrl
$link) use ($link_cacheability) { $href =
$link->
setAbsolute()->
toString(TRUE
);
$link_cacheability->
addCacheableDependency($href);
return ['href' =>
$href->
getGeneratedUrl()];
},
static::
getRelationshipLinks($context['resource_object'
],
$resource_relationship));
$data_normalization =
$normalized_items->
getNormalization();
$normalization =
[ // Empty 'to-one' relationships must be NULL.
// Empty 'to-many' relationships must be an empty array.