Loading core/lib/Drupal/Core/DefaultContent/Importer.php +1 −1 Original line number Diff line number Diff line Loading @@ -123,7 +123,7 @@ public function importContent(Finder $content, Existing $existing = Existing::Er } } $entity = $this->toEntity($decoded)->enforceIsNew(); $entity = $this->toEntity($decoded)->enforceIsNew()->setSyncing(TRUE); // Ensure that the entity is not owned by the anonymous user. if ($entity instanceof EntityOwnerInterface && empty($entity->getOwnerId())) { Loading core/tests/Drupal/KernelTests/Core/DefaultContent/ImporterTest.php +20 −0 Original line number Diff line number Diff line Loading @@ -7,7 +7,9 @@ use Drupal\Core\DefaultContent\Finder; use Drupal\Core\DefaultContent\Importer; use Drupal\Core\DefaultContent\PreEntityImportEvent; use Drupal\Core\Entity\ContentEntityInterface; use Drupal\Core\Entity\EntityRepositoryInterface; use Drupal\Core\Hook\Attribute\Hook; use Drupal\KernelTests\KernelTestBase; use Drupal\Tests\user\Traits\UserCreationTrait; use PHPUnit\Framework\Attributes\CoversClass; Loading @@ -31,6 +33,15 @@ class ImporterTest extends KernelTestBase implements EventSubscriberInterface { */ protected static $modules = ['system', 'user', 'entity_test']; /** * Whether the imported content entities were syncing. * * @var bool * * @see ::onPreSave() */ private bool $wasSyncing = FALSE; /** * {@inheritdoc} */ Loading @@ -51,6 +62,14 @@ public static function getSubscribedEvents(): array { ]; } /** * Implements hook_ENTITY_TYPE_presave() for entity_test entities. */ #[Hook('entity_test_presave')] public function onPreSave(ContentEntityInterface $entity): void { $this->wasSyncing = $entity->isSyncing(); } /** * Modify entity data before it is imported. * Loading @@ -77,6 +96,7 @@ public function testChangeDataOnImport(): void { $finder = new Finder($this->getDrupalRoot() . '/core/tests/fixtures/pre_entity_import_default_content'); $this->container->get(Importer::class)->importContent($finder); self::assertTrue($this->wasSyncing); $entity = $this->container->get(EntityRepositoryInterface::class) ->loadEntityByUuid('entity_test', '01234567-89ab-cdef-0123-456789abcdef'); Loading Loading
core/lib/Drupal/Core/DefaultContent/Importer.php +1 −1 Original line number Diff line number Diff line Loading @@ -123,7 +123,7 @@ public function importContent(Finder $content, Existing $existing = Existing::Er } } $entity = $this->toEntity($decoded)->enforceIsNew(); $entity = $this->toEntity($decoded)->enforceIsNew()->setSyncing(TRUE); // Ensure that the entity is not owned by the anonymous user. if ($entity instanceof EntityOwnerInterface && empty($entity->getOwnerId())) { Loading
core/tests/Drupal/KernelTests/Core/DefaultContent/ImporterTest.php +20 −0 Original line number Diff line number Diff line Loading @@ -7,7 +7,9 @@ use Drupal\Core\DefaultContent\Finder; use Drupal\Core\DefaultContent\Importer; use Drupal\Core\DefaultContent\PreEntityImportEvent; use Drupal\Core\Entity\ContentEntityInterface; use Drupal\Core\Entity\EntityRepositoryInterface; use Drupal\Core\Hook\Attribute\Hook; use Drupal\KernelTests\KernelTestBase; use Drupal\Tests\user\Traits\UserCreationTrait; use PHPUnit\Framework\Attributes\CoversClass; Loading @@ -31,6 +33,15 @@ class ImporterTest extends KernelTestBase implements EventSubscriberInterface { */ protected static $modules = ['system', 'user', 'entity_test']; /** * Whether the imported content entities were syncing. * * @var bool * * @see ::onPreSave() */ private bool $wasSyncing = FALSE; /** * {@inheritdoc} */ Loading @@ -51,6 +62,14 @@ public static function getSubscribedEvents(): array { ]; } /** * Implements hook_ENTITY_TYPE_presave() for entity_test entities. */ #[Hook('entity_test_presave')] public function onPreSave(ContentEntityInterface $entity): void { $this->wasSyncing = $entity->isSyncing(); } /** * Modify entity data before it is imported. * Loading @@ -77,6 +96,7 @@ public function testChangeDataOnImport(): void { $finder = new Finder($this->getDrupalRoot() . '/core/tests/fixtures/pre_entity_import_default_content'); $this->container->get(Importer::class)->importContent($finder); self::assertTrue($this->wasSyncing); $entity = $this->container->get(EntityRepositoryInterface::class) ->loadEntityByUuid('entity_test', '01234567-89ab-cdef-0123-456789abcdef'); Loading