tripal_core.module 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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. // Triapl setting groups
  45. $items['admin/tripal/legacy'] = array(
  46. 'title' => 'Tripal Legacy',
  47. 'description' => t("Legacy functionality from Tripal v2.0."),
  48. 'weight' => -8,
  49. 'page callback' => 'system_admin_menu_block_page',
  50. 'access arguments' => array('administer tripal'),
  51. 'file' => 'system.admin.inc',
  52. 'file path' => drupal_get_path('module', 'system'),
  53. );
  54. // Relationshi API autocomplete callback
  55. $items['tripal_ajax/relationship_nodeform/%/%/name_to_id'] = array(
  56. 'page callback' => 'chado_add_node_form_relationships_name_to_id_callback',
  57. 'page arguments' => array(2,3),
  58. 'access arguments' => array('access content'),
  59. 'type' => MENU_CALLBACK
  60. );
  61. // The node's TOC tab
  62. $items['node/%node/tripal_toc'] = array(
  63. 'title' => 'TOC',
  64. 'page callback' => 'drupal_get_form',
  65. 'page arguments' => array('tripal_core_node_toc_form', 1),
  66. 'access callback' => 'tripal_core_access_node_toc_form',
  67. 'access arguments' => array(1),
  68. 'type' => MENU_LOCAL_TASK,
  69. 'file' => '/includes/tripal_core.toc.inc',
  70. );
  71. return $items;
  72. }
  73. /**
  74. * An access wrapper function for editing the TOC
  75. *
  76. * @param $node
  77. * A node object
  78. * @return
  79. * Returns TRUE if the node is a Tripal-based node and the user hass
  80. * the 'administer tripal' role.
  81. */
  82. function tripal_core_access_node_toc_form($node) {
  83. $types = module_invoke_all('node_info');
  84. if (array_key_exists($node->type, $types) and
  85. array_key_exists('chado_node_api', $types[$node->type])) {
  86. return user_access('administer tripal');
  87. }
  88. return FALSE;
  89. }
  90. /**
  91. * Implements hook_permission().
  92. *
  93. * Set the permission types that the chado module uses. Essentially we
  94. * want permissionis that protect creation, editing and deleting of chado
  95. * data objects
  96. *
  97. * @ingroup tripal_core
  98. */
  99. function tripal_core_permission() {
  100. return array();
  101. }
  102. /**
  103. * Implements hook_theme().
  104. * Registers template files/functions used by this module.
  105. *
  106. * @ingroup tripal_core
  107. */
  108. function tripal_core_theme($existing, $type, $theme, $path) {
  109. return array(
  110. 'tripal_core_customize' => array(
  111. 'arguments' => array('job_id' => NULL),
  112. 'template' => 'tripal_core_customize',
  113. 'path' => "$path/theme/templates"
  114. ),
  115. 'theme_file_upload_combo' => array(
  116. 'render element' => 'element',
  117. ),
  118. 'theme_sequence_combo' => array(
  119. 'render element' => 'element',
  120. ),
  121. 'tripal_core_jobs_help' => array(
  122. 'template' => 'tripal_core_jobs_help',
  123. 'variables' => array(NULL),
  124. 'path' => "$path/theme/templates"
  125. ),
  126. 'tripal_core_customtables_help' => array(
  127. 'template' => 'tripal_core_customtables_help',
  128. 'variables' => array(NULL),
  129. 'path' => "$path/theme/templates"
  130. ),
  131. // Chado Node API Themes
  132. // --------------------------------
  133. // Properties Node Form
  134. 'chado_node_properties_form_table' => array(
  135. 'function' => 'theme_chado_add_node_form_properties',
  136. 'render element' => 'element',
  137. ),
  138. // Additional Dbxrefs Nore Form
  139. 'chado_node_additional_dbxrefs_form_table' => array(
  140. 'function' => 'theme_chado_add_node_form_dbxrefs_table',
  141. 'render element' => 'element',
  142. ),
  143. // Relationships Nore Form
  144. 'chado_node_relationships_form_table' => array(
  145. 'function' => 'theme_chado_add_node_form_relationships_table',
  146. 'render element' => 'element',
  147. ),
  148. // Form and form element themes.
  149. // --------------------------------
  150. 'tripal_node_toc_items_table' => array(
  151. 'render element' => 'element',
  152. ),
  153. // Theme function for the extension admin page.
  154. 'tripal_core_extensions_form_tables' => array(
  155. 'render element' => 'element',
  156. )
  157. );
  158. }
  159. /**
  160. * Implements hook_coder_ignore().
  161. *
  162. * Defines the path to the file (tripal_core.coder_ignores.txt) where ignore
  163. * rules for coder are stored.
  164. *
  165. */
  166. function tripal_core_coder_ignore() {
  167. return array(
  168. 'path' => drupal_get_path('module', 'tripal_core'),
  169. 'line prefix' => drupal_get_path('module', 'tripal_core'),
  170. );
  171. }
  172. /**
  173. * Implements hook_views_api().
  174. *
  175. * Essentially this hook tells drupal that there is views support for
  176. * for this module which then includes tripal_db.views.inc where all the
  177. * views integration code is.
  178. *
  179. * @ingroup tripal_core
  180. */
  181. function tripal_core_views_api() {
  182. return array(
  183. 'api' => 3.0,
  184. );
  185. }
  186. /**
  187. * Implements hook_node_view_alter().
  188. *
  189. * @ingroup tripal_core
  190. */
  191. function tripal_core_node_view_alter(&$build) {
  192. module_load_include('inc', 'tripal_core', 'includes/tripal_core.toc');
  193. tripal_core_node_view_build_toc($build);
  194. }
  195. /**
  196. * Implements hook_node_view().
  197. *
  198. * @ingroup tripal_core
  199. */
  200. function tripal_core_node_view($node, $view_mode, $langcode) {
  201. // if this node type is a chado-based node (i.e. Tripal node)
  202. // the we want to add a table of contents to it's content list
  203. // this table of contents will be an empty
  204. if (preg_match('/^chado_/', $node->type)) {
  205. if ($view_mode == 'full') {
  206. if (!isset($node->content['#tripal_generic_node_template'])) {
  207. $node->content['#tripal_generic_node_template'] = TRUE;
  208. }
  209. }
  210. }
  211. }
  212. /**
  213. * Adds support for tokens in the field_resource_links field.
  214. *
  215. * The field_resource_links field is a special field that can be manually
  216. * added by the site admin for providing links on the Tripal TOC sidebar.
  217. * Using tokens will allow for creation of custom links. This function
  218. * will add a fieldset contiaining the list of appropriate tokens for the
  219. * content type.
  220. *
  221. * @param unknown $element
  222. * @param unknown $form_state
  223. * @param unknown $context
  224. */
  225. function tripal_core_field_widget_form_alter(&$element, &$form_state, $context) {
  226. // If the name of the field is 'field_resource_links' then we want to
  227. // add a fieldset of tokens.
  228. if (isset($element['#field_name']) AND $element['#field_name'] == 'field_resource_links') {
  229. // Add the tokens fieldset to the last element.
  230. $num_elements = count($context['items']);
  231. if ($num_elements == $element['#delta']) {
  232. $bundle = $element['#bundle'];
  233. $base_table = preg_replace('/^chado_(.*)$/', '\1', $bundle);
  234. $tokens = chado_node_generate_tokens($base_table);
  235. $token_list = chado_node_format_tokens($tokens);
  236. $element['tokens'] = array(
  237. '#type' => 'fieldset',
  238. '#title' => 'Available tokens',
  239. '#collapsible' => TRUE,
  240. '#collapsed' => TRUE,
  241. '#weight' => 100
  242. );
  243. $element['tokens']['tokens_table'] = array(
  244. '#type' => 'item',
  245. '#markup' => $token_list
  246. );
  247. }
  248. }
  249. }