function hook_entity_delete

Same name and namespace in other branches
  1. 7.x modules/system/system.api.php \hook_entity_delete()
  2. 9 core/lib/Drupal/Core/Entity/entity.api.php \hook_entity_delete()
  3. 8.9.x core/lib/Drupal/Core/Entity/entity.api.php \hook_entity_delete()
  4. 11.x core/lib/Drupal/Core/Entity/entity.api.php \hook_entity_delete()

Respond to entity deletion.

This hook runs once the entity has been deleted from the storage.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity object for the entity that has been deleted.

See also

hook_ENTITY_TYPE_delete()

Related topics

12 functions implement hook_entity_delete()

Note: the procedural functions in this list are found by pattern matching, so the list may include some functions that are not actually implementations of this hook.

ContentModerationHooks::entityDelete in core/modules/content_moderation/src/Hook/ContentModerationHooks.php
Implements hook_entity_delete().
content_moderation_entity_delete in core/modules/content_moderation/content_moderation.module
Implements hook_entity_delete().
EditorHooks::entityDelete in core/modules/editor/src/Hook/EditorHooks.php
Implements hook_entity_delete().
editor_entity_delete in core/modules/editor/editor.module
Implements hook_entity_delete().
EntityCrudHookTestHooks::entityDelete in core/modules/system/tests/modules/entity_crud_hook_test/src/Hook/EntityCrudHookTestHooks.php
Implements hook_entity_delete().

... See full list

1 invocation of hook_entity_delete()
EntityStorageBase::delete in core/lib/Drupal/Core/Entity/EntityStorageBase.php
Deletes permanently saved entities.

File

core/lib/Drupal/Core/Entity/entity.api.php, line 1434

Code

function hook_entity_delete(\Drupal\Core\Entity\EntityInterface $entity) {
  // Delete the entity's entry from a fictional table of all entities.
  \Drupal::database()->delete('example_entity')
    ->condition('type', $entity->getEntityTypeId())
    ->condition('id', $entity->id())
    ->execute();
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.