diff --git a/core/lib/Drupal/Core/Entity/EntityStorageBase.php b/core/lib/Drupal/Core/Entity/EntityStorageBase.php index bd06ca9c95..2ceb19c2b1 100644 --- a/core/lib/Drupal/Core/Entity/EntityStorageBase.php +++ b/core/lib/Drupal/Core/Entity/EntityStorageBase.php @@ -537,7 +537,10 @@ protected function doPostSave(EntityInterface $entity, $update) { * {@inheritdoc} */ public function restore(EntityInterface $entity) { - // The restore process does not invoke any pre-save or post-save operations. + // Allow code to run before saving. + $entity->preSave($this); + + // The restore process does not invoke any post-save operations. $this->doSave($entity->id(), $entity); } diff --git a/core/lib/Drupal/Core/Entity/EntityStorageInterface.php b/core/lib/Drupal/Core/Entity/EntityStorageInterface.php index 9ceb1b09ac..0c776ab3b4 100644 --- a/core/lib/Drupal/Core/Entity/EntityStorageInterface.php +++ b/core/lib/Drupal/Core/Entity/EntityStorageInterface.php @@ -159,7 +159,7 @@ public function save(EntityInterface $entity); * * Note that the entity is assumed to be in a valid state for the storage, so * the restore process does not invoke any hooks, nor does it perform any - * pre-save or post-save operations. + * post-save operations. * * @param \Drupal\Core\Entity\EntityInterface $entity * The entity to restore. diff --git a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php index accfb3220c..d7c03ba7a5 100644 --- a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php +++ b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php @@ -791,6 +791,10 @@ public function save(EntityInterface $entity) { * {@inheritdoc} */ public function restore(EntityInterface $entity) { + // Allow code to run before saving. + $entity->preSave($this); + $this->invokeFieldMethod('preSave', $entity); + $transaction = $this->database->startTransaction(); try { /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */ diff --git a/core/lib/Drupal/Core/Entity/Sql/SqlFieldableEntityTypeListenerTrait.php b/core/lib/Drupal/Core/Entity/Sql/SqlFieldableEntityTypeListenerTrait.php index 655277b776..8770ca08e3 100644 --- a/core/lib/Drupal/Core/Entity/Sql/SqlFieldableEntityTypeListenerTrait.php +++ b/core/lib/Drupal/Core/Entity/Sql/SqlFieldableEntityTypeListenerTrait.php @@ -202,6 +202,7 @@ protected function copyData(EntityTypeInterface $entity_type, EntityTypeInterfac } // Finally, save the entity in the temporary storage. + $entity->enforceIsNew(TRUE); $temporary_storage->restore($entity); } catch (\Exception $e) {