forked from discoverygarden/dgi_actions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dgi_actions.module
51 lines (45 loc) · 1.35 KB
/
dgi_actions.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
40
41
42
43
44
45
46
47
48
49
50
51
<?php
/**
* @file
* Holds entity CRUD hooks for DGI Actions.
*/
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\dgi_actions\Plugin\ContextReaction\EntityDeleteReaction;
use Drupal\dgi_actions\Plugin\ContextReaction\EntityMintReaction;
/**
* Implements hook_entity_insert().
*/
function dgi_actions_entity_insert(EntityInterface $entity) {
if (!$entity instanceof ContentEntityInterface) {
return;
}
$utils = \Drupal::service('dgi_actions.dgiutils');
$original_entity = clone $entity;
$utils->executeEntityReactions(EntityMintReaction::class, $entity);
if (\Drupal::service('islandora.utils')->haveFieldsChanged($entity, $original_entity)) {
$entity->save();
}
}
/**
* Implements hook_entity_presave().
*/
function dgi_actions_entity_presave(EntityInterface $entity) {
if (!$entity instanceof ContentEntityInterface) {
return;
}
if (!$entity->isNew()) {
$utils = \Drupal::service('dgi_actions.dgiutils');
$utils->executeEntityReactions(EntityMintReaction::class, $entity);
}
}
/**
* Implements hook_entity_delete().
*/
function dgi_actions_entity_delete(EntityInterface $entity) {
if (!$entity instanceof ContentEntityInterface) {
return;
}
$utils = \Drupal::service('dgi_actions.dgiutils');
$utils->executeEntityReactions(EntityDeleteReaction::class, $entity);
}