X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fchi-teck%2Fdrupal-code-generator%2Ftemplates%2Fd8%2Fhook%2Fentity_predelete.twig;fp=vendor%2Fchi-teck%2Fdrupal-code-generator%2Ftemplates%2Fd8%2Fhook%2Fentity_predelete.twig;h=5aaf9a529e77346262bdbb0da04f2a4b8060b3c6;hp=0000000000000000000000000000000000000000;hb=af6d1fb995500ae68849458ee10d66abbdcfb252;hpb=680c79a86e3ed402f263faeac92e89fb6d9edcc0 diff --git a/vendor/chi-teck/drupal-code-generator/templates/d8/hook/entity_predelete.twig b/vendor/chi-teck/drupal-code-generator/templates/d8/hook/entity_predelete.twig new file mode 100644 index 000000000..5aaf9a529 --- /dev/null +++ b/vendor/chi-teck/drupal-code-generator/templates/d8/hook/entity_predelete.twig @@ -0,0 +1,21 @@ +/** + * Implements hook_entity_predelete(). + */ +function {{ machine_name }}_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->getEntityTypeId(); + $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. + db_merge('example_deleted_entity_statistics') + ->key(['type' => $type, 'id' => $id]) + ->fields(['count' => $count]) + ->execute(); +}