1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file Invokes events on behalf core modules. Usually this should be
|
5
|
* directly in the module providing rules integration instead.
|
6
|
*
|
7
|
* @addtogroup rules
|
8
|
* @{
|
9
|
*/
|
10
|
|
11
|
|
12
|
/**
|
13
|
* Gets an unchanged entity that doesn't contain any recent changes. This
|
14
|
* handler assumes the name of the variable for the changed entity is the same
|
15
|
* as for the unchanged entity but without the trailing "_unchanged"; e.g., for
|
16
|
* the "node_unchanged" variable the handler assumes there is a "node" variable.
|
17
|
*/
|
18
|
function rules_events_entity_unchanged($arguments, $name, $info) {
|
19
|
// Cut of the trailing _unchanged.
|
20
|
$var_name = substr($name, 0, -10);
|
21
|
$entity = $arguments[$var_name];
|
22
|
if (isset($entity->original)) {
|
23
|
return $entity->original;
|
24
|
}
|
25
|
}
|
26
|
|
27
|
/**
|
28
|
* Generic entity events, used for core-entities for which we provide Rules
|
29
|
* integration only.
|
30
|
* We are implementing the generic-entity hooks instead of the entity-type
|
31
|
* specific hooks to ensure we come last. See http://drupal.org/node/1211946
|
32
|
* for details.
|
33
|
*/
|
34
|
|
35
|
/**
|
36
|
* Implements hook_entity_view().
|
37
|
*/
|
38
|
function rules_entity_view($entity, $type, $view_mode, $langcode) {
|
39
|
switch ($type) {
|
40
|
case 'comment':
|
41
|
rules_invoke_event('comment_view--' . $entity->node_type, $entity, $view_mode);
|
42
|
rules_invoke_event('comment_view', $entity, $view_mode);
|
43
|
break;
|
44
|
case 'node':
|
45
|
rules_invoke_event('node_view--' . $entity->type, $entity, $view_mode);
|
46
|
rules_invoke_event('node_view', $entity, $view_mode);
|
47
|
break;
|
48
|
case 'user':
|
49
|
rules_invoke_event('user_view', $entity, $view_mode);
|
50
|
break;
|
51
|
}
|
52
|
}
|
53
|
|
54
|
/**
|
55
|
* Implements hook_entity_presave().
|
56
|
*/
|
57
|
function rules_entity_presave($entity, $type) {
|
58
|
switch ($type) {
|
59
|
case 'comment':
|
60
|
rules_invoke_event('comment_presave--' . $entity->node_type, $entity);
|
61
|
rules_invoke_event('comment_presave', $entity);
|
62
|
break;
|
63
|
case 'node':
|
64
|
rules_invoke_event('node_presave--' . $entity->type, $entity);
|
65
|
rules_invoke_event('node_presave', $entity);
|
66
|
break;
|
67
|
case 'taxonomy_term':
|
68
|
rules_invoke_event('taxonomy_term_presave--' . $entity->vocabulary_machine_name, $entity);
|
69
|
rules_invoke_event('taxonomy_term_presave', $entity);
|
70
|
break;
|
71
|
case 'taxonomy_vocabulary':
|
72
|
case 'user':
|
73
|
rules_invoke_event($type . '_presave', $entity);
|
74
|
break;
|
75
|
}
|
76
|
}
|
77
|
|
78
|
/**
|
79
|
* Implements hook_entity_update().
|
80
|
*/
|
81
|
function rules_entity_update($entity, $type) {
|
82
|
switch ($type) {
|
83
|
case 'comment':
|
84
|
rules_invoke_event('comment_update--' . $entity->node_type, $entity);
|
85
|
rules_invoke_event('comment_update', $entity);
|
86
|
break;
|
87
|
case 'node':
|
88
|
rules_invoke_event('node_update--' . $entity->type, $entity);
|
89
|
rules_invoke_event('node_update', $entity);
|
90
|
break;
|
91
|
case 'taxonomy_term':
|
92
|
rules_invoke_event('taxonomy_term_update--' . $entity->vocabulary_machine_name, $entity);
|
93
|
rules_invoke_event('taxonomy_term_update', $entity);
|
94
|
break;
|
95
|
case 'taxonomy_vocabulary':
|
96
|
case 'user':
|
97
|
rules_invoke_event($type . '_update', $entity);
|
98
|
break;
|
99
|
}
|
100
|
}
|
101
|
|
102
|
/**
|
103
|
* Implements hook_entity_insert().
|
104
|
*/
|
105
|
function rules_entity_insert($entity, $type) {
|
106
|
switch ($type) {
|
107
|
case 'comment':
|
108
|
rules_invoke_event('comment_insert--' . $entity->node_type, $entity);
|
109
|
rules_invoke_event('comment_insert', $entity);
|
110
|
break;
|
111
|
case 'node':
|
112
|
rules_invoke_event('node_insert--' . $entity->type, $entity);
|
113
|
rules_invoke_event('node_insert', $entity);
|
114
|
break;
|
115
|
case 'taxonomy_term':
|
116
|
rules_invoke_event('taxonomy_term_insert--' . $entity->vocabulary_machine_name, $entity);
|
117
|
rules_invoke_event('taxonomy_term_insert', $entity);
|
118
|
break;
|
119
|
case 'taxonomy_vocabulary':
|
120
|
case 'user':
|
121
|
rules_invoke_event($type . '_insert', $entity);
|
122
|
break;
|
123
|
}
|
124
|
}
|
125
|
|
126
|
/**
|
127
|
* Implements hook_entity_delete().
|
128
|
*/
|
129
|
function rules_entity_delete($entity, $type) {
|
130
|
switch ($type) {
|
131
|
case 'comment':
|
132
|
rules_invoke_event('comment_delete--' . $entity->node_type, $entity);
|
133
|
rules_invoke_event('comment_delete', $entity);
|
134
|
break;
|
135
|
case 'node':
|
136
|
rules_invoke_event('node_delete--' . $entity->type, $entity);
|
137
|
rules_invoke_event('node_delete', $entity);
|
138
|
break;
|
139
|
case 'taxonomy_term':
|
140
|
rules_invoke_event('taxonomy_term_delete--' . $entity->vocabulary_machine_name, $entity);
|
141
|
rules_invoke_event('taxonomy_term_delete', $entity);
|
142
|
break;
|
143
|
case 'taxonomy_vocabulary':
|
144
|
case 'user':
|
145
|
rules_invoke_event($type . '_delete', $entity);
|
146
|
break;
|
147
|
}
|
148
|
}
|
149
|
|
150
|
/**
|
151
|
* Implements hook_user_login().
|
152
|
*/
|
153
|
function rules_user_login(&$edit, $account) {
|
154
|
rules_invoke_event('user_login', $account);
|
155
|
}
|
156
|
|
157
|
/**
|
158
|
* Implements hook_user_logout().
|
159
|
*/
|
160
|
function rules_user_logout($account) {
|
161
|
rules_invoke_event('user_logout', $account);
|
162
|
}
|
163
|
|
164
|
/**
|
165
|
* System events. Note that rules_init() is the main module file is used to
|
166
|
* invoke the init event.
|
167
|
*/
|
168
|
|
169
|
/**
|
170
|
* Implements hook_cron().
|
171
|
*/
|
172
|
function rules_cron() {
|
173
|
rules_invoke_event('cron');
|
174
|
}
|
175
|
|
176
|
/**
|
177
|
* Implements hook_watchdog().
|
178
|
*/
|
179
|
function rules_watchdog($log_entry) {
|
180
|
rules_invoke_event('watchdog', $log_entry);
|
181
|
}
|
182
|
|
183
|
/**
|
184
|
* Getter callback for the log entry message property.
|
185
|
*/
|
186
|
function rules_system_log_get_message($log_entry) {
|
187
|
return t($log_entry['message'], (array)$log_entry['variables']);
|
188
|
}
|
189
|
|
190
|
/**
|
191
|
* Gets all view modes of an entity for an entity_view event.
|
192
|
*/
|
193
|
function rules_get_entity_view_modes($name, $var_info) {
|
194
|
// Read the entity type from a special key out of the variable info.
|
195
|
$entity_type = $var_info['options list entity type'];
|
196
|
$info = entity_get_info($entity_type);
|
197
|
foreach ($info['view modes'] as $mode => $mode_info) {
|
198
|
$modes[$mode] = $mode_info['label'];
|
199
|
}
|
200
|
return $modes;
|
201
|
}
|
202
|
|
203
|
/**
|
204
|
* @}
|
205
|
*/
|