Unverified Commit 24c74c20 authored by Alex Pott's avatar Alex Pott
Browse files

fix: #3460896 Core DefaultContent Importer does not set isSyncing

By: @geek-merlin
By: @phenaproxima
(cherry picked from commit e7d3637a)
parent 99867562
Loading
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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())) {
+20 −0
Original line number Diff line number Diff line
@@ -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;
@@ -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}
   */
@@ -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.
   *
@@ -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');