private function ContentEntityNormalizer::createEntityInstance in Replication 8.2
Same name and namespace in other branches
- 8 src/Normalizer/ContentEntityNormalizer.php \Drupal\replication\Normalizer\ContentEntityNormalizer::createEntityInstance()
Handles entity creation for fieldable and non-fieldable entities.
This makes sure denormalization runs on field items.
Parameters
array $data:
EntityTypeInterface $entity_type:
$format:
array $context:
Return value
\Drupal\Core\Entity\EntityInterface
See also
\Drupal\serialization\Normalizer\FieldableEntityNormalizerTrait
1 call to ContentEntityNormalizer::createEntityInstance()
- ContentEntityNormalizer::denormalize in src/
Normalizer/ ContentEntityNormalizer.php - Denormalizes data back into an object of the given class.
File
- src/
Normalizer/ ContentEntityNormalizer.php, line 535
Class
Namespace
Drupal\replication\NormalizerCode
private function createEntityInstance(array $data, EntityTypeInterface $entity_type, $format, array $context = []) {
// The bundle property will be required to denormalize a bundleable
// fieldable entity.
if ($entity_type
->entityClassImplements(FieldableEntityInterface::class)) {
// Extract bundle data to pass into entity creation if the entity type uses
// bundles.
if ($entity_type
->hasKey('bundle')) {
// Get an array containing the bundle only. This also remove the bundle
// key from the $data array.
$create_params = $this
->extractBundleData($data, $entity_type);
}
else {
$create_params = [];
}
// Create the entity from bundle data only, then apply field values after.
$entity = $this->entityManager
->getStorage($entity_type
->id())
->create($create_params);
$this
->denormalizeFieldData($data, $entity, $format, $context);
}
else {
// Create the entity from all data.
$entity = $this->entityManager
->getStorage($entity_type
->id())
->create($data);
}
return $entity;
}