if (!
$field instanceof ReferenceVersionField
) { throw DataAbstractionLayerException::
invalidSerializerField(ReferenceVersionField::
class,
$field);
} $value =
$data[$field->
getPropertyName()] ?? null;
if ($value === null && !
$field->
is(Required::
class)) { return $data;
} $definition =
$parameters->
getDefinition();
$reference =
$field->
getVersionReferenceDefinition();
$context =
$parameters->
getContext();
if ($value !== null ||
$definition ===
$reference) { // parent inheritance with versioning
$value ??= Defaults::LIVE_VERSION;
} elseif ($context->
has($reference->
getEntityName(), 'versionId'
)) { // if the reference is already written, use the version id of the written entity
$value =
$context->
get($reference->
getEntityName(), 'versionId'
);
} elseif ($definition->
getParentDefinition() ===
$reference &&
$context->
has($definition->
getEntityName(), 'versionId'
)) { // if the current entity is a sub entity (e.g. order -> line-item)