1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Rules integration for the node module.
|
6
|
*
|
7
|
* @addtogroup rules
|
8
|
*
|
9
|
* @{
|
10
|
*/
|
11
|
|
12
|
/**
|
13
|
* Implements hook_rules_category_info() on behalf of the node module.
|
14
|
*/
|
15
|
function rules_node_category_info() {
|
16
|
return array(
|
17
|
'node' => array(
|
18
|
'label' => t('Node'),
|
19
|
'equals group' => t('Node'),
|
20
|
),
|
21
|
);
|
22
|
}
|
23
|
|
24
|
/**
|
25
|
* Implements hook_rules_file_info() on behalf of the node module.
|
26
|
*/
|
27
|
function rules_node_file_info() {
|
28
|
return array('modules/node.eval');
|
29
|
}
|
30
|
|
31
|
/**
|
32
|
* Implements hook_rules_event_info() on behalf of the node module.
|
33
|
*/
|
34
|
function rules_node_event_info() {
|
35
|
$items = array(
|
36
|
'node_insert' => array(
|
37
|
'label' => t('After saving new content'),
|
38
|
'category' => 'node',
|
39
|
'variables' => rules_events_node_variables(t('created content')),
|
40
|
'access callback' => 'rules_node_integration_access',
|
41
|
'class' => 'RulesNodeEventHandler',
|
42
|
),
|
43
|
'node_update' => array(
|
44
|
'label' => t('After updating existing content'),
|
45
|
'category' => 'node',
|
46
|
'variables' => rules_events_node_variables(t('updated content'), TRUE),
|
47
|
'access callback' => 'rules_node_integration_access',
|
48
|
'class' => 'RulesNodeEventHandler',
|
49
|
),
|
50
|
'node_presave' => array(
|
51
|
'label' => t('Before saving content'),
|
52
|
'category' => 'node',
|
53
|
'variables' => rules_events_node_variables(t('saved content'), TRUE),
|
54
|
'access callback' => 'rules_node_integration_access',
|
55
|
'class' => 'RulesNodeEventHandler',
|
56
|
),
|
57
|
'node_view' => array(
|
58
|
'label' => t('Content is viewed'),
|
59
|
'category' => 'node',
|
60
|
'help' => t("Note that if drupal's page cache is enabled, this event won't be generated for pages served from cache."),
|
61
|
'variables' => rules_events_node_variables(t('viewed content')) + array(
|
62
|
'view_mode' => array(
|
63
|
'type' => 'text',
|
64
|
'label' => t('view mode'),
|
65
|
'options list' => 'rules_get_entity_view_modes',
|
66
|
// Add the entity-type for the options list callback.
|
67
|
'options list entity type' => 'node',
|
68
|
),
|
69
|
),
|
70
|
'access callback' => 'rules_node_integration_access',
|
71
|
'class' => 'RulesNodeEventHandler',
|
72
|
),
|
73
|
'node_delete' => array(
|
74
|
'label' => t('After deleting content'),
|
75
|
'category' => 'node',
|
76
|
'variables' => rules_events_node_variables(t('deleted content')),
|
77
|
'access callback' => 'rules_node_integration_access',
|
78
|
'class' => 'RulesNodeEventHandler',
|
79
|
),
|
80
|
);
|
81
|
// Specify that on presave the node is saved anyway.
|
82
|
$items['node_presave']['variables']['node']['skip save'] = TRUE;
|
83
|
return $items;
|
84
|
}
|
85
|
|
86
|
/**
|
87
|
* Returns some parameter suitable for using it with a node.
|
88
|
*/
|
89
|
function rules_events_node_variables($node_label, $update = FALSE) {
|
90
|
$args = array(
|
91
|
'node' => array('type' => 'node', 'label' => $node_label),
|
92
|
);
|
93
|
if ($update) {
|
94
|
$args += array(
|
95
|
'node_unchanged' => array(
|
96
|
'type' => 'node',
|
97
|
'label' => t('unchanged content'),
|
98
|
'handler' => 'rules_events_entity_unchanged',
|
99
|
),
|
100
|
);
|
101
|
}
|
102
|
return $args;
|
103
|
}
|
104
|
|
105
|
/**
|
106
|
* Implements hook_rules_action_info() on behalf of the node module.
|
107
|
*/
|
108
|
function rules_node_action_info() {
|
109
|
$defaults = array(
|
110
|
'parameter' => array(
|
111
|
'node' => array('type' => 'node', 'label' => t('Content'), 'save' => TRUE),
|
112
|
),
|
113
|
'category' => 'node',
|
114
|
'access callback' => 'rules_node_admin_access',
|
115
|
);
|
116
|
// Add support for hand-picked core actions.
|
117
|
$core_actions = node_action_info();
|
118
|
$actions = array('node_publish_action', 'node_unpublish_action', 'node_make_sticky_action', 'node_make_unsticky_action', 'node_promote_action', 'node_unpromote_action');
|
119
|
foreach ($actions as $base) {
|
120
|
$action_name = str_replace('_action', '', $base);
|
121
|
$items[$action_name] = $defaults + array(
|
122
|
'label' => $core_actions[$base]['label'],
|
123
|
'base' => $base,
|
124
|
);
|
125
|
}
|
126
|
return $items;
|
127
|
}
|
128
|
|
129
|
/**
|
130
|
* Node integration access callback.
|
131
|
*/
|
132
|
function rules_node_integration_access($type, $name) {
|
133
|
if ($type == 'event' || $type == 'condition') {
|
134
|
return entity_access('view', 'node');
|
135
|
}
|
136
|
}
|
137
|
|
138
|
/**
|
139
|
* Node integration admin access callback.
|
140
|
*/
|
141
|
function rules_node_admin_access() {
|
142
|
return user_access('administer nodes');
|
143
|
}
|
144
|
|
145
|
/**
|
146
|
* Event handler support node bundle event settings.
|
147
|
*/
|
148
|
class RulesNodeEventHandler extends RulesEventHandlerEntityBundle {
|
149
|
|
150
|
/**
|
151
|
* Returns the label to use for the bundle property.
|
152
|
*
|
153
|
* @return string
|
154
|
*/
|
155
|
protected function getBundlePropertyLabel() {
|
156
|
return t('type');
|
157
|
}
|
158
|
|
159
|
}
|
160
|
|
161
|
/**
|
162
|
* @}
|
163
|
*/
|