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