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