-
Notifications
You must be signed in to change notification settings - Fork 1
/
next_for_drupal_pantheon.module
39 lines (35 loc) · 1.14 KB
/
next_for_drupal_pantheon.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?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();
}
}
}