Act before entity deletion.
This hook runs after the entity type-specific predelete hook.
Drupal\Core\Entity\EntityInterface $entity: The entity object for the entity that is about to be deleted.
Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.
function hook_entity_predelete(Drupal\Core\Entity\EntityInterface $entity) {
// Count references to this entity in a custom table before they are removed
// upon entity deletion.
$id = $entity
->id();
$type = $entity
->entityType();
$count = db_select('example_entity_data')
->condition('type', $type)
->condition('id', $id)
->countQuery()
->execute()
->fetchField();
// Log the count in a table that records this statistic for deleted entities.
$ref_count_record = (object) array(
'count' => $count,
'type' => $type,
'id' => $id,
);
drupal_write_record('example_deleted_entity_statistics', $ref_count_record);
}