function hook_ENTITY_TYPE_delete

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Entity/entity.api.php \hook_ENTITY_TYPE_delete()
  2. 8.9.x core/lib/Drupal/Core/Entity/entity.api.php \hook_ENTITY_TYPE_delete()
  3. 10 core/lib/Drupal/Core/Entity/entity.api.php \hook_ENTITY_TYPE_delete()

Respond to entity deletion of a particular type.

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_delete()

Related topics

18 functions implement hook_ENTITY_TYPE_delete()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

content_moderation_entity_bundle_delete in core/modules/content_moderation/content_moderation.module
Implements hook_entity_bundle_delete().
content_moderation_entity_revision_delete in core/modules/content_moderation/content_moderation.module
Implements hook_entity_revision_delete().
content_moderation_entity_translation_delete in core/modules/content_moderation/content_moderation.module
Implements hook_entity_translation_delete().
content_translation_test_entity_translation_delete in core/modules/content_translation/tests/modules/content_translation_test/content_translation_test.module
Implements hook_entity_translation_delete().
editor_entity_revision_delete in core/modules/editor/editor.module
Implements hook_entity_revision_delete().

... See full list

File

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

Code

function hook_ENTITY_TYPE_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.