function hook_entity_delete

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Entity/entity.api.php \hook_entity_delete()
  2. 8.9.x core/lib/Drupal/Core/Entity/entity.api.php \hook_entity_delete()
  3. 10 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()

Act on entities when deleted.

Parameters

$entity: The entity object.

$type: The type of entity being deleted (i.e. node, user, comment).

Related topics

7 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().
EditorHooks::entityDelete in core/modules/editor/src/Hook/EditorHooks.php
Implements hook_entity_delete().
EntityCrudHookTestHooks::entityDelete in core/modules/system/tests/modules/entity_crud_hook_test/src/Hook/EntityCrudHookTestHooks.php
Implements hook_entity_delete().
EntityOperations::entityDelete in core/modules/workspaces/src/Hook/EntityOperations.php
Implements hook_entity_delete().
entity_crud_hook_test_entity_delete in modules/simpletest/tests/entity_crud_hook_test.module
Implements hook_entity_delete().

... See full list

6 invocations of hook_entity_delete()
comment_delete_multiple in modules/comment/comment.module
Delete comments and all their replies.
file_delete in includes/file.inc
Deletes a file and its database record.
node_delete_multiple in modules/node/node.module
Deletes multiple nodes.
taxonomy_term_delete in modules/taxonomy/taxonomy.module
Delete a term.
taxonomy_vocabulary_delete in modules/taxonomy/taxonomy.module
Deletes a vocabulary.

... See full list

File

modules/system/system.api.php, line 371

Code

function hook_entity_delete($entity, $type) {
    // Delete the entity's entry from a fictional table of all entities.
    $info = entity_get_info($type);
    list($id) = entity_extract_ids($type, $entity);
    db_delete('example_entity')->condition('type', $type)
        ->condition('id', $id)
        ->execute();
}

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