diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/ChangedItem.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/ChangedItem.php index 7116809acdb4eb985178dfa94b227066927570a7..3294ed40c97e5cc7d10d016bb3d35d4e7b75b55e 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/ChangedItem.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/ChangedItem.php @@ -5,6 +5,7 @@ use Drupal\Core\Field\Attribute\FieldType; use Drupal\Core\Field\ChangedFieldItemList; use Drupal\Core\StringTranslation\TranslatableMarkup; +use Drupal\Core\Entity\SynchronizableInterface; /** * Defines the 'changed' entity field type. @@ -44,13 +45,15 @@ public function preSave() { // \Drupal\content_translation\ContentTranslationMetadataWrapperInterface::setChangedTime(). /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */ $entity = $this->getEntity(); - /** @var \Drupal\Core\Entity\ContentEntityInterface $original */ - $original = $entity->original; - $langcode = $entity->language()->getId(); - if (!$entity->isNew() && $original && $original->hasTranslation($langcode)) { - $original_value = $original->getTranslation($langcode)->get($this->getFieldDefinition()->getName())->value; - if ($this->value == $original_value && $entity->hasTranslationChanges()) { - $this->value = \Drupal::time()->getRequestTime(); + if (!$entity instanceof SynchronizableInterface || !$entity->isSyncing()) { + /** @var \Drupal\Core\Entity\ContentEntityInterface $original */ + $original = $entity->original; + $langcode = $entity->language()->getId(); + if (!$entity->isNew() && $original && $original->hasTranslation($langcode)) { + $original_value = $original->getTranslation($langcode)->get($this->getFieldDefinition()->getName())->value; + if ($this->value == $original_value && $entity->hasTranslationChanges()) { + $this->value = \Drupal::time()->getRequestTime(); + } } } } diff --git a/core/tests/Drupal/KernelTests/Core/Entity/ContentEntityChangedTest.php b/core/tests/Drupal/KernelTests/Core/Entity/ContentEntityChangedTest.php index 32a49bf0a0487a90b022fa0652e6e34ba3d7d5c0..7824248bf55b9543035a7c6412db62e6c20ff4a3 100644 --- a/core/tests/Drupal/KernelTests/Core/Entity/ContentEntityChangedTest.php +++ b/core/tests/Drupal/KernelTests/Core/Entity/ContentEntityChangedTest.php @@ -472,6 +472,29 @@ public function testRevisionChanged(): void { } + /** + * Tests the changed functionality when an entity is syncing. + */ + public function testChangedSyncing(): void { + $entity = EntityTestMulChanged::create(); + $entity->save(); + $changed_time_1 = $entity->getChangedTime(); + + // Without the syncing flag the changed time will increment when content is + // changed. + $entity->setName($this->randomString()); + $entity->save(); + $changed_time_2 = $entity->getChangedTime(); + $this->assertTrue($changed_time_2 > $changed_time_1); + + // With the syncing flag, the changed time will not change. + $entity->setName($this->randomString()); + $entity->setSyncing(TRUE); + $entity->save(); + $changed_time_3 = $entity->getChangedTime(); + $this->assertEquals($changed_time_2, $changed_time_3); + } + /** * Retrieves the revision translation affected flag value. *