2 * Implements hook_entity_predelete().
4 function {{ machine_name }}_entity_predelete(Drupal\Core\Entity\EntityInterface $entity) {
5 // Count references to this entity in a custom table before they are removed
6 // upon entity deletion.
8 $type = $entity->getEntityTypeId();
9 $count = db_select('example_entity_data')
10 ->condition('type', $type)
11 ->condition('id', $id)
16 // Log the count in a table that records this statistic for deleted entities.
17 db_merge('example_deleted_entity_statistics')
18 ->key(['type' => $type, 'id' => $id])
19 ->fields(['count' => $count])