ctools_export_ui.class.php

  1. cis7 sites/all/modules/ulmus/ctools/plugins/export_ui/ctools_export_ui.class.php
  2. cle7 sites/all/modules/ulmus/ctools/plugins/export_ui/ctools_export_ui.class.php
  3. ecd7 sites/all/modules/ulmus/ctools/plugins/export_ui/ctools_export_ui.class.php
  4. elmsmedia7 sites/all/modules/ulmus/ctools/plugins/export_ui/ctools_export_ui.class.php
  5. harmony7 sites/all/modules/ulmus/ctools/plugins/export_ui/ctools_export_ui.class.php
  6. icor7 sites/all/modules/ulmus/ctools/plugins/export_ui/ctools_export_ui.class.php
  7. meedjum_blog7 sites/all/modules/ulmus/ctools/plugins/export_ui/ctools_export_ui.class.php
  8. mooc7 sites/all/modules/ulmus/ctools/plugins/export_ui/ctools_export_ui.class.php

Functions

Namesort descending Description
ctools_export_ui_delete_confirm_form Delete/Revert confirm form.
ctools_export_ui_edit_item_form Form callback to edit an exportable item.
ctools_export_ui_edit_item_form_delete Submit handler to delete for ctools_export_ui_edit_item_form
ctools_export_ui_edit_item_form_submit Submit handler for ctools_export_ui_edit_item_form.
ctools_export_ui_edit_item_form_validate Validate handler for ctools_export_ui_edit_item_form.
ctools_export_ui_edit_item_wizard_form Form callback to edit an exportable item using the wizard
ctools_export_ui_edit_item_wizard_form_submit Submit handler for ctools_export_ui_edit_item_wizard_form.
ctools_export_ui_edit_item_wizard_form_validate Validate handler for ctools_export_ui_edit_item_wizard_form.
ctools_export_ui_edit_name_exists Test for #machine_name type to see if an export exists.
ctools_export_ui_edit_name_validate Validate that an export item name is acceptable and unique during add.
ctools_export_ui_list_form Form callback to handle the filter/sort form when listing items.
ctools_export_ui_list_form_submit Submit handler for ctools_export_ui_list_form.
ctools_export_ui_list_form_validate Validate handler for ctools_export_ui_list_form.
ctools_export_ui_wizard_back Wizard 'back' callback when using a wizard to edit an item.
ctools_export_ui_wizard_cancel Wizard 'cancel' callback when using a wizard to edit an item.
ctools_export_ui_wizard_finish Wizard 'finish' callback when using a wizard to edit an item.
ctools_export_ui_wizard_next Wizard 'next' callback when using a wizard to edit an item.
_ctools_export_ui_add_form_files Add all appropriate includes to forms so that caching the form still loads the files that we need.

Classes

Namesort descending Description
ctools_export_ui Base class for export UI.

File

sites/all/modules/ulmus/ctools/plugins/export_ui/ctools_export_ui.class.php
View source
  1. <?php
  2. /**
  3. * Base class for export UI.
  4. */
  5. class ctools_export_ui {
  6. var $plugin;
  7. var $name;
  8. var $options = array();
  9. /**
  10. * Fake constructor -- this is easier to deal with than the real
  11. * constructor because we are retaining PHP4 compatibility, which
  12. * would require all child classes to implement their own constructor.
  13. */
  14. function init($plugin) {
  15. ctools_include('export');
  16. $this->plugin = $plugin;
  17. }
  18. /**
  19. * Get a page title for the current page from our plugin strings.
  20. */
  21. function get_page_title($op, $item = NULL) {
  22. if (empty($this->plugin['strings']['title'][$op])) {
  23. return;
  24. }
  25. // Replace %title that might be there with the exportable title.
  26. $title = $this->plugin['strings']['title'][$op];
  27. if (!empty($item)) {
  28. $export_key = $this->plugin['export']['key'];
  29. $title = (str_replace('%title', check_plain($item->{$export_key}), $title));
  30. }
  31. return $title;
  32. }
  33. /**
  34. * Called by ctools_export_ui_load to load the item.
  35. *
  36. * This can be overridden for modules that want to be able to export
  37. * items currently being edited, for example.
  38. */
  39. function load_item($item_name) {
  40. $item = ctools_export_crud_load($this->plugin['schema'], $item_name);
  41. return empty($item) ? FALSE : $item;
  42. }
  43. // ------------------------------------------------------------------------
  44. // Menu item manipulation
  45. /**
  46. * hook_menu() entry point.
  47. *
  48. * Child implementations that need to add or modify menu items should
  49. * probably call parent::hook_menu($items) and then modify as needed.
  50. */
  51. function hook_menu(&$items) {
  52. // During upgrades, the schema can be empty as this is called prior to
  53. // actual update functions being run. Ensure that we can cope with this
  54. // situation.
  55. if (empty($this->plugin['schema'])) {
  56. return;
  57. }
  58. $prefix = ctools_export_ui_plugin_base_path($this->plugin);
  59. if (isset($this->plugin['menu']['items']) && is_array($this->plugin['menu']['items'])) {
  60. $my_items = array();
  61. foreach ($this->plugin['menu']['items'] as $item) {
  62. // Add menu item defaults.
  63. $item += array(
  64. 'file' => 'export-ui.inc',
  65. 'file path' => drupal_get_path('module', 'ctools') . '/includes',
  66. );
  67. $path = !empty($item['path']) ? $prefix . '/' . $item['path'] : $prefix;
  68. unset($item['path']);
  69. $my_items[$path] = $item;
  70. }
  71. $items += $my_items;
  72. }
  73. }
  74. /**
  75. * Menu callback to determine if an operation is accessible.
  76. *
  77. * This function enforces a basic access check on the configured perm
  78. * string, and then additional checks as needed.
  79. *
  80. * @param $op
  81. * The 'op' of the menu item, which is defined by 'allowed operations'
  82. * and embedded into the arguments in the menu item.
  83. * @param $item
  84. * If an op that works on an item, then the item object, otherwise NULL.
  85. *
  86. * @return
  87. * TRUE if the current user has access, FALSE if not.
  88. */
  89. function access($op, $item) {
  90. if (!user_access($this->plugin['access'])) {
  91. return FALSE;
  92. }
  93. // More fine-grained access control:
  94. if ($op == 'add' && !user_access($this->plugin['create access'])) {
  95. return FALSE;
  96. }
  97. // More fine-grained access control:
  98. if (($op == 'revert' || $op == 'delete') && !user_access($this->plugin['delete access'])) {
  99. return FALSE;
  100. }
  101. // If we need to do a token test, do it here.
  102. if (!empty($this->plugin['allowed operations'][$op]['token']) && (!isset($_GET['token']) || !drupal_valid_token($_GET['token'], $op))) {
  103. return FALSE;
  104. }
  105. switch ($op) {
  106. case 'import':
  107. return user_access('use PHP for settings');
  108. case 'revert':
  109. return ($item->export_type & EXPORT_IN_DATABASE) && ($item->export_type & EXPORT_IN_CODE);
  110. case 'delete':
  111. return ($item->export_type & EXPORT_IN_DATABASE) && !($item->export_type & EXPORT_IN_CODE);
  112. case 'disable':
  113. return empty($item->disabled);
  114. case 'enable':
  115. return !empty($item->disabled);
  116. default:
  117. return TRUE;
  118. }
  119. }
  120. // ------------------------------------------------------------------------
  121. // These methods are the API for generating the list of exportable items.
  122. /**
  123. * Master entry point for handling a list.
  124. *
  125. * It is unlikely that a child object will need to override this method,
  126. * unless the listing mechanism is going to be highly specialized.
  127. */
  128. function list_page($js, $input) {
  129. $this->items = ctools_export_crud_load_all($this->plugin['schema'], $js);
  130. // Respond to a reset command by clearing session and doing a drupal goto
  131. // back to the base URL.
  132. if (isset($input['op']) && $input['op'] == t('Reset')) {
  133. unset($_SESSION['ctools_export_ui'][$this->plugin['name']]);
  134. if (!$js) {
  135. drupal_goto($_GET['q']);
  136. }
  137. // clear everything but form id, form build id and form token:
  138. $keys = array_keys($input);
  139. foreach ($keys as $id) {
  140. if (!in_array($id, array('form_id', 'form_build_id', 'form_token'))) {
  141. unset($input[$id]);
  142. }
  143. }
  144. $replace_form = TRUE;
  145. }
  146. // If there is no input, check to see if we have stored input in the
  147. // session.
  148. if (!isset($input['form_id'])) {
  149. if (isset($_SESSION['ctools_export_ui'][$this->plugin['name']]) && is_array($_SESSION['ctools_export_ui'][$this->plugin['name']])) {
  150. $input = $_SESSION['ctools_export_ui'][$this->plugin['name']];
  151. }
  152. }
  153. else {
  154. $_SESSION['ctools_export_ui'][$this->plugin['name']] = $input;
  155. unset($_SESSION['ctools_export_ui'][$this->plugin['name']]['q']);
  156. }
  157. // This is where the form will put the output.
  158. $this->rows = array();
  159. $this->sorts = array();
  160. $form_state = array(
  161. 'plugin' => $this->plugin,
  162. 'input' => $input,
  163. 'rerender' => TRUE,
  164. 'no_redirect' => TRUE,
  165. 'object' => &$this,
  166. );
  167. if (!isset($form_state['input']['form_id'])) {
  168. $form_state['input']['form_id'] = 'ctools_export_ui_list_form';
  169. }
  170. // If we do any form rendering, it's to completely replace a form on the
  171. // page, so don't let it force our ids to change.
  172. if ($js && isset($_POST['ajax_html_ids'])) {
  173. unset($_POST['ajax_html_ids']);
  174. }
  175. $form = drupal_build_form('ctools_export_ui_list_form', $form_state);
  176. $form = drupal_render($form);
  177. $output = $this->list_header($form_state) . $this->list_render($form_state) . $this->list_footer($form_state);
  178. if (!$js) {
  179. $this->list_css();
  180. return $form . $output;
  181. }
  182. $commands = array();
  183. $commands[] = ajax_command_replace('#ctools-export-ui-list-items', $output);
  184. if (!empty($replace_form)) {
  185. $commands[] = ajax_command_replace('#ctools-export-ui-list-form', $form);
  186. }
  187. print ajax_render($commands);
  188. ajax_footer();
  189. }
  190. /**
  191. * Create the filter/sort form at the top of a list of exports.
  192. *
  193. * This handles the very default conditions, and most lists are expected
  194. * to override this and call through to parent::list_form() in order to
  195. * get the base form and then modify it as necessary to add search
  196. * gadgets for custom fields.
  197. */
  198. function list_form(&$form, &$form_state) {
  199. // This forces the form to *always* treat as submitted which is
  200. // necessary to make it work.
  201. $form['#token'] = FALSE;
  202. if (empty($form_state['input'])) {
  203. $form["#post"] = TRUE;
  204. }
  205. // Add the 'q' in if we are not using clean URLs or it can get lost when
  206. // using this kind of form.
  207. if (!variable_get('clean_url', FALSE)) {
  208. $form['q'] = array(
  209. '#type' => 'hidden',
  210. '#value' => $_GET['q'],
  211. );
  212. }
  213. $all = array('all' => t('- All -'));
  214. $form['top row'] = array(
  215. '#prefix' => '<div class="ctools-export-ui-row ctools-export-ui-top-row clearfix">',
  216. '#suffix' => '</div>',
  217. );
  218. $form['bottom row'] = array(
  219. '#prefix' => '<div class="ctools-export-ui-row ctools-export-ui-bottom-row clearfix">',
  220. '#suffix' => '</div>',
  221. );
  222. $form['top row']['storage'] = array(
  223. '#type' => 'select',
  224. '#title' => t('Storage'),
  225. '#options' => $all + array(
  226. t('Normal') => t('Normal'),
  227. t('Default') => t('Default'),
  228. t('Overridden') => t('Overridden'),
  229. ),
  230. '#default_value' => 'all',
  231. );
  232. $form['top row']['disabled'] = array(
  233. '#type' => 'select',
  234. '#title' => t('Enabled'),
  235. '#options' => $all + array(
  236. '0' => t('Enabled'),
  237. '1' => t('Disabled')
  238. ),
  239. '#default_value' => 'all',
  240. );
  241. $form['top row']['search'] = array(
  242. '#type' => 'textfield',
  243. '#title' => t('Search'),
  244. );
  245. $form['bottom row']['order'] = array(
  246. '#type' => 'select',
  247. '#title' => t('Sort by'),
  248. '#options' => $this->list_sort_options(),
  249. '#default_value' => 'disabled',
  250. );
  251. $form['bottom row']['sort'] = array(
  252. '#type' => 'select',
  253. '#title' => t('Order'),
  254. '#options' => array(
  255. 'asc' => t('Up'),
  256. 'desc' => t('Down'),
  257. ),
  258. '#default_value' => 'asc',
  259. );
  260. $form['bottom row']['submit'] = array(
  261. '#type' => 'submit',
  262. '#id' => 'ctools-export-ui-list-items-apply',
  263. '#value' => t('Apply'),
  264. '#attributes' => array('class' => array('use-ajax-submit ctools-auto-submit-click')),
  265. );
  266. $form['bottom row']['reset'] = array(
  267. '#type' => 'submit',
  268. '#id' => 'ctools-export-ui-list-items-apply',
  269. '#value' => t('Reset'),
  270. '#attributes' => array('class' => array('use-ajax-submit')),
  271. );
  272. $form['#prefix'] = '<div class="clearfix">';
  273. $form['#suffix'] = '</div>';
  274. $form['#attached']['js'] = array(ctools_attach_js('auto-submit'));
  275. $form['#attached']['library'][] = array('system', 'drupal.ajax');
  276. $form['#attached']['library'][] = array('system', 'jquery.form');
  277. $form['#attributes'] = array('class' => array('ctools-auto-submit-full-form'));
  278. }
  279. /**
  280. * Validate the filter/sort form.
  281. *
  282. * It is very rare that a filter form needs validation, but if it is
  283. * needed, override this.
  284. */
  285. function list_form_validate(&$form, &$form_state) { }
  286. /**
  287. * Submit the filter/sort form.
  288. *
  289. * This submit handler is actually responsible for building up all of the
  290. * rows that will later be rendered, since it is doing the filtering and
  291. * sorting.
  292. *
  293. * For the most part, you should not need to override this method, as the
  294. * fiddly bits call through to other functions.
  295. */
  296. function list_form_submit(&$form, &$form_state) {
  297. // Filter and re-sort the pages.
  298. $plugin = $this->plugin;
  299. $prefix = ctools_export_ui_plugin_base_path($plugin);
  300. foreach ($this->items as $name => $item) {
  301. // Call through to the filter and see if we're going to render this
  302. // row. If it returns TRUE, then this row is filtered out.
  303. if ($this->list_filter($form_state, $item)) {
  304. continue;
  305. }
  306. $operations = $this->build_operations($item);
  307. $this->list_build_row($item, $form_state, $operations);
  308. }
  309. // Now actually sort
  310. if ($form_state['values']['sort'] == 'desc') {
  311. arsort($this->sorts);
  312. }
  313. else {
  314. asort($this->sorts);
  315. }
  316. // Nuke the original.
  317. $rows = $this->rows;
  318. $this->rows = array();
  319. // And restore.
  320. foreach ($this->sorts as $name => $title) {
  321. $this->rows[$name] = $rows[$name];
  322. }
  323. }
  324. /**
  325. * Determine if a row should be filtered out.
  326. *
  327. * This handles the default filters for the export UI list form. If you
  328. * added additional filters in list_form() then this is where you should
  329. * handle them.
  330. *
  331. * @return
  332. * TRUE if the item should be excluded.
  333. */
  334. function list_filter($form_state, $item) {
  335. $schema = ctools_export_get_schema($this->plugin['schema']);
  336. if ($form_state['values']['storage'] != 'all' && $form_state['values']['storage'] != $item->{$schema['export']['export type string']}) {
  337. return TRUE;
  338. }
  339. if ($form_state['values']['disabled'] != 'all' && $form_state['values']['disabled'] != !empty($item->disabled)) {
  340. return TRUE;
  341. }
  342. if ($form_state['values']['search']) {
  343. $search = strtolower($form_state['values']['search']);
  344. foreach ($this->list_search_fields() as $field) {
  345. if (strpos(strtolower($item->$field), $search) !== FALSE) {
  346. $hit = TRUE;
  347. break;
  348. }
  349. }
  350. if (empty($hit)) {
  351. return TRUE;
  352. }
  353. }
  354. }
  355. /**
  356. * Provide a list of fields to test against for the default "search" widget.
  357. *
  358. * This widget will search against whatever fields are configured here. By
  359. * default it will attempt to search against the name, title and description fields.
  360. */
  361. function list_search_fields() {
  362. $fields = array(
  363. $this->plugin['export']['key'],
  364. );
  365. if (!empty($this->plugin['export']['admin_title'])) {
  366. $fields[] = $this->plugin['export']['admin_title'];
  367. }
  368. if (!empty($this->plugin['export']['admin_description'])) {
  369. $fields[] = $this->plugin['export']['admin_description'];
  370. }
  371. return $fields;
  372. }
  373. /**
  374. * Provide a list of sort options.
  375. *
  376. * Override this if you wish to provide more or change how these work.
  377. * The actual handling of the sorting will happen in build_row().
  378. */
  379. function list_sort_options() {
  380. if (!empty($this->plugin['export']['admin_title'])) {
  381. $options = array(
  382. 'disabled' => t('Enabled, title'),
  383. $this->plugin['export']['admin_title'] => t('Title'),
  384. );
  385. }
  386. else {
  387. $options = array(
  388. 'disabled' => t('Enabled, name'),
  389. );
  390. }
  391. $options += array(
  392. 'name' => t('Name'),
  393. 'storage' => t('Storage'),
  394. );
  395. return $options;
  396. }
  397. /**
  398. * Add listing CSS to the page.
  399. *
  400. * Override this if you need custom CSS for your list.
  401. */
  402. function list_css() {
  403. ctools_add_css('export-ui-list');
  404. }
  405. /**
  406. * Builds the operation links for a specific exportable item.
  407. */
  408. function build_operations($item) {
  409. $plugin = $this->plugin;
  410. $schema = ctools_export_get_schema($plugin['schema']);
  411. $operations = $plugin['allowed operations'];
  412. $operations['import'] = FALSE;
  413. if ($item->{$schema['export']['export type string']} == t('Normal')) {
  414. $operations['revert'] = FALSE;
  415. }
  416. elseif ($item->{$schema['export']['export type string']} == t('Overridden')) {
  417. $operations['delete'] = FALSE;
  418. }
  419. else {
  420. $operations['revert'] = FALSE;
  421. $operations['delete'] = FALSE;
  422. }
  423. if (empty($item->disabled)) {
  424. $operations['enable'] = FALSE;
  425. }
  426. else {
  427. $operations['disable'] = FALSE;
  428. }
  429. $allowed_operations = array();
  430. foreach ($operations as $op => $info) {
  431. if (!empty($info)) {
  432. $allowed_operations[$op] = array(
  433. 'title' => $info['title'],
  434. 'href' => ctools_export_ui_plugin_menu_path($plugin, $op, $item->{$this->plugin['export']['key']}),
  435. );
  436. if (!empty($info['ajax'])) {
  437. $allowed_operations[$op]['attributes'] = array('class' => array('use-ajax'));
  438. }
  439. if (!empty($info['token'])) {
  440. $allowed_operations[$op]['query'] = array('token' => drupal_get_token($op));
  441. }
  442. }
  443. }
  444. return $allowed_operations;
  445. }
  446. /**
  447. * Build a row based on the item.
  448. *
  449. * By default all of the rows are placed into a table by the render
  450. * method, so this is building up a row suitable for theme('table').
  451. * This doesn't have to be true if you override both.
  452. */
  453. function list_build_row($item, &$form_state, $operations) {
  454. // Set up sorting
  455. $name = $item->{$this->plugin['export']['key']};
  456. $schema = ctools_export_get_schema($this->plugin['schema']);
  457. // Note: $item->{$schema['export']['export type string']} should have already been set up by export.inc so
  458. // we can use it safely.
  459. switch ($form_state['values']['order']) {
  460. case 'disabled':
  461. $this->sorts[$name] = empty($item->disabled) . $name;
  462. break;
  463. case 'title':
  464. $this->sorts[$name] = $item->{$this->plugin['export']['admin_title']};
  465. break;
  466. case 'name':
  467. $this->sorts[$name] = $name;
  468. break;
  469. case 'storage':
  470. $this->sorts[$name] = $item->{$schema['export']['export type string']} . $name;
  471. break;
  472. }
  473. $this->rows[$name]['data'] = array();
  474. $this->rows[$name]['class'] = !empty($item->disabled) ? array('ctools-export-ui-disabled') : array('ctools-export-ui-enabled');
  475. // If we have an admin title, make it the first row.
  476. if (!empty($this->plugin['export']['admin_title'])) {
  477. $this->rows[$name]['data'][] = array('data' => check_plain($item->{$this->plugin['export']['admin_title']}), 'class' => array('ctools-export-ui-title'));
  478. }
  479. $this->rows[$name]['data'][] = array('data' => check_plain($name), 'class' => array('ctools-export-ui-name'));
  480. $this->rows[$name]['data'][] = array('data' => check_plain($item->{$schema['export']['export type string']}), 'class' => array('ctools-export-ui-storage'));
  481. $ops = theme('links__ctools_dropbutton', array('links' => $operations, 'attributes' => array('class' => array('links', 'inline'))));
  482. $this->rows[$name]['data'][] = array('data' => $ops, 'class' => array('ctools-export-ui-operations'));
  483. // Add an automatic mouseover of the description if one exists.
  484. if (!empty($this->plugin['export']['admin_description'])) {
  485. $this->rows[$name]['title'] = $item->{$this->plugin['export']['admin_description']};
  486. }
  487. }
  488. /**
  489. * Provide the table header.
  490. *
  491. * If you've added columns via list_build_row() but are still using a
  492. * table, override this method to set up the table header.
  493. */
  494. function list_table_header() {
  495. $header = array();
  496. if (!empty($this->plugin['export']['admin_title'])) {
  497. $header[] = array('data' => t('Title'), 'class' => array('ctools-export-ui-title'));
  498. }
  499. $header[] = array('data' => t('Name'), 'class' => array('ctools-export-ui-name'));
  500. $header[] = array('data' => t('Storage'), 'class' => array('ctools-export-ui-storage'));
  501. $header[] = array('data' => t('Operations'), 'class' => array('ctools-export-ui-operations'));
  502. return $header;
  503. }
  504. /**
  505. * Render all of the rows together.
  506. *
  507. * By default we place all of the rows in a table, and this should be the
  508. * way most lists will go.
  509. *
  510. * Whatever you do if this method is overridden, the ID is important for AJAX
  511. * so be sure it exists.
  512. */
  513. function list_render(&$form_state) {
  514. $table = array(
  515. 'header' => $this->list_table_header(),
  516. 'rows' => $this->rows,
  517. 'attributes' => array('id' => 'ctools-export-ui-list-items'),
  518. 'empty' => $this->plugin['strings']['message']['no items'],
  519. );
  520. return theme('table', $table);
  521. }
  522. /**
  523. * Render a header to go before the list.
  524. *
  525. * This will appear after the filter/sort widgets.
  526. */
  527. function list_header($form_state) { }
  528. /**
  529. * Render a footer to go after thie list.
  530. *
  531. * This is a good place to add additional links.
  532. */
  533. function list_footer($form_state) { }
  534. // ------------------------------------------------------------------------
  535. // These methods are the API for adding/editing exportable items
  536. /**
  537. * Perform a drupal_goto() to the location provided by the plugin for the
  538. * operation.
  539. *
  540. * @param $op
  541. * The operation to use. A string must exist in $this->plugin['redirect']
  542. * for this operation.
  543. * @param $item
  544. * The item in use; this may be necessary as item IDs are often embedded in
  545. * redirects.
  546. */
  547. function redirect($op, $item = NULL) {
  548. if (isset($this->plugin['redirect'][$op])) {
  549. $destination = (array) $this->plugin['redirect'][$op];
  550. if ($item) {
  551. $export_key = $this->plugin['export']['key'];
  552. $destination[0] = str_replace('%ctools_export_ui', $item->{$export_key}, $destination[0]);
  553. }
  554. call_user_func_array('drupal_goto', $destination);
  555. }
  556. else {
  557. // If the operation isn't set, fall back to the plugin's base path.
  558. drupal_goto(ctools_export_ui_plugin_base_path($this->plugin));
  559. }
  560. }
  561. function add_page($js, $input, $step = NULL) {
  562. drupal_set_title($this->get_page_title('add'));
  563. // If a step not set, they are trying to create a new item. If a step
  564. // is set, they're in the process of creating an item.
  565. if (!empty($this->plugin['use wizard']) && !empty($step)) {
  566. $item = $this->edit_cache_get(NULL, 'add');
  567. }
  568. if (empty($item)) {
  569. $item = ctools_export_crud_new($this->plugin['schema']);
  570. }
  571. $form_state = array(
  572. 'plugin' => $this->plugin,
  573. 'object' => &$this,
  574. 'ajax' => $js,
  575. 'item' => $item,
  576. 'op' => 'add',
  577. 'form type' => 'add',
  578. 'rerender' => TRUE,
  579. 'no_redirect' => TRUE,
  580. 'step' => $step,
  581. // Store these in case additional args are needed.
  582. 'function args' => func_get_args(),
  583. );
  584. $output = $this->edit_execute_form($form_state);
  585. if (!empty($form_state['executed']) && empty($form_state['rebuild'])) {
  586. $this->redirect($form_state['op'], $form_state['item']);
  587. }
  588. return $output;
  589. }
  590. /**
  591. * Main entry point to edit an item.
  592. */
  593. function edit_page($js, $input, $item, $step = NULL) {
  594. drupal_set_title($this->get_page_title('edit', $item));
  595. // Check to see if there is a cached item to get if we're using the wizard.
  596. if (!empty($this->plugin['use wizard'])) {
  597. $cached = $this->edit_cache_get($item, 'edit');
  598. if (!empty($cached)) {
  599. $item = $cached;
  600. }
  601. }
  602. $form_state = array(
  603. 'plugin' => $this->plugin,
  604. 'object' => &$this,
  605. 'ajax' => $js,
  606. 'item' => $item,
  607. 'op' => 'edit',
  608. 'form type' => 'edit',
  609. 'rerender' => TRUE,
  610. 'no_redirect' => TRUE,
  611. 'step' => $step,
  612. // Store these in case additional args are needed.
  613. 'function args' => func_get_args(),
  614. );
  615. $output = $this->edit_execute_form($form_state);
  616. if (!empty($form_state['executed']) && empty($form_state['rebuild'])) {
  617. $this->redirect($form_state['op'], $form_state['item']);
  618. }
  619. return $output;
  620. }
  621. /**
  622. * Main entry point to clone an item.
  623. */
  624. function clone_page($js, $input, $original, $step = NULL) {
  625. drupal_set_title($this->get_page_title('clone', $original));
  626. // If a step not set, they are trying to create a new clone. If a step
  627. // is set, they're in the process of cloning an item.
  628. if (!empty($this->plugin['use wizard']) && !empty($step)) {
  629. $item = $this->edit_cache_get(NULL, 'clone');
  630. }
  631. if (empty($item)) {
  632. // To make a clone of an item, we first export it and then re-import it.
  633. // Export the handler, which is a fantastic way to clean database IDs out of it.
  634. $export = ctools_export_crud_export($this->plugin['schema'], $original);
  635. $item = ctools_export_crud_import($this->plugin['schema'], $export);
  636. $item->{$this->plugin['export']['key']} = 'clone_of_' . $item->{$this->plugin['export']['key']};
  637. }
  638. // Tabs and breadcrumb disappearing, this helps alleviate through cheating.
  639. // ...not sure this this is the best way.
  640. $trail = menu_set_active_item(ctools_export_ui_plugin_base_path($this->plugin));
  641. $name = $original->{$this->plugin['export']['key']};
  642. $form_state = array(
  643. 'plugin' => $this->plugin,
  644. 'object' => &$this,
  645. 'ajax' => $js,
  646. 'item' => $item,
  647. 'op' => 'add',
  648. 'form type' => 'clone',
  649. 'original name' => $name,
  650. 'rerender' => TRUE,
  651. 'no_redirect' => TRUE,
  652. 'step' => $step,
  653. // Store these in case additional args are needed.
  654. 'function args' => func_get_args(),
  655. );
  656. $output = $this->edit_execute_form($form_state);
  657. if (!empty($form_state['executed']) && empty($form_state['rebuild'])) {
  658. $this->redirect($form_state['op'], $form_state['item']);
  659. }
  660. return $output;
  661. }
  662. /**
  663. * Execute the form.
  664. *
  665. * Add and Edit both funnel into this, but they have a few different
  666. * settings.
  667. */
  668. function edit_execute_form(&$form_state) {
  669. if (!empty($this->plugin['use wizard'])) {
  670. return $this->edit_execute_form_wizard($form_state);
  671. }
  672. else {
  673. return $this->edit_execute_form_standard($form_state);
  674. }
  675. }
  676. /**
  677. * Execute the standard form for editing.
  678. *
  679. * By default, export UI will provide a single form for editing an object.
  680. */
  681. function edit_execute_form_standard(&$form_state) {
  682. $output = drupal_build_form('ctools_export_ui_edit_item_form', $form_state);
  683. if (!empty($form_state['executed']) && empty($form_state['rebuild'])) {
  684. $this->edit_save_form($form_state);
  685. }
  686. return $output;
  687. }
  688. /**
  689. * Get the form info for the wizard.
  690. *
  691. * This gets the form info out of the plugin, then adds defaults based on
  692. * how we want edit forms to work.
  693. *
  694. * Overriding this can allow child UIs to tweak this info for specialized
  695. * wizards.
  696. *
  697. * @param array $form_state
  698. * The already created form state.
  699. */
  700. function get_wizard_info(&$form_state) {
  701. if (!isset($form_state['step'])) {
  702. $form_state['step'] = NULL;
  703. }
  704. $export_key = $this->plugin['export']['key'];
  705. // When cloning, the name of the item being cloned is referenced in the
  706. // path, not the name of this item.
  707. if ($form_state['form type'] == 'clone') {
  708. $name = $form_state['original name'];
  709. }
  710. else {
  711. $name = $form_state['item']->{$export_key};
  712. }
  713. $form_info = !empty($this->plugin['form info']) ? $this->plugin['form info'] : array();
  714. $form_info += array(
  715. 'id' => 'ctools_export_ui_edit',
  716. 'path' => ctools_export_ui_plugin_menu_path($this->plugin, $form_state['form type'], $name) . '/%step',
  717. 'show trail' => TRUE,
  718. 'free trail' => TRUE,
  719. 'show back' => $form_state['form type'] == 'add',
  720. 'show return' => FALSE,
  721. 'show cancel' => TRUE,
  722. 'finish callback' => 'ctools_export_ui_wizard_finish',
  723. 'next callback' => 'ctools_export_ui_wizard_next',
  724. 'back callback' => 'ctools_export_ui_wizard_back',
  725. 'cancel callback' => 'ctools_export_ui_wizard_cancel',
  726. 'order' => array(),
  727. 'import order' => array(
  728. 'import' => t('Import code'),
  729. 'settings' => t('Settings'),
  730. ),
  731. );
  732. // Set the order of forms based on the op if we have a specific one.
  733. if (isset($form_info[$form_state['form type'] . ' order'])) {
  734. $form_info['order'] = $form_info[$form_state['form type'] . ' order'];
  735. }
  736. // We have generic fallback forms we can use if they are not specified,
  737. // and they automatically delegate back to the UI object. Use these if
  738. // not specified.
  739. foreach ($form_info['order'] as $key => $title) {
  740. if (empty($form_info['forms'][$key])) {
  741. $form_info['forms'][$key] = array(
  742. 'form id' => 'ctools_export_ui_edit_item_wizard_form',
  743. );
  744. }
  745. }
  746. // 'free trail' means the wizard can freely go back and form from item
  747. // via the trail and not with next/back buttons.
  748. if ($form_state['form type'] == 'add' || ($form_state['form type'] == 'import' && empty($form_state['item']->{$export_key}))) {
  749. $form_info['free trail'] = FALSE;
  750. }
  751. return $form_info;
  752. }
  753. /**
  754. * Execute the wizard for editing.
  755. *
  756. * For complex objects, sometimes a wizard is needed. This is normally
  757. * activated by setting 'use wizard' => TRUE in the plugin definition
  758. * and then creating a 'form info' array to feed the wizard the data
  759. * it needs.
  760. *
  761. * When creating this wizard, the plugin is responsible for defining all forms
  762. * that will be utilized with the wizard.
  763. *
  764. * Using 'add order' or 'edit order' can be used to ensure that add/edit order
  765. * is different.
  766. */
  767. function edit_execute_form_wizard(&$form_state) {
  768. $form_info = $this->get_wizard_info($form_state);
  769. // If there aren't any forms set, fail.
  770. if (empty($form_info['order'])) {
  771. return MENU_NOT_FOUND;
  772. }
  773. // Figure out if this is a new instance of the wizard
  774. if (empty($form_state['step'])) {
  775. $order = array_keys($form_info['order']);
  776. $form_state['step'] = reset($order);
  777. }
  778. if (empty($form_info['order'][$form_state['step']]) && empty($form_info['forms'][$form_state['step']])) {
  779. return MENU_NOT_FOUND;
  780. }
  781. ctools_include('wizard');
  782. $output = ctools_wizard_multistep_form($form_info, $form_state['step'], $form_state);
  783. if (!empty($form_state['complete'])) {
  784. $this->edit_save_form($form_state);
  785. }
  786. else if ($output && !empty($form_state['item']->export_ui_item_is_cached)) {
  787. // @todo this should be in the plugin strings
  788. drupal_set_message(t('You have unsaved changes. These changes will not be made permanent until you click <em>Save</em>.'), 'warning');
  789. }
  790. // Unset the executed flag if any non-wizard button was pressed. Those
  791. // buttons require special handling by whatever client is operating them.
  792. if (!empty($form_state['executed']) && empty($form_state['clicked_button']['#wizard type'])) {
  793. unset($form_state['executed']);
  794. }
  795. return $output;
  796. }
  797. /**
  798. * Wizard 'back' callback when using a wizard to edit an item.
  799. *
  800. * The wizard callback delegates this back to the object.
  801. */
  802. function edit_wizard_back(&$form_state) {
  803. // This only exists so child implementations can use it.
  804. }
  805. /**
  806. * Wizard 'next' callback when using a wizard to edit an item.
  807. *
  808. * The wizard callback delegates this back to the object.
  809. */
  810. function edit_wizard_next(&$form_state) {
  811. $this->edit_cache_set($form_state['item'], $form_state['form type']);
  812. }
  813. /**
  814. * Wizard 'cancel' callback when using a wizard to edit an item.
  815. *
  816. * The wizard callback delegates this back to the object.
  817. */
  818. function edit_wizard_cancel(&$form_state) {
  819. $this->edit_cache_clear($form_state['item'], $form_state['form type']);
  820. }
  821. /**
  822. * Wizard 'cancel' callback when using a wizard to edit an item.
  823. *
  824. * The wizard callback delegates this back to the object.
  825. */
  826. function edit_wizard_finish(&$form_state) {
  827. $form_state['complete'] = TRUE;
  828. // If we are importing, and overwrite was selected, delete the original so
  829. // that this one writes properly.
  830. if ($form_state['form type'] == 'import' && !empty($form_state['item']->export_ui_allow_overwrite)) {
  831. ctools_export_crud_delete($this->plugin['schema'], $form_state['item']);
  832. }
  833. $this->edit_cache_clear($form_state['item'], $form_state['form type']);
  834. }
  835. /**
  836. * Retrieve the item currently being edited from the object cache.
  837. */
  838. function edit_cache_get($item, $op = 'edit') {
  839. ctools_include('object-cache');
  840. if (is_string($item)) {
  841. $name = $item;
  842. }
  843. else {
  844. $name = $this->edit_cache_get_key($item, $op);
  845. }
  846. $cache = ctools_object_cache_get('ctui_' . $this->plugin['name'], $name);
  847. if ($cache) {
  848. $cache->export_ui_item_is_cached = TRUE;
  849. return $cache;
  850. }
  851. }
  852. /**
  853. * Cache the item currently currently being edited.
  854. */
  855. function edit_cache_set($item, $op = 'edit') {
  856. ctools_include('object-cache');
  857. $name = $this->edit_cache_get_key($item, $op);
  858. return $this->edit_cache_set_key($item, $name);
  859. }
  860. function edit_cache_set_key($item, $name) {
  861. return ctools_object_cache_set('ctui_' . $this->plugin['name'], $name, $item);
  862. }
  863. /**
  864. * Clear the object cache for the currently edited item.
  865. */
  866. function edit_cache_clear($item, $op = 'edit') {
  867. ctools_include('object-cache');
  868. $name = $this->edit_cache_get_key($item, $op);
  869. return ctools_object_cache_clear('ctui_' . $this->plugin['name'], $name);
  870. }
  871. /**
  872. * Figure out what the cache key is for this object.
  873. */
  874. function edit_cache_get_key($item, $op) {
  875. $export_key = $this->plugin['export']['key'];
  876. return $op == 'edit' ? $item->{$this->plugin['export']['key']} : "::$op";
  877. }
  878. /**
  879. * Called to save the final product from the edit form.
  880. */
  881. function edit_save_form($form_state) {
  882. $item = &$form_state['item'];
  883. $export_key = $this->plugin['export']['key'];
  884. $result = ctools_export_crud_save($this->plugin['schema'], $item);
  885. if ($result) {
  886. $message = str_replace('%title', check_plain($item->{$export_key}), $this->plugin['strings']['confirmation'][$form_state['op']]['success']);
  887. drupal_set_message($message);
  888. }
  889. else {
  890. $message = str_replace('%title', check_plain($item->{$export_key}), $this->plugin['strings']['confirmation'][$form_state['op']]['fail']);
  891. drupal_set_message($message, 'error');
  892. }
  893. }
  894. /**
  895. * Provide the actual editing form.
  896. */
  897. function edit_form(&$form, &$form_state) {
  898. $export_key = $this->plugin['export']['key'];
  899. $item = $form_state['item'];
  900. $schema = ctools_export_get_schema($this->plugin['schema']);
  901. if (!empty($this->plugin['export']['admin_title'])) {
  902. $form['info'][$this->plugin['export']['admin_title']] = array(
  903. '#type' => 'textfield',
  904. '#title' => t('Administrative title'),
  905. '#description' => t('This will appear in the administrative interface to easily identify it.'),
  906. '#default_value' => $item->{$this->plugin['export']['admin_title']},
  907. );
  908. }
  909. $form['info'][$export_key] = array(
  910. '#title' => t($schema['export']['key name']),
  911. '#type' => 'textfield',
  912. '#default_value' => $item->{$export_key},
  913. '#description' => t('The unique ID for this @export.', array('@export' => $this->plugin['title singular'])),
  914. '#required' => TRUE,
  915. '#maxlength' => 255,
  916. );
  917. if (!empty($this->plugin['export']['admin_title'])) {
  918. $form['info'][$export_key]['#type'] = 'machine_name';
  919. $form['info'][$export_key]['#machine_name'] = array(
  920. 'exists' => 'ctools_export_ui_edit_name_exists',
  921. 'source' => array('info', $this->plugin['export']['admin_title']),
  922. );
  923. }
  924. if ($form_state['op'] === 'edit') {
  925. $form['info'][$export_key]['#disabled'] = TRUE;
  926. $form['info'][$export_key]['#value'] = $item->{$export_key};
  927. }
  928. if (!empty($this->plugin['export']['admin_description'])) {
  929. $form['info'][$this->plugin['export']['admin_description']] = array(
  930. '#type' => 'textarea',
  931. '#title' => t('Administrative description'),
  932. '#default_value' => $item->{$this->plugin['export']['admin_description']},
  933. );
  934. }
  935. // Add plugin's form definitions.
  936. if (!empty($this->plugin['form']['settings'])) {
  937. // Pass $form by reference.
  938. $this->plugin['form']['settings']($form, $form_state);
  939. }
  940. // Add the buttons if the wizard is not in use.
  941. if (empty($form_state['form_info'])) {
  942. // Make sure that whatever happens, the buttons go to the bottom.
  943. $form['buttons']['#weight'] = 100;
  944. // Add buttons.
  945. $form['buttons']['submit'] = array(
  946. '#type' => 'submit',
  947. '#value' => t('Save'),
  948. );
  949. $form['buttons']['delete'] = array(
  950. '#type' => 'submit',
  951. '#value' => $item->export_type & EXPORT_IN_CODE ? t('Revert') : t('Delete'),
  952. '#access' => $form_state['op'] === 'edit' && $item->export_type & EXPORT_IN_DATABASE,
  953. '#submit' => array('ctools_export_ui_edit_item_form_delete'),
  954. );
  955. }
  956. }
  957. /**
  958. * Validate callback for the edit form.
  959. */
  960. function edit_form_validate(&$form, &$form_state) {
  961. if (!empty($this->plugin['form']['validate'])) {
  962. // Pass $form by reference.
  963. $this->plugin['form']['validate']($form, $form_state);
  964. }
  965. }
  966. /**
  967. * Perform a final validation check before allowing the form to be
  968. * finished.
  969. */
  970. function edit_finish_validate(&$form, &$form_state) {
  971. if ($form_state['op'] != 'edit') {
  972. // Validate the export key. Fake an element for form_error().
  973. $export_key = $this->plugin['export']['key'];
  974. $element = array(
  975. '#value' => $form_state['item']->{$export_key},
  976. '#parents' => array($export_key),
  977. );
  978. $form_state['plugin'] = $this->plugin;
  979. ctools_export_ui_edit_name_validate($element, $form_state);
  980. }
  981. }
  982. /**
  983. * Handle the submission of the edit form.
  984. *
  985. * At this point, submission is successful. Our only responsibility is
  986. * to copy anything out of values onto the item that we are able to edit.
  987. *
  988. * If the keys all match up to the schema, this method will not need to be
  989. * overridden.
  990. */
  991. function edit_form_submit(&$form, &$form_state) {
  992. if (!empty($this->plugin['form']['submit'])) {
  993. // Pass $form by reference.
  994. $this->plugin['form']['submit']($form, $form_state);
  995. }
  996. // Transfer data from the form to the $item based upon schema values.
  997. $schema = ctools_export_get_schema($this->plugin['schema']);
  998. foreach (array_keys($schema['fields']) as $key) {
  999. if(isset($form_state['values'][$key])) {
  1000. $form_state['item']->{$key} = $form_state['values'][$key];
  1001. }
  1002. }
  1003. }
  1004. // ------------------------------------------------------------------------
  1005. // These methods are the API for 'other' stuff with exportables such as
  1006. // enable, disable, import, export, delete
  1007. /**
  1008. * Callback to enable a page.
  1009. */
  1010. function enable_page($js, $input, $item) {
  1011. return $this->set_item_state(FALSE, $js, $input, $item);
  1012. }
  1013. /**
  1014. * Callback to disable a page.
  1015. */
  1016. function disable_page($js, $input, $item) {
  1017. return $this->set_item_state(TRUE, $js, $input, $item);
  1018. }
  1019. /**
  1020. * Set an item's state to enabled or disabled and output to user.
  1021. *
  1022. * If javascript is in use, this will rebuild the list and send that back
  1023. * as though the filter form had been executed.
  1024. */
  1025. function set_item_state($state, $js, $input, $item) {
  1026. ctools_export_crud_set_status($this->plugin['schema'], $item, $state);
  1027. if (!$js) {
  1028. drupal_goto(ctools_export_ui_plugin_base_path($this->plugin));
  1029. }
  1030. else {
  1031. return $this->list_page($js, $input);
  1032. }
  1033. }
  1034. /**
  1035. * Page callback to delete an exportable item.
  1036. */
  1037. function delete_page($js, $input, $item) {
  1038. $form_state = array(
  1039. 'plugin' => $this->plugin,
  1040. 'object' => &$this,
  1041. 'ajax' => $js,
  1042. 'item' => $item,
  1043. 'op' => $item->export_type & EXPORT_IN_CODE ? 'revert' : 'delete',
  1044. 'rerender' => TRUE,
  1045. 'no_redirect' => TRUE,
  1046. );
  1047. $output = drupal_build_form('ctools_export_ui_delete_confirm_form', $form_state);
  1048. if (!empty($form_state['executed'])) {
  1049. $this->delete_form_submit($form_state);
  1050. $this->redirect($form_state['op'], $item);
  1051. }
  1052. return $output;
  1053. }
  1054. /**
  1055. * Deletes exportable items from the database.
  1056. */
  1057. function delete_form_submit(&$form_state) {
  1058. $item = $form_state['item'];
  1059. ctools_export_crud_delete($this->plugin['schema'], $item);
  1060. $export_key = $this->plugin['export']['key'];
  1061. $message = str_replace('%title', check_plain($item->{$export_key}), $this->plugin['strings']['confirmation'][$form_state['op']]['success']);
  1062. drupal_set_message($message);
  1063. }
  1064. /**
  1065. * Page callback to display export information for an exportable item.
  1066. */
  1067. function export_page($js, $input, $item) {
  1068. drupal_set_title($this->get_page_title('export', $item));
  1069. return drupal_get_form('ctools_export_form', ctools_export_crud_export($this->plugin['schema'], $item), t('Export'));
  1070. }
  1071. /**
  1072. * Page callback to import information for an exportable item.
  1073. */
  1074. function import_page($js, $input, $step = NULL) {
  1075. drupal_set_title($this->get_page_title('import'));
  1076. // Import is basically a multi step wizard form, so let's go ahead and
  1077. // use CTools' wizard.inc for it.
  1078. // If a step not set, they are trying to create a new item. If a step
  1079. // is set, they're in the process of creating an item.
  1080. if (!empty($step)) {
  1081. $item = $this->edit_cache_get(NULL, 'import');
  1082. }
  1083. if (empty($item)) {
  1084. $item = ctools_export_crud_new($this->plugin['schema']);
  1085. }
  1086. $form_state = array(
  1087. 'plugin' => $this->plugin,
  1088. 'object' => &$this,
  1089. 'ajax' => $js,
  1090. 'item' => $item,
  1091. 'op' => 'add',
  1092. 'form type' => 'import',
  1093. 'rerender' => TRUE,
  1094. 'no_redirect' => TRUE,
  1095. 'step' => $step,
  1096. // Store these in case additional args are needed.
  1097. 'function args' => func_get_args(),
  1098. );
  1099. // import always uses the wizard.
  1100. $output = $this->edit_execute_form_wizard($form_state);
  1101. if (!empty($form_state['executed'])) {
  1102. $this->redirect($form_state['op'], $form_state['item']);
  1103. }
  1104. return $output;
  1105. }
  1106. /**
  1107. * Import form. Provides simple helptext instructions and textarea for
  1108. * pasting a export definition.
  1109. */
  1110. function edit_form_import(&$form, &$form_state) {
  1111. $form['help'] = array(
  1112. '#type' => 'item',
  1113. '#value' => $this->plugin['strings']['help']['import'],
  1114. );
  1115. $form['import'] = array(
  1116. '#title' => t('@plugin code', array('@plugin' => $this->plugin['title singular proper'])),
  1117. '#type' => 'textarea',
  1118. '#rows' => 10,
  1119. '#required' => TRUE,
  1120. '#default_value' => !empty($form_state['item']->export_ui_code) ? $form_state['item']->export_ui_code : '',
  1121. );
  1122. $form['overwrite'] = array(
  1123. '#title' => t('Allow import to overwrite an existing record.'),
  1124. '#type' => 'checkbox',
  1125. '#default_value' => !empty($form_state['item']->export_ui_allow_overwrite) ? $form_state['item']->export_ui_allow_overwrite : FALSE,
  1126. );
  1127. }
  1128. /**
  1129. * Import form validate handler.
  1130. *
  1131. * Evaluates code and make sure it creates an object before we continue.
  1132. */
  1133. function edit_form_import_validate($form, &$form_state) {
  1134. $item = ctools_export_crud_import($this->plugin['schema'], $form_state['values']['import']);
  1135. if (is_string($item)) {
  1136. form_error($form['import'], t('Unable to get an import from the code. Errors reported: @errors', array('@errors' => $item)));
  1137. return;
  1138. }
  1139. $form_state['item'] = $item;
  1140. $form_state['item']->export_ui_allow_overwrite = $form_state['values']['overwrite'];
  1141. $form_state['item']->export_ui_code = $form_state['values']['import'];
  1142. }
  1143. /**
  1144. * Submit callback for import form.
  1145. *
  1146. * Stores the item in the session.
  1147. */
  1148. function edit_form_import_submit($form, &$form_state) {
  1149. // The validate function already imported and stored the item. This
  1150. // function exists simply to prevent it from going to the default
  1151. // edit_form_submit() method.
  1152. }
  1153. }
  1154. // -----------------------------------------------------------------------
  1155. // Forms to be used with this class.
  1156. //
  1157. // Since Drupal's forms are completely procedural, these forms will
  1158. // mostly just be pass-throughs back to the object.
  1159. /**
  1160. * Add all appropriate includes to forms so that caching the form
  1161. * still loads the files that we need.
  1162. */
  1163. function _ctools_export_ui_add_form_files($form, &$form_state) {
  1164. ctools_form_include($form_state, 'export');
  1165. ctools_form_include($form_state, 'export-ui');
  1166. // Also make sure the plugin .inc file is loaded.
  1167. ctools_form_include_file($form_state, $form_state['object']->plugin['path'] . '/' . $form_state['object']->plugin['file']);
  1168. }
  1169. /**
  1170. * Form callback to handle the filter/sort form when listing items.
  1171. *
  1172. * This simply loads the object defined in the plugin and hands it off.
  1173. */
  1174. function ctools_export_ui_list_form($form, $form_state) {
  1175. $form_state['object']->list_form($form, $form_state);
  1176. return $form;
  1177. }
  1178. /**
  1179. * Validate handler for ctools_export_ui_list_form.
  1180. */
  1181. function ctools_export_ui_list_form_validate(&$form, &$form_state) {
  1182. $form_state['object']->list_form_validate($form, $form_state);
  1183. }
  1184. /**
  1185. * Submit handler for ctools_export_ui_list_form.
  1186. */
  1187. function ctools_export_ui_list_form_submit(&$form, &$form_state) {
  1188. $form_state['object']->list_form_submit($form, $form_state);
  1189. }
  1190. /**
  1191. * Form callback to edit an exportable item.
  1192. *
  1193. * This simply loads the object defined in the plugin and hands it off.
  1194. */
  1195. function ctools_export_ui_edit_item_form($form, &$form_state) {
  1196. // When called using #ajax via ajax_form_callback(), 'export' may
  1197. // not be included so include it here.
  1198. _ctools_export_ui_add_form_files($form, $form_state);
  1199. $form_state['object']->edit_form($form, $form_state);
  1200. return $form;
  1201. }
  1202. /**
  1203. * Validate handler for ctools_export_ui_edit_item_form.
  1204. */
  1205. function ctools_export_ui_edit_item_form_validate(&$form, &$form_state) {
  1206. $form_state['object']->edit_form_validate($form, $form_state);
  1207. }
  1208. /**
  1209. * Submit handler for ctools_export_ui_edit_item_form.
  1210. */
  1211. function ctools_export_ui_edit_item_form_submit(&$form, &$form_state) {
  1212. $form_state['object']->edit_form_submit($form, $form_state);
  1213. }
  1214. /**
  1215. * Submit handler to delete for ctools_export_ui_edit_item_form
  1216. *
  1217. * @todo Put this on a callback in the object.
  1218. */
  1219. function ctools_export_ui_edit_item_form_delete(&$form, &$form_state) {
  1220. _ctools_export_ui_add_form_files($form, $form_state);
  1221. $export_key = $form_state['plugin']['export']['key'];
  1222. $path = $form_state['item']->export_type & EXPORT_IN_CODE ? 'revert' : 'delete';
  1223. drupal_goto(ctools_export_ui_plugin_menu_path($form_state['plugin'], $path, $form_state['item']->{$export_key}), array('cancel_path' => $_GET['q']));
  1224. }
  1225. /**
  1226. * Validate that an export item name is acceptable and unique during add.
  1227. */
  1228. function ctools_export_ui_edit_name_validate($element, &$form_state) {
  1229. $plugin = $form_state['plugin'];
  1230. // Check for string identifier sanity
  1231. if (!preg_match('!^[a-z0-9_]+$!', $element['#value'])) {
  1232. form_error($element, t('The export id can only consist of lowercase letters, underscores, and numbers.'));
  1233. return;
  1234. }
  1235. // Check for name collision
  1236. if (empty($form_state['item']->export_ui_allow_overwrite) && $exists = ctools_export_crud_load($plugin['schema'], $element['#value'])) {
  1237. form_error($element, t('A @plugin with this name already exists. Please choose another name or delete the existing item before creating a new one.', array('@plugin' => $plugin['title singular'])));
  1238. }
  1239. }
  1240. /**
  1241. * Test for #machine_name type to see if an export exists.
  1242. */
  1243. function ctools_export_ui_edit_name_exists($name, $element, &$form_state) {
  1244. $plugin = $form_state['plugin'];
  1245. return (empty($form_state['item']->export_ui_allow_overwrite) && ctools_export_crud_load($plugin['schema'], $name));
  1246. }
  1247. /**
  1248. * Delete/Revert confirm form.
  1249. *
  1250. * @todo -- call back into the object instead.
  1251. */
  1252. function ctools_export_ui_delete_confirm_form($form, &$form_state) {
  1253. _ctools_export_ui_add_form_files($form, $form_state);
  1254. $plugin = $form_state['plugin'];
  1255. $item = $form_state['item'];
  1256. $form = array();
  1257. $export_key = $plugin['export']['key'];
  1258. $question = str_replace('%title', check_plain($item->{$export_key}), $plugin['strings']['confirmation'][$form_state['op']]['question']);
  1259. $path = empty($_REQUEST['cancel_path']) ? ctools_export_ui_plugin_base_path($plugin) : $_REQUEST['cancel_path'];
  1260. $form = confirm_form($form,
  1261. $question,
  1262. $path,
  1263. $plugin['strings']['confirmation'][$form_state['op']]['information'],
  1264. $plugin['allowed operations'][$form_state['op']]['title'], t('Cancel')
  1265. );
  1266. return $form;
  1267. }
  1268. // --------------------------------------------------------------------------
  1269. // Forms and callbacks for using the edit system with the wizard.
  1270. /**
  1271. * Form callback to edit an exportable item using the wizard
  1272. *
  1273. * This simply loads the object defined in the plugin and hands it off.
  1274. */
  1275. function ctools_export_ui_edit_item_wizard_form($form, &$form_state) {
  1276. _ctools_export_ui_add_form_files($form, $form_state);
  1277. $method = 'edit_form_' . $form_state['step'];
  1278. if (!method_exists($form_state['object'], $method)) {
  1279. $method = 'edit_form';
  1280. }
  1281. $form_state['object']->$method($form, $form_state);
  1282. return $form;
  1283. }
  1284. /**
  1285. * Validate handler for ctools_export_ui_edit_item_wizard_form.
  1286. */
  1287. function ctools_export_ui_edit_item_wizard_form_validate(&$form, &$form_state) {
  1288. $method = 'edit_form_' . $form_state['step'] . '_validate';
  1289. if (!method_exists($form_state['object'], $method)) {
  1290. $method = 'edit_form_validate';
  1291. }
  1292. $form_state['object']->$method($form, $form_state);
  1293. // Additionally, if there were no errors from that, and we're finishing,
  1294. // perform a final validate to make sure everything is ok.
  1295. if (isset($form_state['clicked_button']['#wizard type']) && $form_state['clicked_button']['#wizard type'] == 'finish' && !form_get_errors()) {
  1296. $form_state['object']->edit_finish_validate($form, $form_state);
  1297. }
  1298. }
  1299. /**
  1300. * Submit handler for ctools_export_ui_edit_item_wizard_form.
  1301. */
  1302. function ctools_export_ui_edit_item_wizard_form_submit(&$form, &$form_state) {
  1303. $method = 'edit_form_' . $form_state['step'] . '_submit';
  1304. if (!method_exists($form_state['object'], $method)) {
  1305. $method = 'edit_form_submit';
  1306. }
  1307. $form_state['object']->$method($form, $form_state);
  1308. }
  1309. /**
  1310. * Wizard 'back' callback when using a wizard to edit an item.
  1311. */
  1312. function ctools_export_ui_wizard_back(&$form_state) {
  1313. $form_state['object']->edit_wizard_back($form_state);
  1314. }
  1315. /**
  1316. * Wizard 'next' callback when using a wizard to edit an item.
  1317. */
  1318. function ctools_export_ui_wizard_next(&$form_state) {
  1319. $form_state['object']->edit_wizard_next($form_state);
  1320. }
  1321. /**
  1322. * Wizard 'cancel' callback when using a wizard to edit an item.
  1323. */
  1324. function ctools_export_ui_wizard_cancel(&$form_state) {
  1325. $form_state['object']->edit_wizard_cancel($form_state);
  1326. }
  1327. /**
  1328. * Wizard 'finish' callback when using a wizard to edit an item.
  1329. */
  1330. function ctools_export_ui_wizard_finish(&$form_state) {
  1331. $form_state['object']->edit_wizard_finish($form_state);
  1332. }
Error | ELMSLN API

Error

×

Error message

  • Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/elmsln_community/api.elmsln.org/includes/common.inc:2791) in drupal_send_headers() (line 1499 of /var/www/html/elmsln_community/api.elmsln.org/includes/bootstrap.inc).
  • Error: Call to undefined function apc_delete() in DrupalAPCCache->clear() (line 289 of /var/www/html/elmsln_community/api.elmsln.org/sites/all/modules/apc/drupal_apc_cache.inc).
The website encountered an unexpected error. Please try again later.