tripal_core.module 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. <?php
  2. /**
  3. * @file
  4. * The Tripal Core module
  5. */
  6. require_once 'api/tripal_core.chado_nodes.api.inc';
  7. require_once 'api/tripal_core.chado_nodes.title_and_path.inc';
  8. require_once 'api/tripal_core.chado_nodes.properties.api.inc';
  9. require_once 'api/tripal_core.chado_nodes.dbxrefs.api.inc';
  10. require_once 'api/tripal_core.chado_nodes.relationships.api.inc';
  11. require_once 'api/tripal_core.tripal_variables.api.inc';
  12. require_once 'includes/tripal_core.form_elements.inc';
  13. /**
  14. * @defgroup tripal_core Tripal Core Module
  15. * @ingroup tripal_modules
  16. * @{
  17. * Functionality useful for all other Tripal modules including the Tripal jobs, files,
  18. * materialized views and custom table functions.
  19. * @}
  20. */
  21. /**
  22. * Implements hook_init().
  23. * Used to set the search_path, create default content and set default variables.
  24. *
  25. * @ingroup tripal_core
  26. */
  27. function tripal_core_init() {
  28. // If we want AHAH elements on the node forms (e.g. chado_pub form) then we need to include
  29. // the node.pages file. Otherwise this error message is given:
  30. //
  31. // warning: call_user_func_array() expects parameter 1 to be a valid callback,
  32. // function 'node_form' not found or invalid function name
  33. // in /var/www/includes/form.inc on line 382.
  34. module_load_include('inc', 'node', 'node.pages');
  35. }
  36. /**
  37. * Implements hook_menu().
  38. * Defines all menu items needed by Tripal Core
  39. *
  40. * @ingroup tripal_core
  41. */
  42. function tripal_core_menu() {
  43. $items = array();
  44. // Relationshi API autocomplete callback
  45. $items['tripal_ajax/relationship_nodeform/%/%/name_to_id'] = array(
  46. 'page callback' => 'chado_add_node_form_relationships_name_to_id_callback',
  47. 'page arguments' => array(2,3),
  48. 'access arguments' => array('access content'),
  49. 'type' => MENU_CALLBACK
  50. );
  51. // The node's TOC tab
  52. $items['node/%node/tripal_toc'] = array(
  53. 'title' => 'TOC',
  54. 'page callback' => 'drupal_get_form',
  55. 'page arguments' => array('tripal_core_node_toc_form', 1),
  56. 'access callback' => 'tripal_core_access_node_toc_form',
  57. 'access arguments' => array(1),
  58. 'type' => MENU_LOCAL_TASK,
  59. 'file' => '/includes/tripal_core.toc.inc',
  60. );
  61. return $items;
  62. }
  63. /**
  64. * An access wrapper function for editing the TOC
  65. *
  66. * @param $node
  67. * A node object
  68. * @return
  69. * Returns TRUE if the node is a Tripal-based node and the user hass
  70. * the 'administer tripal' role.
  71. */
  72. function tripal_core_access_node_toc_form($node) {
  73. $types = module_invoke_all('node_info');
  74. if (array_key_exists($node->type, $types) and
  75. array_key_exists('chado_node_api', $types[$node->type])) {
  76. return user_access('administer tripal');
  77. }
  78. return FALSE;
  79. }
  80. /**
  81. * Implements hook_permission().
  82. *
  83. * Set the permission types that the chado module uses. Essentially we
  84. * want permissionis that protect creation, editing and deleting of chado
  85. * data objects
  86. *
  87. * @ingroup tripal_core
  88. */
  89. function tripal_core_permission() {
  90. return array();
  91. }
  92. /**
  93. * Implements hook_theme().
  94. * Registers template files/functions used by this module.
  95. *
  96. * @ingroup tripal_core
  97. */
  98. function tripal_core_theme($existing, $type, $theme, $path) {
  99. return array(
  100. 'tripal_core_customize' => array(
  101. 'arguments' => array('job_id' => NULL),
  102. 'template' => 'tripal_core_customize',
  103. 'path' => "$path/theme/templates"
  104. ),
  105. 'theme_file_upload_combo' => array(
  106. 'render element' => 'element',
  107. ),
  108. 'theme_sequence_combo' => array(
  109. 'render element' => 'element',
  110. ),
  111. 'tripal_core_jobs_help' => array(
  112. 'template' => 'tripal_core_jobs_help',
  113. 'variables' => array(NULL),
  114. 'path' => "$path/theme/templates"
  115. ),
  116. 'tripal_core_customtables_help' => array(
  117. 'template' => 'tripal_core_customtables_help',
  118. 'variables' => array(NULL),
  119. 'path' => "$path/theme/templates"
  120. ),
  121. // Chado Node API Themes
  122. // --------------------------------
  123. // Properties Node Form
  124. 'chado_node_properties_form_table' => array(
  125. 'function' => 'theme_chado_add_node_form_properties',
  126. 'render element' => 'element',
  127. ),
  128. // Additional Dbxrefs Nore Form
  129. 'chado_node_additional_dbxrefs_form_table' => array(
  130. 'function' => 'theme_chado_add_node_form_dbxrefs_table',
  131. 'render element' => 'element',
  132. ),
  133. // Relationships Nore Form
  134. 'chado_node_relationships_form_table' => array(
  135. 'function' => 'theme_chado_add_node_form_relationships_table',
  136. 'render element' => 'element',
  137. ),
  138. // Form and form element themes.
  139. // --------------------------------
  140. 'tripal_node_toc_items_table' => array(
  141. 'render element' => 'element',
  142. ),
  143. // Theme function for the extension admin page.
  144. 'tripal_core_extensions_form_tables' => array(
  145. 'render element' => 'element',
  146. )
  147. );
  148. }
  149. /**
  150. * Implements hook_coder_ignore().
  151. *
  152. * Defines the path to the file (tripal_core.coder_ignores.txt) where ignore
  153. * rules for coder are stored.
  154. *
  155. */
  156. function tripal_core_coder_ignore() {
  157. return array(
  158. 'path' => drupal_get_path('module', 'tripal_core'),
  159. 'line prefix' => drupal_get_path('module', 'tripal_core'),
  160. );
  161. }
  162. /**
  163. * Implements hook_views_api().
  164. *
  165. * Essentially this hook tells drupal that there is views support for
  166. * for this module which then includes tripal_db.views.inc where all the
  167. * views integration code is.
  168. *
  169. * @ingroup tripal_core
  170. */
  171. function tripal_core_views_api() {
  172. return array(
  173. 'api' => 3.0,
  174. );
  175. }
  176. /**
  177. * Implements hook_node_view_alter().
  178. *
  179. * @ingroup tripal_core
  180. */
  181. function tripal_core_node_view_alter(&$build) {
  182. module_load_include('inc', 'tripal_core', 'includes/tripal_core.toc');
  183. tripal_core_node_view_build_toc($build);
  184. }
  185. /**
  186. * Implements hook_node_view().
  187. *
  188. * @ingroup tripal_core
  189. */
  190. function tripal_core_node_view($node, $view_mode, $langcode) {
  191. // if this node type is a chado-based node (i.e. Tripal node)
  192. // the we want to add a table of contents to it's content list
  193. // this table of contents will be an empty
  194. if (preg_match('/^chado_/', $node->type)) {
  195. // Show feature browser and counts
  196. if ($view_mode == 'full') {
  197. if (!isset($node->content['#tripal_generic_node_template'])) {
  198. $node->content['#tripal_generic_node_template'] = TRUE;
  199. }
  200. }
  201. }
  202. }