.../serialization/src/Normalizer/EntityNormalizer.php | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/core/modules/serialization/src/Normalizer/EntityNormalizer.php b/core/modules/serialization/src/Normalizer/EntityNormalizer.php index 84baec9..4103d1d 100644 --- a/core/modules/serialization/src/Normalizer/EntityNormalizer.php +++ b/core/modules/serialization/src/Normalizer/EntityNormalizer.php @@ -40,13 +40,20 @@ public function denormalize($data, $class, $format = NULL, array $context = []) // The bundle property will be required to denormalize a bundleable // fieldable entity. - if ($entity_type_definition->hasKey('bundle') && $entity_type_definition->isSubclassOf(FieldableEntityInterface::class)) { - // Get an array containing the bundle only. This also remove the bundle - // key from the $data array. - $bundle_data = $this->extractBundleData($data, $entity_type_definition); + if ($entity_type_definition->isSubclassOf(FieldableEntityInterface::class)) { + // Extract bundle data to pass into entity creation if the entity type uses + // bundles. + if ($entity_type_definition->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_definition); + } + else { + $create_params = []; + } // Create the entity from bundle data only, then apply field values after. - $entity = $this->entityManager->getStorage($entity_type_id)->create($bundle_data); + $entity = $this->entityManager->getStorage($entity_type_id)->create($create_params); $this->denormalizeFieldData($data, $entity, $format, $context); }