1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file Rules core integration providing data types and conditions and
|
5 |
|
|
* actions to invoke configured components.
|
6 |
|
|
*
|
7 |
|
|
* @addtogroup rules
|
8 |
|
|
* @{
|
9 |
|
|
*/
|
10 |
|
|
|
11 |
|
|
/**
|
12 |
|
|
* Implements hook_rules_category_info() on behalf of the rules_core.
|
13 |
|
|
*/
|
14 |
|
|
function rules_rules_core_category_info() {
|
15 |
|
|
return array(
|
16 |
|
|
'rules_components' => array(
|
17 |
|
|
'label' => t('Components'),
|
18 |
|
|
'equals group' => t('Components'),
|
19 |
|
|
'weight' => 50,
|
20 |
|
|
),
|
21 |
|
|
);
|
22 |
|
|
}
|
23 |
|
|
|
24 |
|
|
/**
|
25 |
|
|
* Implements hook_rules_file_info() on behalf of the pseudo rules_core module.
|
26 |
|
|
*
|
27 |
|
|
* @see rules_core_modules()
|
28 |
|
|
*/
|
29 |
|
|
function rules_rules_core_file_info() {
|
30 |
|
|
return array('modules/rules_core.eval');
|
31 |
|
|
}
|
32 |
|
|
|
33 |
|
|
/**
|
34 |
|
|
* Implements hook_rules_data_info() on behalf of the pseudo rules_core module.
|
35 |
|
|
*
|
36 |
|
|
* @see rules_core_modules()
|
37 |
|
|
*/
|
38 |
|
|
function rules_rules_core_data_info() {
|
39 |
|
|
$return = array(
|
40 |
|
|
'text' => array(
|
41 |
|
|
'label' => t('text'),
|
42 |
|
|
'ui class' => 'RulesDataUIText',
|
43 |
|
|
'token type' => 'rules_text',
|
44 |
|
|
),
|
45 |
|
|
'token' => array(
|
46 |
|
|
'label' => t('text token'),
|
47 |
|
|
'parent' => 'text',
|
48 |
|
|
'ui class' => 'RulesDataUITextToken',
|
49 |
|
|
'token type' => 'rules_token',
|
50 |
|
|
),
|
51 |
|
|
// A formatted text as used by entity metadata.
|
52 |
|
|
'text_formatted' => array(
|
53 |
|
|
'label' => t('formatted text'),
|
54 |
|
|
'ui class' => 'RulesDataUITextFormatted',
|
55 |
|
|
'wrap' => TRUE,
|
56 |
|
|
'property info' => entity_property_text_formatted_info(),
|
57 |
|
|
),
|
58 |
|
|
'decimal' => array(
|
59 |
|
|
'label' => t('decimal number'),
|
60 |
|
|
'parent' => 'text',
|
61 |
|
|
'ui class' => 'RulesDataUIDecimal',
|
62 |
|
|
'token type' => 'rules_decimal',
|
63 |
|
|
),
|
64 |
|
|
'integer' => array(
|
65 |
|
|
'label' => t('integer'),
|
66 |
|
|
'class' => 'RulesIntegerWrapper',
|
67 |
|
|
'parent' => 'decimal',
|
68 |
|
|
'ui class' => 'RulesDataUIInteger',
|
69 |
|
|
'token type' => 'rules_integer',
|
70 |
|
|
),
|
71 |
|
|
'date' => array(
|
72 |
|
|
'label' => t('date'),
|
73 |
|
|
'ui class' => 'RulesDataUIDate',
|
74 |
|
|
'token type' => 'rules_date',
|
75 |
|
|
),
|
76 |
|
|
'duration' => array(
|
77 |
|
|
'label' => t('duration'),
|
78 |
|
|
'parent' => 'integer',
|
79 |
|
|
'ui class' => 'RulesDataUIDuration',
|
80 |
|
|
'token type' => 'rules_duration',
|
81 |
|
|
),
|
82 |
|
|
'boolean' => array(
|
83 |
|
|
'label' => t('truth value'),
|
84 |
|
|
'ui class' => 'RulesDataUIBoolean',
|
85 |
|
|
'token type' => 'rules_boolean',
|
86 |
|
|
),
|
87 |
|
|
'uri' => array(
|
88 |
|
|
'label' => t('URI'),
|
89 |
|
|
'parent' => 'text',
|
90 |
|
|
// Clean inserted tokens with "rawurlencode".
|
91 |
|
|
'cleaning callback' => 'rawurlencode',
|
92 |
|
|
'ui class' => 'RulesDataUIURI',
|
93 |
|
|
'token type' => 'rules_uri',
|
94 |
|
|
),
|
95 |
|
|
'list' => array(
|
96 |
|
|
'label' => t('list', array(), array('context' => 'data_types')),
|
97 |
|
|
'wrap' => TRUE,
|
98 |
|
|
'group' => t('List', array(), array('context' => 'data_types')),
|
99 |
|
|
),
|
100 |
|
|
'list<text>' => array(
|
101 |
|
|
'label' => t('list of text'),
|
102 |
|
|
'ui class' => 'RulesDataUIListText',
|
103 |
|
|
'wrap' => TRUE,
|
104 |
|
|
'group' => t('List', array(), array('context' => 'data_types')),
|
105 |
|
|
),
|
106 |
|
|
'list<integer>' => array(
|
107 |
|
|
'label' => t('list of integer'),
|
108 |
|
|
'ui class' => 'RulesDataUIListInteger',
|
109 |
|
|
'wrap' => TRUE,
|
110 |
|
|
'group' => t('List', array(), array('context' => 'data_types')),
|
111 |
|
|
),
|
112 |
|
|
'list<token>' => array(
|
113 |
|
|
'label' => t('list of text tokens'),
|
114 |
|
|
'ui class' => 'RulesDataUIListToken',
|
115 |
|
|
'wrap' => TRUE,
|
116 |
|
|
'group' => t('List', array(), array('context' => 'data_types')),
|
117 |
|
|
),
|
118 |
|
|
'entity' => array(
|
119 |
|
|
'label' => t('any entity'),
|
120 |
|
|
'group' => t('Entity'),
|
121 |
|
|
'is wrapped' => TRUE,
|
122 |
|
|
),
|
123 |
76e2e7c3
|
Assos Assos
|
'ip_address' => array(
|
124 |
|
|
'label' => t('IP Address'),
|
125 |
|
|
'parent' => 'text',
|
126 |
|
|
'ui class' => 'RulesDataUIIPAddress',
|
127 |
|
|
'token type' => 'rules_text',
|
128 |
|
|
),
|
129 |
85ad3d82
|
Assos Assos
|
);
|
130 |
|
|
foreach (entity_get_info() as $type => $info) {
|
131 |
|
|
if (!empty($info['label'])) {
|
132 |
|
|
$return[$type] = array(
|
133 |
|
|
'label' => strtolower($info['label'][0]) . substr($info['label'], 1),
|
134 |
|
|
'parent' => 'entity',
|
135 |
|
|
'wrap' => TRUE,
|
136 |
|
|
'group' => t('Entity'),
|
137 |
|
|
'ui class' => empty($info['exportable']) ? 'RulesDataUIEntity' : 'RulesDataUIEntityExportable',
|
138 |
|
|
);
|
139 |
|
|
// If this entity type serves as bundle for another one, provide an
|
140 |
|
|
// options list for selecting a bundle entity.
|
141 |
|
|
if (!empty($info['bundle of'])) {
|
142 |
|
|
$return[$type]['ui class'] = 'RulesDataUIBundleEntity';
|
143 |
|
|
}
|
144 |
|
|
}
|
145 |
|
|
}
|
146 |
|
|
|
147 |
|
|
if (module_exists('taxonomy')) {
|
148 |
|
|
// For exportability identify vocabularies by name.
|
149 |
|
|
$return['taxonomy_vocabulary']['wrapper class'] = 'RulesTaxonomyVocabularyWrapper';
|
150 |
|
|
$return['taxonomy_vocabulary']['ui class'] = 'RulesDataUITaxonomyVocabulary';
|
151 |
|
|
}
|
152 |
|
|
|
153 |
|
|
return $return;
|
154 |
|
|
}
|
155 |
|
|
|
156 |
|
|
/**
|
157 |
|
|
* Implements hook_rules_data_info_alter() on behalf of the pseudo rules_core module.
|
158 |
|
|
*
|
159 |
|
|
* Makes sure there is a list<type> data type for each type registered.
|
160 |
|
|
*
|
161 |
|
|
* @see rules_rules_data_info_alter()
|
162 |
|
|
*/
|
163 |
|
|
function rules_rules_core_data_info_alter(&$data_info) {
|
164 |
|
|
foreach ($data_info as $type => $info) {
|
165 |
|
|
if (!entity_property_list_extract_type($type)) {
|
166 |
|
|
$list_type = "list<$type>";
|
167 |
|
|
if (!isset($data_info[$list_type])) {
|
168 |
|
|
$data_info[$list_type] = array(
|
169 |
|
|
'label' => t('list of @type_label items', array('@type_label' => $info['label'])),
|
170 |
|
|
'wrap' => TRUE,
|
171 |
|
|
'group' => t('List', array(), array('context' => 'data_types')),
|
172 |
|
|
);
|
173 |
|
|
if (isset($info['parent']) && $info['parent'] == 'entity') {
|
174 |
|
|
$data_info[$list_type]['ui class'] = 'RulesDataUIListEntity';
|
175 |
|
|
}
|
176 |
|
|
}
|
177 |
|
|
}
|
178 |
|
|
}
|
179 |
|
|
}
|
180 |
|
|
|
181 |
|
|
/**
|
182 |
|
|
* Implements hook_rules_evaluator_info() on behalf of the pseudo rules_core
|
183 |
|
|
* module.
|
184 |
|
|
*
|
185 |
|
|
* @see rules_core_modules()
|
186 |
|
|
*/
|
187 |
|
|
function rules_rules_core_evaluator_info() {
|
188 |
|
|
return array(
|
189 |
|
|
// Process strtotime() inputs to timestamps.
|
190 |
|
|
'date' => array(
|
191 |
|
|
'class' => 'RulesDateInputEvaluator',
|
192 |
|
|
'type' => 'date',
|
193 |
|
|
'weight' => -10,
|
194 |
|
|
),
|
195 |
|
|
// Post-process any input value to absolute URIs.
|
196 |
|
|
'uri' => array(
|
197 |
|
|
'class' => 'RulesURIInputEvaluator',
|
198 |
|
|
'type' => 'uri',
|
199 |
|
|
'weight' => 50,
|
200 |
|
|
),
|
201 |
|
|
);
|
202 |
|
|
}
|
203 |
|
|
|
204 |
|
|
/**
|
205 |
|
|
* Implements hook_rules_data_processor_info() on behalf of the pseudo
|
206 |
|
|
* rules_core module.
|
207 |
|
|
*
|
208 |
|
|
* @see rules_core_modules()
|
209 |
|
|
*/
|
210 |
|
|
function rules_rules_core_data_processor_info() {
|
211 |
|
|
return array(
|
212 |
|
|
'date_offset' => array(
|
213 |
|
|
'class' => 'RulesDateOffsetProcessor',
|
214 |
|
|
'type' => 'date',
|
215 |
|
|
'weight' => -2,
|
216 |
|
|
),
|
217 |
|
|
'num_offset' => array(
|
218 |
|
|
'class' => 'RulesNumericOffsetProcessor',
|
219 |
|
|
'type' => array('integer', 'decimal'),
|
220 |
|
|
'weight' => -2,
|
221 |
|
|
),
|
222 |
|
|
);
|
223 |
|
|
}
|
224 |
|
|
|
225 |
|
|
/**
|
226 |
|
|
* Implements hook_rules_condition_info() on behalf of the pseudo rules_core
|
227 |
|
|
* module.
|
228 |
|
|
*
|
229 |
|
|
* @see rules_core_modules()
|
230 |
|
|
*/
|
231 |
|
|
function rules_rules_core_condition_info() {
|
232 |
|
|
$defaults = array(
|
233 |
|
|
'group' => t('Components'),
|
234 |
|
|
'base' => 'rules_element_invoke_component',
|
235 |
|
|
'named parameter' => TRUE,
|
236 |
|
|
'access callback' => 'rules_element_invoke_component_access_callback',
|
237 |
|
|
);
|
238 |
|
|
$items = array();
|
239 |
|
|
foreach (rules_get_components(FALSE, 'condition') as $name => $config) {
|
240 |
|
|
$items['component_' . $name] = $defaults + array(
|
241 |
|
|
'label' => $config->plugin() . ': ' . drupal_ucfirst($config->label()),
|
242 |
|
|
'parameter' => $config->parameterInfo(),
|
243 |
|
|
);
|
244 |
|
|
$items['component_' . $name]['#config_name'] = $name;
|
245 |
|
|
}
|
246 |
|
|
return $items;
|
247 |
|
|
}
|
248 |
|
|
|
249 |
|
|
/**
|
250 |
|
|
* Implements hook_rules_action_info() on behalf of the pseudo rules_core
|
251 |
|
|
* module.
|
252 |
|
|
*
|
253 |
|
|
* @see rules_core_modules()
|
254 |
|
|
*/
|
255 |
|
|
function rules_rules_core_action_info() {
|
256 |
|
|
$defaults = array(
|
257 |
|
|
'group' => t('Components'),
|
258 |
|
|
'base' => 'rules_element_invoke_component',
|
259 |
|
|
'named parameter' => TRUE,
|
260 |
|
|
'access callback' => 'rules_element_invoke_component_access_callback',
|
261 |
|
|
);
|
262 |
|
|
$items = array();
|
263 |
|
|
foreach (rules_get_components(FALSE, 'action') as $name => $config) {
|
264 |
|
|
$items['component_' . $name] = $defaults + array(
|
265 |
|
|
'label' => $config->plugin() . ': ' . drupal_ucfirst($config->label()),
|
266 |
|
|
'parameter' => $config->parameterInfo(),
|
267 |
|
|
'provides' => $config->providesVariables(),
|
268 |
|
|
);
|
269 |
|
|
$items['component_' . $name]['#config_name'] = $name;
|
270 |
|
|
}
|
271 |
|
|
return $items;
|
272 |
|
|
}
|
273 |
|
|
|
274 |
|
|
/**
|
275 |
|
|
* Implements RulesPluginUIInterface::operations() for the action.
|
276 |
|
|
*/
|
277 |
|
|
function rules_element_invoke_component_operations(RulesPlugin $element) {
|
278 |
|
|
$defaults = $element->extender('RulesPluginUI')->operations();
|
279 |
|
|
$info = $element->info();
|
280 |
|
|
|
281 |
|
|
// Add an operation for editing the component.
|
282 |
|
|
$defaults['#links']['component'] = array(
|
283 |
|
|
'title' => t('edit component'),
|
284 |
|
|
'href' => RulesPluginUI::path($info['#config_name']),
|
285 |
|
|
);
|
286 |
|
|
return $defaults;
|
287 |
|
|
}
|
288 |
|
|
|
289 |
|
|
/**
|
290 |
|
|
* Validate callback to make sure the invoked component exists and is not dirty.
|
291 |
|
|
*
|
292 |
|
|
* @see rules_scheduler_action_schedule_validate()
|
293 |
|
|
*/
|
294 |
|
|
function rules_element_invoke_component_validate(RulesPlugin $element) {
|
295 |
|
|
$info = $element->info();
|
296 |
|
|
$component = rules_config_load($info['#config_name']);
|
297 |
|
|
// Check if a component exists.
|
298 |
|
|
if (!$component) {
|
299 |
|
|
throw new RulesIntegrityException(t('The component %config does not exist.', array('%config' => $info['#config_name'])), $element);
|
300 |
|
|
}
|
301 |
|
|
// Check if a component is marked as dirty.
|
302 |
|
|
rules_config_update_dirty_flag($component);
|
303 |
|
|
if (!empty($component->dirty)) {
|
304 |
|
|
throw new RulesIntegrityException(t('The utilized component %config fails the integrity check.', array('%config' => $info['#config_name'])), $element);
|
305 |
|
|
}
|
306 |
|
|
}
|
307 |
|
|
|
308 |
|
|
/**
|
309 |
|
|
* Implements the features export callback of the RulesPluginFeaturesIntegrationInterace.
|
310 |
|
|
*/
|
311 |
|
|
function rules_element_invoke_component_features_export(&$export, &$pipe, $module_name = '', $element) {
|
312 |
|
|
// Add the used component to the pipe.
|
313 |
|
|
$info = $element->info();
|
314 |
|
|
$pipe['rules_config'][] = $info['#config_name'];
|
315 |
|
|
}
|
316 |
|
|
|
317 |
|
|
/**
|
318 |
|
|
* Access callback for the invoke component condition/action.
|
319 |
|
|
*/
|
320 |
|
|
function rules_element_invoke_component_access_callback($type, $name) {
|
321 |
|
|
// Cut of the leading 'component_' from the action name.
|
322 |
|
|
$component = rules_config_load(substr($name, 10));
|
323 |
|
|
|
324 |
|
|
if (!$component) {
|
325 |
|
|
// Missing component.
|
326 |
|
|
return FALSE;
|
327 |
|
|
}
|
328 |
|
|
// If access is not exposed for this component, default to component access.
|
329 |
|
|
if (empty($component->access_exposed)) {
|
330 |
|
|
return $component->access();
|
331 |
|
|
}
|
332 |
|
|
// Apply the permissions.
|
333 |
|
|
return user_access('bypass rules access') || user_access("use Rules component $component->name");
|
334 |
|
|
}
|
335 |
|
|
|
336 |
|
|
/**
|
337 |
|
|
* @}
|
338 |
|
|
*/ |