1 entity.api.php hook_entity_predelete($entity, $type)

Act before entity deletion.

This hook runs after the entity type-specific predelete hook.


$entity: The entity object for the entity that is about to be deleted.

$type: The type of entity being deleted (e.g. node, user, comment).

Related topics


core/modules/entity/entity.api.php, line 291
Hooks provided by the Entity module.


function hook_entity_predelete($entity, $type) {
  // Count references to this entity in a custom table before they are removed
  // upon entity deletion.
  list($id) = entity_extract_ids($type, $entity);
  $count = db_select('example_entity_data')
    ->condition('type', $type)
    ->condition('id', $id)

  // Log the count in a table that records this statistic for deleted entities.
  $ref_count_record = (object) array(
    'count' => $count,
    'type' => $type,
    'id' => $id,
  backdrop_write_record('example_deleted_entity_statistics', $ref_count_record);