1 | <?php |
---|
2 | |
---|
3 | /** |
---|
4 | * @file |
---|
5 | * Provide a tool for creating UIs for exportable objects. |
---|
6 | * |
---|
7 | * See Advanced Help for documentation. |
---|
8 | */ |
---|
9 | /** |
---|
10 | * Implementation of hook_ctools_plugin_*. |
---|
11 | */ |
---|
12 | function ctools_ctools_plugin_export_ui() { |
---|
13 | return array( |
---|
14 | 'process' => 'ctools_export_ui_process', |
---|
15 | ); |
---|
16 | } |
---|
17 | |
---|
18 | /** |
---|
19 | * Process an export-ui plugin to provide it with defaults. |
---|
20 | */ |
---|
21 | function ctools_export_ui_process(&$plugin, $info) { |
---|
22 | ctools_include('export'); |
---|
23 | |
---|
24 | $plugin += array( |
---|
25 | 'has menu' => TRUE, |
---|
26 | 'title' => $plugin['name'], |
---|
27 | 'export' => array(), |
---|
28 | 'allowed operations' => array(), |
---|
29 | 'menu' => array(), |
---|
30 | 'form' => array(), |
---|
31 | 'strings' => array(), |
---|
32 | 'list' => NULL, |
---|
33 | 'access' => 'administer site configuration', |
---|
34 | 'use advanced help' => FALSE, |
---|
35 | 'advanced help' => array(), |
---|
36 | ); |
---|
37 | |
---|
38 | // Provide CRUD access defaults based on the base 'access' setting: |
---|
39 | $plugin += array( |
---|
40 | 'create access' => $plugin['access'], |
---|
41 | 'delete access' => $plugin['access'], |
---|
42 | ); |
---|
43 | |
---|
44 | if (empty($plugin['has menu'])) { |
---|
45 | return; |
---|
46 | } |
---|
47 | |
---|
48 | // The following keys are required and the plugin cannot be processed |
---|
49 | // without them. |
---|
50 | $keys = array( |
---|
51 | 'title singular', |
---|
52 | 'title plural', |
---|
53 | 'title singular proper', |
---|
54 | 'title plural proper', |
---|
55 | 'schema', |
---|
56 | ); |
---|
57 | |
---|
58 | foreach ($keys as $key) { |
---|
59 | if (empty($plugin[$key])) { |
---|
60 | drupal_set_message(t('The plugin definition of @plugin is missing the %key key.', array('%key' => $key, '@plugin' => $plugin['name'])), 'error'); |
---|
61 | } |
---|
62 | } |
---|
63 | |
---|
64 | // If we're on the modules page and building a menu, there is a design flaw |
---|
65 | // in Drupal core that causes modules to be installed but the schema does |
---|
66 | // not become available until AFTER menu rebuild. This helps smooth that |
---|
67 | // out. This is a HACK but it should work: |
---|
68 | $schema = ctools_export_get_schema($plugin['schema']); |
---|
69 | |
---|
70 | if (!$schema && $_GET['q'] == 'admin/build/modules/list/confirm') { |
---|
71 | $schema = ctools_export_get_schema($plugin['schema'], TRUE); |
---|
72 | } |
---|
73 | |
---|
74 | if (empty($schema)) { |
---|
75 | // If we're updating the schema may not have been read yet, so don't report this error in that case. |
---|
76 | if (!defined('MAINTENANCE_MODE')) { |
---|
77 | drupal_set_message(t('The plugin definition of @plugin cannot locate schema %schema.', array('%schema' => $plugin['schema'], '@plugin' => $plugin['name'])), 'error'); |
---|
78 | } |
---|
79 | return; |
---|
80 | } |
---|
81 | |
---|
82 | if (empty($schema['export'])) { |
---|
83 | drupal_set_message(t('The plugin definition of @plugin uses %schema, but it has no export section.', array('%schema' => $plugin['schema'], '@plugin' => $plugin['name'])), 'error'); |
---|
84 | return; |
---|
85 | } |
---|
86 | |
---|
87 | $plugin['export'] += array( |
---|
88 | // Add the identifier key from the schema so we don't have to call |
---|
89 | // ctools_export_get_schema() just for that. |
---|
90 | 'key' => $schema['export']['key'], |
---|
91 | ); |
---|
92 | |
---|
93 | // Add some default fields that appear often in exports |
---|
94 | // If these use different keys they can easily be specified in the |
---|
95 | // $plugin. |
---|
96 | |
---|
97 | if (empty($plugin['export']['admin_title']) && !empty($schema['fields']['admin_title'])) { |
---|
98 | $plugin['export']['admin_title'] = 'admin_title'; |
---|
99 | } |
---|
100 | if (empty($plugin['export']['admin_description']) && !empty($schema['fields']['admin_description'])) { |
---|
101 | $plugin['export']['admin_description'] = 'admin_description'; |
---|
102 | } |
---|
103 | |
---|
104 | // Define allowed operations, and the name of the operations. |
---|
105 | $plugin['allowed operations'] += array( |
---|
106 | 'edit' => array('title' => t('Edit')), |
---|
107 | 'enable' => array('title' => t('Enable'), 'ajax' => TRUE, 'token' => TRUE), |
---|
108 | 'disable' => array('title' => t('Disable'), 'ajax' => TRUE, 'token' => TRUE), |
---|
109 | 'revert' => array('title' => t('Revert')), |
---|
110 | 'delete' => array('title' => t('Delete')), |
---|
111 | 'clone' => array('title' => t('Clone')), |
---|
112 | 'import' => array('title' => t('Import')), |
---|
113 | 'export' => array('title' => t('Export')), |
---|
114 | ); |
---|
115 | |
---|
116 | $plugin['menu'] += array( |
---|
117 | 'menu item' => str_replace(' ', '-', $plugin['name']), |
---|
118 | 'menu prefix' => 'admin/build', |
---|
119 | 'menu title' => $plugin['title'], |
---|
120 | 'menu description' => '', |
---|
121 | ); |
---|
122 | $base_path = ctools_export_ui_plugin_base_path($plugin); |
---|
123 | $prefix_count = count(explode('/', $plugin['menu']['menu prefix'])); |
---|
124 | |
---|
125 | $plugin['menu'] += array( |
---|
126 | // Default menu items that should be declared. |
---|
127 | 'items' => array(), |
---|
128 | ); |
---|
129 | |
---|
130 | $plugin['menu']['items'] += array( |
---|
131 | 'list callback' => array( |
---|
132 | 'path' => '', |
---|
133 | // Menu items are translated by the menu system. |
---|
134 | // TODO: We need more flexibility in title. The title of the admin page |
---|
135 | // is not necessarily the title of the object, plus we need |
---|
136 | // plural, singular, proper, not proper, etc. |
---|
137 | 'title' => $plugin['menu']['menu title'], |
---|
138 | 'description' => $plugin['menu']['menu description'], |
---|
139 | 'page callback' => 'ctools_export_ui_switcher_page', |
---|
140 | 'page arguments' => array($plugin['name'], 'list'), |
---|
141 | 'access callback' => 'ctools_export_ui_task_access', |
---|
142 | 'access arguments' => array($plugin['name'], 'list'), |
---|
143 | 'type' => MENU_NORMAL_ITEM, |
---|
144 | ), |
---|
145 | 'list' => array( |
---|
146 | 'path' => 'list', |
---|
147 | 'title' => 'List', |
---|
148 | 'page callback' => 'ctools_export_ui_switcher_page', |
---|
149 | 'page arguments' => array($plugin['name'], 'list'), |
---|
150 | 'access callback' => 'ctools_export_ui_task_access', |
---|
151 | 'access arguments' => array($plugin['name'], 'list'), |
---|
152 | 'type' => MENU_DEFAULT_LOCAL_TASK, |
---|
153 | 'weight' => -10, |
---|
154 | ), |
---|
155 | 'add' => array( |
---|
156 | 'path' => 'add', |
---|
157 | 'title' => 'Add', |
---|
158 | 'page callback' => 'ctools_export_ui_switcher_page', |
---|
159 | 'page arguments' => array($plugin['name'], 'add'), |
---|
160 | 'access callback' => 'ctools_export_ui_task_access', |
---|
161 | 'access arguments' => array($plugin['name'], 'add'), |
---|
162 | 'type' => MENU_LOCAL_TASK, |
---|
163 | ), |
---|
164 | 'edit callback' => array( |
---|
165 | 'path' => 'list/%ctools_export_ui', |
---|
166 | 'page callback' => 'ctools_export_ui_switcher_page', |
---|
167 | 'page arguments' => array($plugin['name'], 'edit', $prefix_count + 2), |
---|
168 | 'load arguments' => array($plugin['name']), |
---|
169 | 'access callback' => 'ctools_export_ui_task_access', |
---|
170 | 'access arguments' => array($plugin['name'], 'edit', $prefix_count + 2), |
---|
171 | 'type' => MENU_CALLBACK, |
---|
172 | ), |
---|
173 | 'edit' => array( |
---|
174 | 'path' => 'list/%ctools_export_ui/edit', |
---|
175 | 'title' => 'Edit', |
---|
176 | 'page callback' => 'ctools_export_ui_switcher_page', |
---|
177 | 'page arguments' => array($plugin['name'], 'edit', $prefix_count + 2), |
---|
178 | 'load arguments' => array($plugin['name']), |
---|
179 | 'access callback' => 'ctools_export_ui_task_access', |
---|
180 | 'access arguments' => array($plugin['name'], 'edit', $prefix_count + 2), |
---|
181 | 'type' => MENU_DEFAULT_LOCAL_TASK, |
---|
182 | ), |
---|
183 | ); |
---|
184 | |
---|
185 | if ($plugin['allowed operations']['import']) { |
---|
186 | $plugin['menu']['items'] += array( |
---|
187 | 'import' => array( |
---|
188 | 'path' => 'import', |
---|
189 | 'title' => 'Import', |
---|
190 | 'page callback' => 'ctools_export_ui_switcher_page', |
---|
191 | 'page arguments' => array($plugin['name'], 'import'), |
---|
192 | 'access callback' => 'ctools_export_ui_task_access', |
---|
193 | 'access arguments' => array($plugin['name'], 'import'), |
---|
194 | 'type' => MENU_LOCAL_TASK, |
---|
195 | ), |
---|
196 | ); |
---|
197 | } |
---|
198 | |
---|
199 | if ($plugin['allowed operations']['export']) { |
---|
200 | $plugin['menu']['items'] += array( |
---|
201 | 'export' => array( |
---|
202 | 'path' => 'list/%ctools_export_ui/export', |
---|
203 | 'title' => 'Export', |
---|
204 | 'page callback' => 'ctools_export_ui_switcher_page', |
---|
205 | 'page arguments' => array($plugin['name'], 'export', $prefix_count + 2), |
---|
206 | 'load arguments' => array($plugin['name']), |
---|
207 | 'access callback' => 'ctools_export_ui_task_access', |
---|
208 | 'access arguments' => array($plugin['name'], 'export', $prefix_count + 2), |
---|
209 | 'type' => MENU_LOCAL_TASK, |
---|
210 | ), |
---|
211 | ); |
---|
212 | } |
---|
213 | |
---|
214 | if ($plugin['allowed operations']['revert']) { |
---|
215 | $plugin['menu']['items'] += array( |
---|
216 | 'revert' => array( |
---|
217 | 'path' => 'list/%ctools_export_ui/revert', |
---|
218 | 'title' => 'Revert', |
---|
219 | 'page callback' => 'ctools_export_ui_switcher_page', |
---|
220 | // Note: Yes, 'delete' op is correct. |
---|
221 | 'page arguments' => array($plugin['name'], 'delete', $prefix_count + 2), |
---|
222 | 'load arguments' => array($plugin['name']), |
---|
223 | 'access callback' => 'ctools_export_ui_task_access', |
---|
224 | 'access arguments' => array($plugin['name'], 'revert', $prefix_count + 2), |
---|
225 | 'type' => MENU_CALLBACK, |
---|
226 | ), |
---|
227 | ); |
---|
228 | } |
---|
229 | |
---|
230 | if ($plugin['allowed operations']['delete']) { |
---|
231 | $plugin['menu']['items'] += array( |
---|
232 | 'delete' => array( |
---|
233 | 'path' => 'list/%ctools_export_ui/delete', |
---|
234 | 'title' => 'Delete', |
---|
235 | 'page callback' => 'ctools_export_ui_switcher_page', |
---|
236 | 'page arguments' => array($plugin['name'], 'delete', $prefix_count + 2), |
---|
237 | 'load arguments' => array($plugin['name']), |
---|
238 | 'access callback' => 'ctools_export_ui_task_access', |
---|
239 | 'access arguments' => array($plugin['name'], 'delete', $prefix_count + 2), |
---|
240 | 'type' => MENU_CALLBACK, |
---|
241 | ), |
---|
242 | ); |
---|
243 | } |
---|
244 | |
---|
245 | if ($plugin['allowed operations']['clone']) { |
---|
246 | $plugin['menu']['items'] += array( |
---|
247 | 'clone' => array( |
---|
248 | 'path' => 'list/%ctools_export_ui/clone', |
---|
249 | 'title' => 'Clone', |
---|
250 | 'page callback' => 'ctools_export_ui_switcher_page', |
---|
251 | 'page arguments' => array($plugin['name'], 'clone', $prefix_count + 2), |
---|
252 | 'load arguments' => array($plugin['name']), |
---|
253 | 'access callback' => 'ctools_export_ui_task_access', |
---|
254 | 'access arguments' => array($plugin['name'], 'clone', $prefix_count + 2), |
---|
255 | 'type' => MENU_CALLBACK, |
---|
256 | ), |
---|
257 | ); |
---|
258 | } |
---|
259 | |
---|
260 | if ($plugin['allowed operations']['enable']) { |
---|
261 | $plugin['menu']['items'] += array( |
---|
262 | 'enable' => array( |
---|
263 | 'path' => 'list/%ctools_export_ui/enable', |
---|
264 | 'title' => 'Enable', |
---|
265 | 'page callback' => 'ctools_export_ui_switcher_page', |
---|
266 | 'page arguments' => array($plugin['name'], 'enable', $prefix_count + 2), |
---|
267 | 'load arguments' => array($plugin['name']), |
---|
268 | 'access callback' => 'ctools_export_ui_task_access', |
---|
269 | 'access arguments' => array($plugin['name'], 'enable', $prefix_count + 2), |
---|
270 | 'type' => MENU_CALLBACK, |
---|
271 | ), |
---|
272 | ); |
---|
273 | } |
---|
274 | |
---|
275 | if ($plugin['allowed operations']['disable']) { |
---|
276 | $plugin['menu']['items'] += array( |
---|
277 | 'disable' => array( |
---|
278 | 'path' => 'list/%ctools_export_ui/disable', |
---|
279 | 'title' => 'Disable', |
---|
280 | 'page callback' => 'ctools_export_ui_switcher_page', |
---|
281 | 'page arguments' => array($plugin['name'], 'disable', $prefix_count + 2), |
---|
282 | 'load arguments' => array($plugin['name']), |
---|
283 | 'access callback' => 'ctools_export_ui_task_access', |
---|
284 | 'access arguments' => array($plugin['name'], 'disable', $prefix_count + 2), |
---|
285 | 'type' => MENU_CALLBACK, |
---|
286 | ), |
---|
287 | ); |
---|
288 | } |
---|
289 | |
---|
290 | // Define some redirects that should happen after edit/add/clone operations. |
---|
291 | $plugin['redirect'] = array( |
---|
292 | 'add' => $base_path, |
---|
293 | 'clone' => $base_path, |
---|
294 | 'edit' => $base_path, |
---|
295 | 'import' => $base_path, |
---|
296 | ); |
---|
297 | |
---|
298 | // Define form elements. |
---|
299 | $plugin['form'] += array( |
---|
300 | 'settings' => function_exists($plugin['name'] . '_form') ? $plugin['name'] . '_form' : '', |
---|
301 | 'validate' => function_exists($plugin['name'] . '_form_validate') ? $plugin['name'] . '_form_validate' : '', |
---|
302 | 'submit' => function_exists($plugin['name'] . '_form_submit') ? $plugin['name'] . '_form_submit' : '', |
---|
303 | ); |
---|
304 | |
---|
305 | // Define strings. |
---|
306 | |
---|
307 | // For all strings, %title may be filled in at a later time via str_replace |
---|
308 | // since we do not know the title now. |
---|
309 | $plugin['strings'] += array( |
---|
310 | 'title' => array(), |
---|
311 | 'confirmation' => array(), |
---|
312 | 'help' => array(), |
---|
313 | 'message' => array(), |
---|
314 | 'advanced help' => array(), |
---|
315 | ); |
---|
316 | |
---|
317 | // Strings used in drupal_set_title(). |
---|
318 | $plugin['strings']['title'] += array( |
---|
319 | 'add' => t('Add a new @plugin', array('@plugin' => $plugin['title singular'])), |
---|
320 | // The "%title" will be replaced in ctools_export_ui_form(), as in this |
---|
321 | // stage we dont have the specific exportable object. |
---|
322 | 'edit' => t('Edit @plugin %title', array('@plugin' => $plugin['title singular'])), |
---|
323 | 'clone' => t('Clone @plugin %title', array('@plugin' => $plugin['title singular'])), |
---|
324 | |
---|
325 | 'import' => t('Import @plugin', array('@plugin' => $plugin['title singular'])), |
---|
326 | 'export' => t('Export @plugin %title', array('@plugin' => $plugin['title singular'])), |
---|
327 | ); |
---|
328 | |
---|
329 | // Strings used in confirmation pages. |
---|
330 | $plugin['strings']['confirmation'] += array( |
---|
331 | 'revert' => array(), |
---|
332 | 'delete' => array(), |
---|
333 | 'add' => array(), |
---|
334 | 'edit' => array(), |
---|
335 | ); |
---|
336 | |
---|
337 | $plugin['strings']['confirmation']['revert'] += array( |
---|
338 | 'question' => t('Are you sure you want to revert %title?'), |
---|
339 | 'information' => t('This action will permanently remove any customizations made to this item.'), |
---|
340 | 'success' => t('The item has been reverted.'), |
---|
341 | ); |
---|
342 | |
---|
343 | $plugin['strings']['confirmation']['delete'] += array( |
---|
344 | 'question' => t('Are you sure you want to delete %title?'), |
---|
345 | 'information' => t('This action will permanently remove this item from your database..'), |
---|
346 | 'success' => t('The item has been deleted.'), |
---|
347 | ); |
---|
348 | |
---|
349 | $plugin['strings']['confirmation']['add'] += array( |
---|
350 | 'success' => t('%title has been created.'), |
---|
351 | 'fail' => t('%title could not be created.'), |
---|
352 | ); |
---|
353 | |
---|
354 | $plugin['strings']['confirmation']['edit'] += array( |
---|
355 | 'success' => t('%title has been updated.'), |
---|
356 | 'fail' => t('%title could not be updated.'), |
---|
357 | ); |
---|
358 | |
---|
359 | // Strings used in $forms. |
---|
360 | $plugin['strings']['help'] += array( |
---|
361 | 'import' => t('You can import an exported definition by pasting the exported object code into the field below.'), |
---|
362 | ); |
---|
363 | |
---|
364 | // Strings used in drupal_set_message(). |
---|
365 | $plugin['strings']['message'] += array( |
---|
366 | 'enable' => t('@plugin %title was enabled.', array('@plugin' => $plugin['title singular proper'])), |
---|
367 | 'disable' => t('@plugin %title was disabled.', array('@plugin' => $plugin['title singular proper'])), |
---|
368 | ); |
---|
369 | |
---|
370 | // Strings used if advanced help module is enabled. |
---|
371 | |
---|
372 | |
---|
373 | if (!empty($plugin['use advanced help'])) { |
---|
374 | if (module_exists('advanced_help')) { |
---|
375 | $plugin['advanced help'] += array( |
---|
376 | 'enabled' => TRUE, |
---|
377 | 'topic' => $plugin['module'], |
---|
378 | 'module' => $plugin['module'], |
---|
379 | ); |
---|
380 | } |
---|
381 | else { |
---|
382 | $plugin['advanced help'] += array( |
---|
383 | 'enabled' => FALSE, |
---|
384 | ); |
---|
385 | } |
---|
386 | |
---|
387 | // Get the module name. |
---|
388 | $info = drupal_parse_info_file(drupal_get_path('module', $plugin['module']) .'/'. $plugin['module'] .'.info'); |
---|
389 | $plugin['strings']['advanced help'] += array( |
---|
390 | // The strings to show when the advanced help module is enabled or disabled. |
---|
391 | 'enabled' => t('Learn more about the @module module.', array('@module' => $info['name'])), |
---|
392 | 'disabled' => t('Learn more about the @module module by enabling the <a href="@path">Advanced help</a> module.', array('@module' => $info['name'], '@path' => 'http://drupal.org/project/advanced_help')), |
---|
393 | ); |
---|
394 | } |
---|
395 | |
---|
396 | |
---|
397 | |
---|
398 | } |
---|
399 | |
---|
400 | /** |
---|
401 | * Get the class to handle creating a list of exportable items. |
---|
402 | * |
---|
403 | * If a plugin does not define a lister class at all, then the default |
---|
404 | * lister class will be used. |
---|
405 | * |
---|
406 | * @return |
---|
407 | * Either the lister class or FALSE if one could not be had. |
---|
408 | */ |
---|
409 | function ctools_export_ui_get_handler($plugin) { |
---|
410 | $cache = &ctools_static(__FUNCTION__, array()); |
---|
411 | if (empty($cache[$plugin['name']])) { |
---|
412 | // If a list class is not specified by the plugin, fall back to the |
---|
413 | // default ctools_export_ui plugin instead. |
---|
414 | if (empty($plugin['handler'])) { |
---|
415 | $default = ctools_get_export_ui('ctools_export_ui'); |
---|
416 | $class = ctools_plugin_get_class($default, 'handler'); |
---|
417 | } |
---|
418 | else { |
---|
419 | $class = ctools_plugin_get_class($plugin, 'handler'); |
---|
420 | } |
---|
421 | |
---|
422 | if ($class) { |
---|
423 | $cache[$plugin['name']] = new $class(); |
---|
424 | $cache[$plugin['name']]->init($plugin); |
---|
425 | } |
---|
426 | } |
---|
427 | return !empty($cache[$plugin['name']]) ? $cache[$plugin['name']] : FALSE; |
---|
428 | } |
---|
429 | |
---|
430 | /** |
---|
431 | * Get the base path from a plugin. |
---|
432 | * |
---|
433 | * @param $plugin |
---|
434 | * The plugin. |
---|
435 | * |
---|
436 | * @return |
---|
437 | * The menu path to the plugin's list. |
---|
438 | */ |
---|
439 | function ctools_export_ui_plugin_base_path($plugin) { |
---|
440 | return $plugin['menu']['menu prefix'] . '/' . $plugin['menu']['menu item']; |
---|
441 | } |
---|
442 | |
---|
443 | /** |
---|
444 | * Get the path to a specific menu item from a plugin. |
---|
445 | * |
---|
446 | * @param $plugin |
---|
447 | * The plugin name. |
---|
448 | * @param $item_id |
---|
449 | * The id in the menu items from the plugin. |
---|
450 | * @param $export_key |
---|
451 | * The export key of the item being edited, if it exists. |
---|
452 | * @return |
---|
453 | * The menu path to the plugin's list. |
---|
454 | */ |
---|
455 | function ctools_export_ui_plugin_menu_path($plugin, $item_id, $export_key = NULL) { |
---|
456 | $path = $plugin['menu']['items'][$item_id]['path']; |
---|
457 | if ($export_key) { |
---|
458 | $path = str_replace('%ctools_export_ui', $export_key, $path); |
---|
459 | } |
---|
460 | return ctools_export_ui_plugin_base_path($plugin) . '/' . $path; |
---|
461 | } |
---|
462 | |
---|
463 | /** |
---|
464 | * Helper function to include CTools plugins and get an export-ui exportable. |
---|
465 | * |
---|
466 | * @param $plugin_name |
---|
467 | * The plugin that should be laoded. |
---|
468 | */ |
---|
469 | function ctools_get_export_ui($plugin_name) { |
---|
470 | ctools_include('plugins'); |
---|
471 | return ctools_get_plugins('ctools', 'export_ui', $plugin_name); |
---|
472 | |
---|
473 | } |
---|
474 | |
---|
475 | /** |
---|
476 | * Helper function to include CTools plugins and get all export-ui exportables. |
---|
477 | */ |
---|
478 | function ctools_get_export_uis() { |
---|
479 | ctools_include('plugins'); |
---|
480 | return ctools_get_plugins('ctools', 'export_ui'); |
---|
481 | } |
---|
482 | |
---|
483 | /** |
---|
484 | * Main page callback to manipulate exportables. |
---|
485 | * |
---|
486 | * This simply loads the object defined in the plugin and hands it off to |
---|
487 | * a method based upon the name of the operation in use. This can easily |
---|
488 | * be used to add more ops. |
---|
489 | */ |
---|
490 | function ctools_export_ui_switcher_page($plugin_name, $op) { |
---|
491 | $args = func_get_args(); |
---|
492 | $js = !empty($_REQUEST['ctools_ajax']); |
---|
493 | |
---|
494 | // Load the $plugin information |
---|
495 | $plugin = ctools_get_export_ui($plugin_name); |
---|
496 | $handler = ctools_export_ui_get_handler($plugin); |
---|
497 | |
---|
498 | if ($handler) { |
---|
499 | $method = $op . '_page'; |
---|
500 | if (method_exists($handler, $method)) { |
---|
501 | // replace the first two arguments: |
---|
502 | $args[0] = $js; |
---|
503 | $args[1] = $_POST; |
---|
504 | return call_user_func_array(array($handler, $method), $args); |
---|
505 | } |
---|
506 | } |
---|
507 | else { |
---|
508 | return t('Configuration error. No handler found.'); |
---|
509 | } |
---|
510 | } |
---|