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. 10 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

1 function implements 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.

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().
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 1436

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.