next_for_drupal_pantheon-1.0.x-dev/next_for_drupal_pantheon.module
next_for_drupal_pantheon.module
<?php
/**
* @file
* Hooks implementation for next_for_drupal_pantheon module.
*/
use Drupal\Core\Entity\EntityInterface;
/**
* Implements hook_entity_delete().
*/
function next_for_drupal_pantheon_entity_delete(EntityInterface $entity) {
$storage = \Drupal::entityTypeManager()->getStorage('next_for_drupal_pantheon');
if ($entity->getEntityTypeId() == 'next_site') {
$entities = $storage->loadByProperties(['next_site' => $entity->id()]);
foreach ($entities as $entity) {
$entity->delete();
}
}
if ($entity->getEntityTypeId() == 'consumer') {
$entities = $storage->loadByProperties(['consumer' => $entity->id()]);
foreach ($entities as $entity) {
$entity->delete();
}
}
// When a next_for_drupal_pantheon entity is deleted, cascade deletion to the referenced
// next_site and consumer entity.
/** @var \Drupal\next_for_drupal_pantheon\Entity\PantheonNextInterface $entity */
if ($entity->getEntityTypeId() === 'next_for_drupal_pantheon') {
if ($next_site = $entity->getNextSite()) {
$next_site->delete();
}
if ($consumer = $entity->getConsumer()) {
$consumer->delete();
}
}
}
