1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* CTools plugin. Provides support for rules components (rule, ruleset, action).
|
6 |
|
|
*/
|
7 |
|
|
|
8 |
|
|
$plugin = array(
|
9 |
|
|
'title' => t('Rules component'),
|
10 |
|
|
'list callback' => 'views_bulk_operations_operation_rules_component_list',
|
11 |
|
|
'handler' => array(
|
12 |
|
|
'file' => 'rules_component.class.php',
|
13 |
|
|
'class' => 'ViewsBulkOperationsRulesComponent',
|
14 |
|
|
),
|
15 |
|
|
);
|
16 |
|
|
|
17 |
|
|
/**
|
18 |
|
|
* Returns a prepared list of available rules components.
|
19 |
|
|
*
|
20 |
|
|
* @param $operation_id
|
21 |
|
|
* The full, prefixed operation_id of the operation (in this case, rules
|
22 |
|
|
* component) to return, or NULL to return an array with all operations.
|
23 |
|
|
*/
|
24 |
|
|
function views_bulk_operations_operation_rules_component_list($operation_id = NULL) {
|
25 |
|
|
if (!module_exists('rules')) {
|
26 |
|
|
return array();
|
27 |
|
|
}
|
28 |
|
|
|
29 |
|
|
$entity_info = entity_get_info();
|
30 |
|
|
$entity_types = array_keys($entity_info);
|
31 |
|
|
$supported_types = array('entity', 'list<entity>');
|
32 |
|
|
$list_types = array('list<entity>');
|
33 |
|
|
foreach ($entity_types as $type) {
|
34 |
|
|
$supported_types[] = $type;
|
35 |
|
|
$supported_types[] = "list<$type>";
|
36 |
|
|
$list_types[] = "list<$type>";
|
37 |
|
|
}
|
38 |
|
|
|
39 |
|
|
$components = array();
|
40 |
|
|
if (isset($operation_id)) {
|
41 |
|
|
$id_fragments = explode('::', $operation_id);
|
42 |
|
|
$components[$id_fragments[1]] = rules_config_load($id_fragments[1]);
|
43 |
|
|
// No need to go any further if the component no longer exists.
|
44 |
|
|
if (!$components[$id_fragments[1]]) {
|
45 |
|
|
return FALSE;
|
46 |
|
|
}
|
47 |
|
|
}
|
48 |
|
|
else {
|
49 |
|
|
$components = rules_get_components(FALSE, 'action');
|
50 |
|
|
}
|
51 |
|
|
|
52 |
|
|
$operations = array();
|
53 |
|
|
foreach ($components as $name => $component) {
|
54 |
|
|
$parameter_info = $component->parameterInfo();
|
55 |
|
|
$first_parameter = reset($parameter_info);
|
56 |
|
|
$parameter_keys = array_keys($parameter_info);
|
57 |
|
|
$entity_key = reset($parameter_keys);
|
58 |
|
|
// If the first param is not an entity type, skip the component.
|
59 |
|
|
if (!in_array($first_parameter['type'], $supported_types)) {
|
60 |
|
|
continue;
|
61 |
|
|
}
|
62 |
|
|
|
63 |
|
|
// If the first parameter is a list type (list<node>, list<entity>, etc)
|
64 |
|
|
// then turn aggregation on, and set the correct entity type.
|
65 |
|
|
if (in_array($first_parameter['type'], $list_types)) {
|
66 |
|
|
$type = str_replace(array('list<', '>'), '', $first_parameter['type']);
|
67 |
|
|
$aggregate = TRUE;
|
68 |
|
|
}
|
69 |
|
|
else {
|
70 |
|
|
$type = $first_parameter['type'];
|
71 |
|
|
$aggregate = FALSE;
|
72 |
|
|
}
|
73 |
|
|
|
74 |
|
|
// All operations must be prefixed with the operation type.
|
75 |
|
|
$new_operation_id = 'rules_component::' . $name;
|
76 |
|
|
$operations[$new_operation_id] = array(
|
77 |
|
|
'operation_type' => 'rules_component',
|
78 |
|
|
// Keep the unprefixed key around, for internal use.
|
79 |
|
|
'key' => $name,
|
80 |
|
|
'label' => $component->label,
|
81 |
|
|
'parameters' => array('component_key' => $name, 'entity_key' => $entity_key),
|
82 |
|
|
'configurable' => count($parameter_info) > 1,
|
83 |
|
|
'type' => $type,
|
84 |
|
|
'aggregate' => $aggregate,
|
85 |
|
|
);
|
86 |
|
|
}
|
87 |
|
|
|
88 |
|
|
if (isset($operation_id)) {
|
89 |
|
|
return isset($operations[$operation_id]) ? $operations[$operation_id] : FALSE;
|
90 |
|
|
}
|
91 |
|
|
else {
|
92 |
|
|
return $operations;
|
93 |
|
|
}
|
94 |
|
|
} |