diff --git a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php index 30dd4a7..6a50c71 100644 --- a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php +++ b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php @@ -1329,7 +1329,7 @@ protected function saveToDedicatedTables(ContentEntityInterface $entity, $update // Check if the given entity is a new revision or not. In case of a new // revision creation, we cannot skip any field else the new revision // would be empty. - if ($original && $vid == $original->getRevisionId() && !$this->hasFieldValueChanged($field_definition, $entity, $original)) { + if ($original && !$entity->isNewRevision() && !$this->hasFieldValueChanged($field_definition, $entity, $original)) { continue; } diff --git a/core/modules/system/src/Tests/Entity/EntityTranslationTest.php b/core/modules/system/src/Tests/Entity/EntityTranslationTest.php index a3cf0a4..c8549e6 100644 --- a/core/modules/system/src/Tests/Entity/EntityTranslationTest.php +++ b/core/modules/system/src/Tests/Entity/EntityTranslationTest.php @@ -460,6 +460,19 @@ protected function doTestEntityTranslationAPI($entity_type) { $hooks = $this->getHooksInfo(); $this->assertFalse($hooks, 'No hooks are run when adding and removing a translation without storing it.'); + // Check that hooks are fired only when actually storing data. + $entity = $this->reloadEntity($entity); + $entity->addTranslation($langcode2); + $entity->save(); + $entity = $this->reloadEntity($entity); + $this->assertTrue($entity->hasTranslation($langcode2), 'Entity has translation after adding one and saving.'); + $entity->removeTranslation($langcode2); + $entity->save(); + $entity = $this->reloadEntity($entity); + $this->assertFalse($entity->hasTranslation($langcode2), 'Entity does not have translation after removing it and saving.'); + // Reset hook firing information. + $this->getHooksInfo(); + // Verify that entity serialization does not cause stale references to be // left around. $entity = $this->reloadEntity($entity);