// Get the ID key from the base field definition for the bundle key or
// default to 'value'.
$key_id =
isset($base_field_definitions[$bundle_key]) ?
$base_field_definitions[$bundle_key]->
getFieldStorageDefinition()->
getMainPropertyName() : 'value';
// Normalize the bundle if it is not explicitly set.
$bundle_value =
$data[$bundle_key][0
][$key_id] ?? ($data[$bundle_key] ?? NULL
);
// Unset the bundle from the data.
unset($data[$bundle_key]);
// Get the bundle entity type from the entity type definition.
$bundle_type_id =
$entity_type_definition->
getBundleEntityType();
$bundle_types =
$bundle_type_id ?
$this->
getEntityTypeManager()->
getStorage($bundle_type_id)->
getQuery()->
accessCheck(TRUE
)->
execute() :
[];
// Make sure a bundle has been provided.
if (!
is_string($bundle_value)) { throw new UnexpectedValueException(sprintf('Could not determine entity type bundle: "%s" field is missing.',
$bundle_key));
} // Make sure the submitted bundle is a valid bundle for the entity type.
if ($bundle_types && !
in_array($bundle_value,
$bundle_types)) { throw new UnexpectedValueException(sprintf('"%s" is not a valid bundle type for denormalization.',
$bundle_value));
}