tripal_views_integration_port.inc 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. /**
  3. * @file
  4. * This file contains the UI to import/export tripal views integration setups
  5. * between sites
  6. */
  7. /**
  8. * The form to export a particular tripal views integration
  9. */
  10. function tripal_views_integration_export_form($form_state, $setup_id) {
  11. $form = array();
  12. $defn_array = tripal_views_integration_export_entry($setup_id);
  13. $form['export'] = array(
  14. '#type' => 'textarea',
  15. '#title' => 'Export',
  16. '#description' => t('Simply copy the provided export into the Import text area on '
  17. . 'another tripal views enabled website to port the integration between websites.'),
  18. '#rows' => 20,
  19. '#value' => serialize($defn_array)
  20. );
  21. return $form;
  22. }
  23. /**
  24. * Imports a tripal views integration
  25. */
  26. function tripal_views_integration_import_form() {
  27. $form = array();
  28. $form['name'] = array(
  29. '#type' => 'textfield',
  30. '#title' => 'Name (optional)',
  31. '#description' => t('A human-readable name for your integration.')
  32. );
  33. $priorities = array();
  34. foreach (range(-10, 10) as $v) {
  35. $priorities[$v] = (string) $v;
  36. }
  37. $form['views_type']['row_priority'] = array(
  38. '#type' => 'select',
  39. '#title' => t('Priority (optional)'),
  40. '#description' => t('The level of priority your Views integration has in relation to the '
  41. .'default core and module definitions. The views integration definition with the '
  42. .'lightest priority will be used. For example, if there is a definition created by '
  43. .'core with a priority of 10 and another by a custom module of 5 and yours is -1 then '
  44. .'you definition will be used for that table because -1 is lighter then both 5 and 10.'),
  45. '#options' => $priorities,
  46. '#default_value' => -1,
  47. );
  48. $form['import'] = array(
  49. '#type' => 'textarea',
  50. '#title' => 'Import',
  51. '#description' => t('Simply copy the provided export into the text area to port the integration between websites.'),
  52. '#rows' => 20,
  53. );
  54. $form['submit'] = array(
  55. '#type' => 'submit',
  56. '#value' => 'Submit'
  57. );
  58. return $form;
  59. }
  60. /**
  61. * Imports a tripal views integration
  62. */
  63. function tripal_views_integration_import_form_submit($form, &$form_state) {
  64. $defn_array = unserialize($form_state['values']['import']);
  65. // Add optional parameters
  66. if ($form_state['values']['name']) {
  67. $defn_array['name'] = $form_state['values']['name'];
  68. }
  69. if ($form_state['values']['row_priority']) {
  70. $defn_array['priority'] = $form_state['values']['row_priority'];
  71. }
  72. // Add the views integration
  73. $success = tripal_views_integration_add_entry($defn_array);
  74. if ($success) {
  75. drupal_set_message(t("Successfully imported %name Integration", array('%name' => $defn_array['name'])));
  76. }
  77. else {
  78. drupal_set_message(t("Unable to import %name Integration", array('%name' => $defn_array['name'])), 'error');
  79. }
  80. }