forked from fago/rules
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrules.module
100 lines (91 loc) · 3.48 KB
/
rules.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
/**
* @file
* Hook implementations for the Rules module.
*/
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\rules\Event\EntityEvent;
use Drupal\rules\Event\UserLoginEvent;
use Drupal\rules\Event\UserLogoutEvent;
/**
* Implements hook_user_login().
*/
function rules_user_login($account) {
// Set the account twice on the event: as the main subject but also in the
// list of arguments.
$event = new UserLoginEvent($account, ['account' => $account]);
$event_dispatcher = \Drupal::service('event_dispatcher');
$event_dispatcher->dispatch(UserLoginEvent::EVENT_NAME, $event);
}
/**
* Implements hook_user_logout().
*/
function rules_user_logout($account) {
// Set the account twice on the event: as the main subject but also in the
// list of arguments.
$event = new UserLogoutEvent($account, ['account' => $account]);
$event_dispatcher = \Drupal::service('event_dispatcher');
$event_dispatcher->dispatch(UserLogoutEvent::EVENT_NAME, $event);
}
/**
* Implements hook_entity_view().
*/
function rules_entity_view(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode, $langcode) {
// Only handle content entities and ignore config entities.
if ($entity instanceof ContentEntityInterface) {
$entity_type_id = $entity->getEntityTypeId();
$event = new EntityEvent($entity, [$entity_type_id => $entity]);
$event_dispatcher = \Drupal::service('event_dispatcher');
$event_dispatcher->dispatch("rules_entity_view:$entity_type_id", $event);
}
}
/**
* Implements hook_entity_presave().
*/
function rules_entity_presave(EntityInterface $entity) {
// Only handle content entities and ignore config entities.
if ($entity instanceof ContentEntityInterface) {
$entity_type_id = $entity->getEntityTypeId();
$event = new EntityEvent($entity, [$entity_type_id => $entity]);
$event_dispatcher = \Drupal::service('event_dispatcher');
$event_dispatcher->dispatch("rules_entity_presave:$entity_type_id", $event);
}
}
/**
* Implements hook_entity_delete().
*/
function rules_entity_delete(EntityInterface $entity) {
// Only handle content entities and ignore config entities.
if ($entity instanceof ContentEntityInterface) {
$entity_type_id = $entity->getEntityTypeId();
$event = new EntityEvent($entity, [$entity_type_id => $entity]);
$event_dispatcher = \Drupal::service('event_dispatcher');
$event_dispatcher->dispatch("rules_entity_delete:$entity_type_id", $event);
}
}
/**
* Implements hook_entity_insert().
*/
function rules_entity_insert(EntityInterface $entity) {
// Only handle content entities and ignore config entities.
if ($entity instanceof ContentEntityInterface) {
$entity_type_id = $entity->getEntityTypeId();
$event = new EntityEvent($entity, [$entity_type_id => $entity]);
$event_dispatcher = \Drupal::service('event_dispatcher');
$event_dispatcher->dispatch("rules_entity_insert:$entity_type_id", $event);
}
}
/**
* Implements hook_entity_update().
*/
function rules_entity_update(EntityInterface $entity) {
// Only handle content entities and ignore config entities.
if ($entity instanceof ContentEntityInterface) {
$entity_type_id = $entity->getEntityTypeId();
$event = new EntityEvent($entity, [$entity_type_id => $entity]);
$event_dispatcher = \Drupal::service('event_dispatcher');
$event_dispatcher->dispatch("rules_entity_update:$entity_type_id", $event);
}
}