function hook_ENTITY_TYPE_delete

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

File

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

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.