protected function extractBundleData(array &
$data, EntityTypeInterface
$entity_type_definition) { $bundle_key =
$entity_type_definition->
getKey('bundle'
);
// Get the base field definitions for this entity type.
$base_field_definitions =
$this->
getEntityFieldManager()->
getBaseFieldDefinitions($entity_type_definition->
id());
// 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.