1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Rules integration for the taxonomy_term module.
|
6
|
*
|
7
|
* @addtogroup rules
|
8
|
*
|
9
|
* @{
|
10
|
*/
|
11
|
|
12
|
/**
|
13
|
* Implements hook_rules_event_info().
|
14
|
*/
|
15
|
function rules_taxonomy_event_info() {
|
16
|
$defaults_term = array(
|
17
|
'group' => t('Taxonomy'),
|
18
|
'access callback' => 'rules_taxonomy_term_integration_access',
|
19
|
'module' => 'taxonomy',
|
20
|
'class' => 'RulesTaxonomyEventHandler',
|
21
|
);
|
22
|
$defaults_vocab = array(
|
23
|
'group' => t('Taxonomy'),
|
24
|
'access callback' => 'rules_taxonomy_vocabulary_integration_access',
|
25
|
'module' => 'taxonomy',
|
26
|
);
|
27
|
return array(
|
28
|
'taxonomy_term_insert' => $defaults_term + array(
|
29
|
'label' => t('After saving a new term'),
|
30
|
'variables' => array(
|
31
|
'term' => array('type' => 'taxonomy_term', 'label' => t('created term')),
|
32
|
),
|
33
|
),
|
34
|
'taxonomy_term_update' => $defaults_term + array(
|
35
|
'label' => t('After updating an existing term'),
|
36
|
'variables' => array(
|
37
|
'term' => array('type' => 'taxonomy_term', 'label' => t('updated term')),
|
38
|
'term_unchanged' => array(
|
39
|
'type' => 'taxonomy_term',
|
40
|
'label' => t('unchanged term'),
|
41
|
'handler' => 'rules_events_entity_unchanged',
|
42
|
),
|
43
|
),
|
44
|
),
|
45
|
'taxonomy_term_presave' => $defaults_term + array(
|
46
|
'label' => t('Before saving a taxonomy term'),
|
47
|
'variables' => array(
|
48
|
'term' => array(
|
49
|
'type' => 'taxonomy_term',
|
50
|
'label' => t('saved term'),
|
51
|
'skip save' => TRUE,
|
52
|
),
|
53
|
'term_unchanged' => array(
|
54
|
'type' => 'taxonomy_term',
|
55
|
'label' => t('unchanged term'),
|
56
|
'handler' => 'rules_events_entity_unchanged',
|
57
|
),
|
58
|
),
|
59
|
),
|
60
|
'taxonomy_term_delete' => $defaults_term + array(
|
61
|
'label' => t('After deleting a term'),
|
62
|
'variables' => array(
|
63
|
'term' => array('type' => 'taxonomy_term', 'label' => t('deleted term')),
|
64
|
),
|
65
|
),
|
66
|
'taxonomy_vocabulary_insert' => $defaults_vocab + array(
|
67
|
'label' => t('After saving a new vocabulary'),
|
68
|
'variables' => array(
|
69
|
'vocabulary' => array('type' => 'taxonomy_vocabulary', 'label' => t('created vocabulary')),
|
70
|
),
|
71
|
),
|
72
|
'taxonomy_vocabulary_update' => $defaults_vocab + array(
|
73
|
'label' => t('After updating an existing vocabulary'),
|
74
|
'variables' => array(
|
75
|
'vocabulary' => array(
|
76
|
'type' => 'taxonomy_vocabulary',
|
77
|
'label' => t('updated vocabulary'),
|
78
|
),
|
79
|
'vocabulary_unchanged' => array(
|
80
|
'type' => 'taxonomy_vocabulary',
|
81
|
'label' => t('unchanged vocabulary'),
|
82
|
'handler' => 'rules_events_entity_unchanged',
|
83
|
),
|
84
|
),
|
85
|
),
|
86
|
'taxonomy_vocabulary_presave' => $defaults_vocab + array(
|
87
|
'label' => t('Before saving a vocabulary'),
|
88
|
'variables' => array(
|
89
|
'vocabulary' => array(
|
90
|
'type' => 'taxonomy_vocabulary',
|
91
|
'label' => t('saved vocabulary'),
|
92
|
'skip save' => TRUE,
|
93
|
),
|
94
|
'vocabulary_unchanged' => array(
|
95
|
'type' => 'taxonomy_vocabulary',
|
96
|
'label' => t('unchanged vocabulary'),
|
97
|
'handler' => 'rules_events_entity_unchanged',
|
98
|
),
|
99
|
),
|
100
|
),
|
101
|
'taxonomy_vocabulary_delete' => $defaults_vocab + array(
|
102
|
'label' => t('After deleting a vocabulary'),
|
103
|
'variables' => array(
|
104
|
'vocabulary' => array(
|
105
|
'type' => 'taxonomy_vocabulary',
|
106
|
'label' => t('deleted vocabulary'),
|
107
|
),
|
108
|
),
|
109
|
),
|
110
|
);
|
111
|
}
|
112
|
|
113
|
/**
|
114
|
* Taxonomy term integration access callback.
|
115
|
*/
|
116
|
function rules_taxonomy_term_integration_access($type, $name) {
|
117
|
if ($type == 'event' || $type == 'condition') {
|
118
|
return entity_access('view', 'taxonomy_term');
|
119
|
}
|
120
|
}
|
121
|
|
122
|
/**
|
123
|
* Taxonomy vocabulary integration access callback.
|
124
|
*/
|
125
|
function rules_taxonomy_vocabulary_integration_access($type, $name) {
|
126
|
if ($type == 'event' || $type == 'condition') {
|
127
|
return entity_access('view', 'taxonomy_vocabulary');
|
128
|
}
|
129
|
}
|
130
|
|
131
|
/**
|
132
|
* Event handler support taxonomy bundle event settings.
|
133
|
*/
|
134
|
class RulesTaxonomyEventHandler extends RulesEventHandlerEntityBundle {
|
135
|
|
136
|
/**
|
137
|
* Returns the label to use for the bundle property.
|
138
|
*
|
139
|
* @return string
|
140
|
* The label to use for the bundle property.
|
141
|
*/
|
142
|
protected function getBundlePropertyLabel() {
|
143
|
return t('vocabulary');
|
144
|
}
|
145
|
|
146
|
}
|
147
|
|
148
|
/**
|
149
|
* @}
|
150
|
*/
|