You are here

function hook_entity_delete in Drupal 10

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

5 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().
2 invocations of hook_entity_delete()
ConfigEntityStorageTest::testDelete in core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php
@covers ::delete @covers ::doDelete
EntityStorageBase::delete in core/lib/Drupal/Core/Entity/EntityStorageBase.php
Deletes permanently saved entities.

File

core/lib/Drupal/Core/Entity/entity.api.php, line 1407
Hooks and documentation related to entities.

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();
}