tripal_jbrowse_page.admin.inc 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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']['embed'] = [
  15. '#type' => 'checkbox',
  16. '#title' => 'Embed JBrowse in your Tripal Site',
  17. '#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.',
  18. '#default_value' => variable_get('trpjbrowse_page_embed', 1),
  19. ];
  20. $form['exclude_fieldset'] = [
  21. '#type' => 'fieldset',
  22. '#title' => 'Exclude JBrowse Instances from Page Integration',
  23. '#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.',
  24. ];
  25. // Get all instances as an option to be excluded.
  26. $instances = tripal_jbrowse_mgmt_get_instances();
  27. $options = [];
  28. foreach ($instances as $instance) {
  29. $key = $instance->id;
  30. $options[$key] = [
  31. 'genus' => $instance->organism->genus,
  32. 'species' => $instance->organism->species,
  33. 'analysis' => $instance->analysis->name ?? 'Not Provided',
  34. 'description' => $instance->description,
  35. ];
  36. }
  37. // Determine the default value.
  38. $default_exclude = variable_get('trpjbrowse_page_exclude', []);
  39. if (!is_array($default_exclude)) {
  40. $default_exclude = unserialize($default_exclude);
  41. }
  42. // Now generate the table.
  43. $form['exclude_fieldset']['exclude'] = [
  44. '#type' => 'tableselect',
  45. '#header' => [
  46. 'genus' => t('Genus'),
  47. 'species' => t('Species'),
  48. 'analysis' => t('Sequence Assembly'),
  49. 'description' => t('Description')
  50. ],
  51. '#options' => $options,
  52. '#empty' => t('No JBrowse Instances available. Please add one through the "List Instances" page.'),
  53. '#default_value' => $default_exclude,
  54. ];
  55. $form['submit'] = [
  56. '#type' => 'submit',
  57. '#value' => 'Save Settings',
  58. ];
  59. return $form;
  60. }
  61. /**
  62. * Settings Form for page integration.
  63. */
  64. function tripal_jbrowse_page_settings_form_submit($form, $form_state) {
  65. $values = $form_state['values'];
  66. // General Settings.
  67. variable_set(
  68. 'trpjbrowse_page_embed',
  69. $values['embed']
  70. );
  71. // Exclude Instances.
  72. variable_set(
  73. 'trpjbrowse_page_exclude',
  74. serialize($values['exclude'])
  75. );
  76. // Ensure the menu is rebuilt.
  77. variable_set('menu_rebuild_needed', TRUE);
  78. }