tripal_project.admin.inc 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. /**
  3. * @file
  4. * Administration of projects
  5. */
  6. /**
  7. * Admin launchpad
  8. *
  9. * @ingroup tripal_project
  10. */
  11. function tripal_project_admin_project_view() {
  12. $output = '';
  13. // set the breadcrumb
  14. $breadcrumb = array();
  15. $breadcrumb[] = l('Home', '<front>');
  16. $breadcrumb[] = l('Administration', 'admin');
  17. $breadcrumb[] = l('Tripal', 'admin/tripal');
  18. $breadcrumb[] = l('Chado', 'admin/tripal/chado');
  19. $breadcrumb[] = l('Projects', 'admin/tripal/chado/tripal_project');
  20. drupal_set_breadcrumb($breadcrumb);
  21. // Add the view
  22. $view = views_embed_view('tripal_project_admin_projects','default');
  23. if (isset($view)) {
  24. $output .= $view;
  25. }
  26. else {
  27. $output .= '<p>The Project module uses primarily views to provide an '
  28. . 'administrative interface. Currently one or more views needed for this '
  29. . 'administrative interface are disabled. <strong>Click each of the following links to '
  30. . 'enable the pertinent views</strong>:</p>';
  31. $output .= '<ul>';
  32. $output .= '<li>'.l('Projects View', 'admin/tripal/chado/tripal_project/views/projects/enable').'</li>';
  33. $output .= '</ul>';
  34. }
  35. return $output;
  36. }
  37. /**
  38. * Project settings
  39. *
  40. * @ingroup tripal_project
  41. */
  42. function tripal_project_admin($form, $form_state) {
  43. $form = array();
  44. // If your module is using the Chado Node: Title & Path API to allow custom titles
  45. // for your node type then you need to add the configuration form for this functionality.
  46. $details = array(
  47. 'module' => 'tripal_project', // the name of the MODULE implementing the content type
  48. 'content_type' => 'chado_project', // the name of the content type
  49. // An array of options to use under "Page Titles"
  50. // the key should be the token and the value should be the human-readable option
  51. 'options' => array(
  52. '[project.name]' => 'project Name Only',
  53. // there should always be one options matching the unique constraint.
  54. '[project.name]' => 'Unique Contraint: The project name'
  55. ),
  56. // the token indicating the unique constraint in the options array
  57. 'unique_option' => '[project.name]'
  58. );
  59. // This call adds the configuration form to your current form
  60. // This sub-form handles it's own validation & submit
  61. chado_add_admin_form_set_title($form, $form_state, $details);
  62. // project URL PATHS
  63. $form['url'] = array(
  64. '#type' => 'fieldset',
  65. '#title' => t('Project URL Path'),
  66. '#collapsible' => TRUE,
  67. '#collapsed' => FALSE,
  68. );
  69. $options = array(
  70. 'project' => 'project:' . t('Chado table name'),
  71. 'SID[id]' => '[id]:' . t('The Chado project_id'),
  72. '[name]' => '[name]:' . t('The project name'),
  73. );
  74. $form['url']['options'] = array(
  75. '#type' => 'item',
  76. '#title' => 'Available Tokens',
  77. '#markup' => '<ul><li>' . implode('</li><li>', $options) . '</li></ul>'
  78. );
  79. $form['url']['chado_project_url_string'] = array(
  80. '#title' => 'URL Syntax',
  81. '#type' => 'textfield',
  82. '#description' => t('You may rearrange elements in this text box to '.
  83. 'customize the URLs. The available tags are listed below. You can separate or '.
  84. 'include any text between the tags. Click the "Set project URLs" button to '.
  85. 'reset the URLs for all project pages. Click the "Save Configuration" button to '.
  86. 'simply save this setup. <b>Important</b>: be sure that whatever you choose will '.
  87. 'always be unique even considering future data that may be added. If you include '.
  88. 'the Chado table name and id you are guaranteed to have a unique URL. For example project/[id]'),
  89. '#size' => 150,
  90. '#default_value' => variable_get('chado_project_url_string', '/project/[id]'),
  91. );
  92. $form['url']['button'] = array(
  93. '#type' => 'submit',
  94. '#value' => t('Set Project URLs'),
  95. );
  96. return system_settings_form($form);
  97. }
  98. /**
  99. * Validate project settings
  100. *
  101. * @ingroup tripal_project
  102. */
  103. function tripal_project_admin_validate($form, &$form_state) {
  104. global $user; // we need access to the user info
  105. $job_args = array();
  106. switch ($form_state['values']['op']) {
  107. case t('Set Project URLs') :
  108. variable_set('chado_project_url', $form_state['values']['chado_project_url_string']);
  109. tripal_add_job('Set Project URLs', 'tripal_project',
  110. 'tripal_project_set_urls', $job_args, $user->uid);
  111. break;
  112. }
  113. }