Commit | Line | Data |
---|---|---|
7f254ad8 AE |
1 | <?php |
2 | ||
3 | /** | |
4 | * @file | |
5 | * CTools plugin. Provides support for core actions. | |
6 | */ | |
7 | ||
8 | $plugin = array( | |
9 | 'title' => t('Action'), | |
10 | 'list callback' => 'views_bulk_operations_operation_action_list', | |
11 | 'handler' => array( | |
12 | 'file' => 'action.class.php', | |
13 | 'class' => 'ViewsBulkOperationsAction', | |
14 | ), | |
15 | ); | |
16 | ||
17 | /** | |
18 | * Returns a prepared list of available actions. | |
19 | * | |
20 | * Actions are fetched by invoking hook_action_info() and by loading | |
21 | * advanced actions from the database. | |
22 | * | |
23 | * @param $operation_id | |
24 | * The full, prefixed operation_id of the operation (in this case, action) | |
25 | * to return, or NULL to return an array with all operations. | |
26 | */ | |
27 | function views_bulk_operations_operation_action_list($operation_id = NULL) { | |
28 | $operations = &drupal_static(__FUNCTION__); | |
29 | ||
30 | if (!isset($operations)) { | |
31 | // Combined list of all actions and advanced actions. | |
32 | $actions_list = actions_list() + views_bulk_operations_operation_advanced_action_list(); | |
33 | // Actions provided by Drupal that aren't usable in a VBO context. | |
34 | $hidden_actions = array( | |
35 | 'system_block_ip_action', | |
36 | 'system_goto_action', | |
37 | 'system_message_action', | |
38 | ); | |
39 | ||
40 | $operations = array(); | |
41 | foreach ($actions_list as $key => $action) { | |
42 | // Actions are keyed by callback. | |
43 | // Advanced actions are keyed by aid and store the callback separately. | |
44 | $callback = isset($action['callback']) ? $action['callback'] : $key; | |
45 | // This action needs to be skipped. | |
46 | if (in_array($callback, $hidden_actions)) { | |
47 | continue; | |
48 | } | |
49 | ||
50 | // All operations must be prefixed with the operation type. | |
51 | $new_operation_id = 'action::' . $key; | |
52 | ||
53 | $operations[$new_operation_id] = array( | |
54 | 'operation_type' => 'action', | |
55 | 'type' => $action['type'], | |
56 | // Keep the unprefixed key around, for internal use. | |
57 | 'key' => $key, | |
58 | 'callback' => $callback, | |
59 | 'label' => isset($action['label']) ? $action['label'] : '', | |
60 | 'parameters' => isset($action['parameters']) ? $action['parameters'] : array(), | |
61 | 'configurable' => !empty($action['configurable']) || !empty($action['vbo_configurable']), | |
62 | 'aggregate' => !empty($action['aggregate']), | |
63 | 'behavior' => isset($action['behavior']) ? $action['behavior'] : array(), | |
64 | 'permissions' => isset($action['permissions']) ? $action['permissions'] : NULL, | |
65 | 'pass rows' => !empty($action['pass rows']), | |
66 | ); | |
67 | } | |
68 | } | |
69 | ||
70 | if (isset($operation_id)) { | |
71 | return isset($operations[$operation_id]) ? $operations[$operation_id] : FALSE; | |
72 | } | |
73 | else { | |
74 | return $operations; | |
75 | } | |
76 | } | |
77 | ||
78 | /** | |
79 | * Get a list of advanced actions (created through the Action UI). | |
80 | */ | |
81 | function views_bulk_operations_operation_advanced_action_list() { | |
82 | $actions = array(); | |
83 | $static_actions = actions_list(); | |
84 | $result = db_query("SELECT * FROM {actions} WHERE parameters > ''"); | |
85 | foreach ($result as $action) { | |
86 | $parameters = unserialize($action->parameters); | |
87 | $actions[$action->aid] = array( | |
88 | 'label' => isset($action->label) ? $action->label : '', | |
89 | 'callback' => $action->callback, | |
90 | 'type' => $action->type, | |
91 | 'configurable' => FALSE, | |
92 | 'parameters' => $parameters, | |
93 | ); | |
94 | foreach (array('aggregate', 'behavior', 'permissions', 'pass rows') as $attribute) { | |
95 | if (isset($static_actions[$action->callback][$attribute])) { | |
96 | $actions[$action->aid][$attribute] = $static_actions[$action->callback][$attribute]; | |
97 | } | |
98 | } | |
99 | if (isset($static_actions[$action->callback]['parameters'])) { | |
100 | $actions[$action->aid]['parameters'] = array_merge($actions[$action->aid]['parameters'], $static_actions[$action->callback]['parameters']); | |
101 | } | |
102 | } | |
103 | return $actions; | |
104 | } |