diff --git a/src/Importer.php b/src/Importer.php index e062781..f0faa7d 100644 --- a/src/Importer.php +++ b/src/Importer.php @@ -225,7 +225,10 @@ class Importer implements ImporterInterface { $entity = $this->contentEntityNormalizer->denormalize(Yaml::decode($contents)); } - $entity->enforceIsNew(TRUE); + if (empty($entity)) { + continue; + } + // Ensure that the entity is not owned by the anonymous user. if ($entity instanceof EntityOwnerInterface && empty($entity->getOwnerId())) { $entity->setOwner($root_user); @@ -314,3 +317,4 @@ class Importer implements ImporterInterface { } } + diff --git a/src/Normalizer/ContentEntityNormalizer.php b/src/Normalizer/ContentEntityNormalizer.php index 08d68ee..9a303fa 100644 --- a/src/Normalizer/ContentEntityNormalizer.php +++ b/src/Normalizer/ContentEntityNormalizer.php @@ -178,8 +178,15 @@ class ContentEntityNormalizer implements ContentEntityNormalizerInterface { $values[$entity_type->getKey('langcode')] = $data['_meta']['default_langcode']; } + // Check exits. /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */ - $entity = $this->entityTypeManager->getStorage($entity_type->id())->create($values); + $entity = $this->entityTypeManager->getStorage($entity_type->id())->loadByProperties(['uuid' => $values['uuid']]); + $entity = reset($entity); + $exists = !empty($entity); + if (!$exists) { + $entity = $this->entityTypeManager->getStorage($entity_type->id())->create($values); + } + foreach ($data['default'] as $field_name => $values) { $this->setFieldValues($entity, $field_name, $values); } @@ -518,3 +525,4 @@ class ContentEntityNormalizer implements ContentEntityNormalizerInterface { } } +