tripal_jbrowse_page.admin.inc 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. /**
  3. * @file
  4. * Administration (settings) for this module.
  5. */
  6. /**
  7. * Settings Form for page integration.
  8. */
  9. function tripal_jbrowse_page_settings_form($form, $form_state) {
  10. $form['general'] = [
  11. '#type' => 'fieldset',
  12. '#title' => 'General Page Integration Settings'
  13. ];
  14. $form['general']['create_menu_items'] = [
  15. '#type' => 'checkbox',
  16. '#title' => 'Create Menu Items',
  17. '#description' => 'Checking this box ensures that menu items under
  18. "Navigation" will be created for each JBrowse instance. This only
  19. applies to JBrowse Instances with a page.',
  20. '#default_value' => variable_get('trpjbrowse_page_create_menu_items', 1),
  21. ];
  22. $form['general']['embed'] = [
  23. '#type' => 'checkbox',
  24. '#title' => 'Embed JBrowse in your Tripal Site',
  25. '#description' => 'Check this box if you would like to embed the JBrowse in your Tripal site. Conversely, uncheck it for links to go directly to the full-screen JBrowse.',
  26. '#default_value' => variable_get('trpjbrowse_page_embed', 1),
  27. ];
  28. $form['exclude_fieldset'] = [
  29. '#type' => 'fieldset',
  30. '#title' => 'Exclude JBrowse Instances from Page Integration',
  31. '#description' => 'To exclude a JBrowse instance from page integration (i.e. no embedded page will be shown and it won\'t show up in the listing), check the checkbox below.',
  32. ];
  33. // Get all instances as an option to be excluded.
  34. $instances = tripal_jbrowse_mgmt_get_instances();
  35. $options = [];
  36. foreach ($instances as $instance) {
  37. $key = $instance->id;
  38. $options[$key] = [
  39. 'genus' => $instance->organism->genus,
  40. 'species' => $instance->organism->species,
  41. ];
  42. }
  43. // Determine the default value.
  44. $default_exclude = variable_get('trpjbrowse_page_exclude', []);
  45. if (!is_array($default_exclude)) {
  46. $default_exclude = unserialize($default_exclude);
  47. }
  48. // Now generate the table.
  49. $form['exclude_fieldset']['exclude'] = [
  50. '#type' => 'tableselect',
  51. '#header' => [
  52. 'genus' => t('Genus'),
  53. 'species' => t('Species'),
  54. ],
  55. '#options' => $options,
  56. '#empty' => t('No JBrowse Instances available. Please add one through the "List Instances" page.'),
  57. '#default_value' => $default_exclude,
  58. ];
  59. $form['submit'] = [
  60. '#type' => 'submit',
  61. '#value' => 'Save Settings',
  62. ];
  63. return $form;
  64. }
  65. /**
  66. * Settings Form for page integration.
  67. */
  68. function tripal_jbrowse_page_settings_form_submit($form, $form_state) {
  69. $values = $form_state['values'];
  70. // General Settings.
  71. variable_set(
  72. 'trpjbrowse_page_create_menu_items',
  73. $values['create_menu_items']
  74. );
  75. variable_set(
  76. 'trpjbrowse_page_embed',
  77. $values['embed']
  78. );
  79. // Exclude Instances.
  80. variable_set(
  81. 'trpjbrowse_page_exclude',
  82. serialize($values['exclude'])
  83. );
  84. // Ensure the menu is rebuilt.
  85. variable_set('menu_rebuild_needed', TRUE);
  86. }