Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / chi-teck / drupal-code-generator / templates / d8 / hook / ENTITY_TYPE_predelete.twig
1 /**
2  * Implements hook_ENTITY_TYPE_predelete().
3  */
4 function {{ machine_name }}_ENTITY_TYPE_predelete(Drupal\Core\Entity\EntityInterface $entity) {
5   // Count references to this entity in a custom table before they are removed
6   // upon entity deletion.
7   $id = $entity->id();
8   $type = $entity->getEntityTypeId();
9   $count = db_select('example_entity_data')
10     ->condition('type', $type)
11     ->condition('id', $id)
12     ->countQuery()
13     ->execute()
14     ->fetchField();
15
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])
20     ->execute();
21 }