diff --git a/core/lib/Drupal/Core/Entity/FieldableDatabaseStorageController.php b/core/lib/Drupal/Core/Entity/FieldableDatabaseStorageController.php index d82c8cf56026..67923b440dd3 100644 --- a/core/lib/Drupal/Core/Entity/FieldableDatabaseStorageController.php +++ b/core/lib/Drupal/Core/Entity/FieldableDatabaseStorageController.php @@ -611,13 +611,16 @@ class FieldableDatabaseStorageController extends FieldableEntityStorageControlle ->execute(); } + foreach ($entities as $entity) { + $this->invokeFieldMethod('delete', $entity); + $this->deleteFieldItems($entity); + } + // Reset the cache as soon as the changes have been applied. $this->resetCache($ids); $entity_class::postDelete($this, $entities); foreach ($entities as $entity) { - $this->invokeFieldMethod('delete', $entity); - $this->deleteFieldItems($entity); $this->invokeHook('delete', $entity); } // Ignore slave server temporarily. @@ -669,11 +672,11 @@ class FieldableDatabaseStorageController extends FieldableEntityStorageControlle if ($this->revisionDataTable) { $this->savePropertyData($entity, 'revision_data_table'); } - $this->resetCache(array($entity->id())); $entity->setNewRevision(FALSE); - $entity->postSave($this, TRUE); $this->invokeFieldMethod('update', $entity); $this->saveFieldItems($entity, TRUE); + $this->resetCache(array($entity->id())); + $entity->postSave($this, TRUE); $this->invokeHook('update', $entity); if ($this->dataTable) { $this->invokeTranslationHooks($entity); @@ -696,13 +699,13 @@ class FieldableDatabaseStorageController extends FieldableEntityStorageControlle $this->savePropertyData($entity, 'revision_data_table'); } - // Reset general caches, but keep caches specific to certain entities. - $this->resetCache(array()); $entity->enforceIsNew(FALSE); - $entity->postSave($this, FALSE); $this->invokeFieldMethod('insert', $entity); $this->saveFieldItems($entity, FALSE); + // Reset general caches, but keep caches specific to certain entities. + $this->resetCache(array()); + $entity->postSave($this, FALSE); $this->invokeHook('insert', $entity); } diff --git a/core/modules/system/entity.api.php b/core/modules/system/entity.api.php index c44b4fda0806..3cf953526ed1 100644 --- a/core/modules/system/entity.api.php +++ b/core/modules/system/entity.api.php @@ -287,7 +287,10 @@ function hook_entity_presave(Drupal\Core\Entity\EntityInterface $entity) { } /** - * Act on entities when inserted. + * Respond to creation of a new entity. + * + * This hook runs once the entity has been stored. Note that hook + * implementations may not alter the stored entity data. * * @param \Drupal\Core\Entity\EntityInterface $entity * The entity object. @@ -305,7 +308,10 @@ function hook_entity_insert(Drupal\Core\Entity\EntityInterface $entity) { } /** - * Act on entities when updated. + * Respond to updates to an entity. + * + * This hook runs once the entity storage has been updated. Note that hook + * implementations may not alter the stored entity data. * * @param \Drupal\Core\Entity\EntityInterface $entity * The entity object. @@ -322,7 +328,10 @@ function hook_entity_update(Drupal\Core\Entity\EntityInterface $entity) { } /** - * Acts after storing a new entity translation. + * Respond to creation of a new entity translation. + * + * This hook runs once the entity translation has been stored. Note that hook + * implementations may not alter the stored entity translation data. * * @param \Drupal\Core\Entity\EntityInterface $translation * The entity object of the translation just stored. @@ -336,7 +345,9 @@ function hook_entity_translation_insert(\Drupal\Core\Entity\EntityInterface $tra } /** - * Acts after deleting an entity translation from the storage. + * Respond to entity translation deletion. + * + * This hook runs once the entity translation has been deleted from storage. * * @param \Drupal\Core\Entity\EntityInterface $entity * The original entity object. @@ -353,8 +364,6 @@ function hook_entity_translation_delete(\Drupal\Core\Entity\EntityInterface $tra /** * Act before entity deletion. * - * This hook runs after the entity type-specific predelete hook. - * * @param \Drupal\Core\Entity\EntityInterface $entity * The entity object for the entity that is about to be deleted. */ @@ -382,7 +391,7 @@ function hook_entity_predelete(Drupal\Core\Entity\EntityInterface $entity) { /** * Respond to entity deletion. * - * This hook runs after the entity type-specific delete hook. + * This hook runs once the entity has been deleted from the storage. * * @param \Drupal\Core\Entity\EntityInterface $entity * The entity object for the entity that has been deleted. @@ -398,7 +407,7 @@ function hook_entity_delete(Drupal\Core\Entity\EntityInterface $entity) { /** * Respond to entity revision deletion. * - * This hook runs after the entity type-specific revision delete hook. + * This hook runs once the entity revision has been deleted from the storage. * * @param \Drupal\Core\Entity\EntityInterface $entity * The entity object for the entity revision that has been deleted.