tripal_core.module 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  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. 'administer controlled vocabularies' => array(
  158. 'title' => t('Administer controlled vocabularies (CVs).'),
  159. 'description' => t('Allow a user to add, edit and delete controlled vocabularies as well as add and edit terms.')
  160. ),
  161. );
  162. }
  163. /**
  164. * Implements hook_coder_ignore().
  165. *
  166. * Defines the path to the file (tripal_core.coder_ignores.txt) where ignore
  167. * rules for coder are stored.
  168. *
  169. */
  170. function tripal_core_coder_ignore() {
  171. return array(
  172. 'path' => drupal_get_path('module', 'tripal_core'),
  173. 'line prefix' => drupal_get_path('module', 'tripal_core'),
  174. );
  175. }
  176. /**
  177. * Implements hook_views_api().
  178. *
  179. * Essentially this hook tells drupal that there is views support for
  180. * for this module which then includes tripal_db.views.inc where all the
  181. * views integration code is.
  182. *
  183. * @ingroup tripal_core
  184. */
  185. function tripal_core_views_api() {
  186. return array(
  187. 'api' => 3.0,
  188. );
  189. }
  190. /**
  191. * Implements hook_node_view_alter().
  192. *
  193. * @ingroup tripal_core
  194. */
  195. function tripal_core_node_view_alter(&$build) {
  196. module_load_include('inc', 'tripal_core', 'includes/tripal_core.toc');
  197. tripal_core_node_view_build_toc($build);
  198. }
  199. /**
  200. * Implements hook_node_view().
  201. *
  202. * @ingroup tripal_core
  203. */
  204. function tripal_core_node_view($node, $view_mode, $langcode) {
  205. // if this node type is a chado-based node (i.e. Tripal node)
  206. // the we want to add a table of contents to it's content list
  207. // this table of contents will be an empty
  208. if (preg_match('/^chado_/', $node->type)) {
  209. if ($view_mode == 'full') {
  210. if (!isset($node->content['#tripal_generic_node_template'])) {
  211. $node->content['#tripal_generic_node_template'] = TRUE;
  212. }
  213. }
  214. }
  215. }
  216. /**
  217. * Adds support for tokens in the field_resource_links field.
  218. *
  219. * The field_resource_links field is a special field that can be manually
  220. * added by the site admin for providing links on the Tripal TOC sidebar.
  221. * Using tokens will allow for creation of custom links. This function
  222. * will add a fieldset contiaining the list of appropriate tokens for the
  223. * content type.
  224. *
  225. * @param unknown $element
  226. * @param unknown $form_state
  227. * @param unknown $context
  228. */
  229. function tripal_core_field_widget_form_alter(&$element, &$form_state, $context) {
  230. // If the name of the field is 'field_resource_links' then we want to
  231. // add a fieldset of tokens.
  232. if (isset($element['#field_name']) AND $element['#field_name'] == 'field_resource_links') {
  233. // Add the tokens fieldset to the last element.
  234. $num_elements = count($context['items']);
  235. if ($num_elements == $element['#delta']) {
  236. $bundle = $element['#bundle'];
  237. $base_table = preg_replace('/^chado_(.*)$/', '\1', $bundle);
  238. $tokens = chado_node_generate_tokens($base_table);
  239. $token_list = chado_node_format_tokens($tokens);
  240. $element['tokens'] = array(
  241. '#type' => 'fieldset',
  242. '#title' => 'Available tokens',
  243. '#collapsible' => TRUE,
  244. '#collapsed' => TRUE,
  245. '#weight' => 100
  246. );
  247. $element['tokens']['tokens_table'] = array(
  248. '#type' => 'item',
  249. '#markup' => $token_list
  250. );
  251. }
  252. }
  253. }