function hook_entity_delete

Same name 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

6 functions implement hook_entity_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_delete in core/modules/content_moderation/content_moderation.module
Implements hook_entity_delete().
editor_entity_delete in core/modules/editor/editor.module
Implements hook_entity_delete().
entity_crud_hook_test_entity_delete in core/modules/system/tests/modules/entity_crud_hook_test/entity_crud_hook_test.module
Implements hook_entity_delete().
jsonapi_entity_delete in core/modules/jsonapi/jsonapi.module
Implements hook_entity_delete().
layout_builder_entity_delete in core/modules/layout_builder/layout_builder.module
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.