tripal_contact.module 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. <?php
  2. /**
  3. * @file
  4. * Functions related to general module functionality.
  5. *
  6. * @ingroup tripal_contact
  7. */
  8. /**
  9. * @defgroup tripal_contact Contact Module
  10. * @ingroup tripal_modules
  11. * @{
  12. * Integrates the Chado Contact module with Drupal Nodes & Views
  13. * @}
  14. */
  15. require_once 'api/tripal_contact.api.inc';
  16. require_once 'api/tripal_contact.DEPRECATED.inc';
  17. require_once 'theme/tripal_contact.theme.inc';
  18. require_once 'includes/tripal_contact.admin.inc';
  19. require_once 'includes/tripal_contact.chado_node.inc';
  20. /**
  21. * Implements hook_views_api().
  22. * Essentially this hook tells drupal that there is views support for
  23. * for this module which then includes tripal_contact.views.inc where all the
  24. * views integration code is.
  25. *
  26. * @ingroup tripal_contact
  27. */
  28. function tripal_contact_views_api() {
  29. return array(
  30. 'api' => 3.0,
  31. );
  32. }
  33. /**
  34. * Implemets hook_menu().
  35. * Adds menu items for the tripal_contact module menu. This section
  36. * gives the outline for the main menu of the Tripal-contact module
  37. *
  38. * @return
  39. * An array of menu items that is visible within the Drupal Menu, returned as soon
  40. * as the program is ran
  41. *
  42. * @ingroup tripal_contact
  43. */
  44. function tripal_contact_menu() {
  45. $items = array();
  46. $items['admin/tripal/chado/tripal_contact']= array(
  47. 'title' => 'Contacts',
  48. 'description' => ('Model persons, institutes, groups, organizations, etc.'),
  49. 'page callback' => 'tripal_contact_admin_contact_view',
  50. 'access arguments' => array('administer tripal contact'),
  51. 'type' => MENU_NORMAL_ITEM
  52. );
  53. $items['admin/tripal/chado/tripal_contact/configuration'] = array(
  54. 'title' => 'Settings',
  55. 'description' => 'Integration of Chado contacts.',
  56. 'page callback' => 'drupal_get_form',
  57. 'page arguments' => array('tripal_contact_admin'),
  58. 'access arguments' => array('administer tripal contact'),
  59. 'type' => MENU_LOCAL_TASK,
  60. 'weight' => 5
  61. );
  62. $items['admin/tripal/chado/tripal_contact/help']= array(
  63. 'title' => 'Help',
  64. 'description' => ('Help with the contact module.'),
  65. 'page callback' => 'theme',
  66. 'page arguments' => array('tripal_contact_help'),
  67. 'access arguments' => array('administer tripal contact'),
  68. 'type' => MENU_LOCAL_TASK,
  69. 'weight' => 10
  70. );
  71. $items['admin/tripal/chado/tripal_contact/sync'] = array(
  72. 'title' => ' Sync',
  73. 'description' => 'Sync contacts in Chado with Drupal',
  74. 'page callback' => 'drupal_get_form',
  75. 'page arguments' => array('tripal_contact_sync_form'),
  76. 'access arguments' => array('administer tripal contact'),
  77. 'type' => MENU_LOCAL_TASK,
  78. 'weight' => 0
  79. );
  80. $items['admin/tripal/chado/tripal_contact/sync'] = array(
  81. 'title' => ' Sync',
  82. 'description' => 'Create pages on this site for libraries stored in Chado',
  83. 'page callback' => 'drupal_get_form',
  84. 'page arguments' => array('chado_node_sync_form', 'tripal_contact', 'chado_contact'),
  85. 'access arguments' => array('administer tripal contact'),
  86. 'type' => MENU_LOCAL_TASK,
  87. 'weight' => 2
  88. );
  89. return $items;
  90. }
  91. /**
  92. * Implements hook_search_biological_data_views().
  93. *
  94. * Adds the described views to the "Search Data" Page created by Tripal Views
  95. */
  96. function tripal_contact_search_biological_data_views() {
  97. return array(
  98. 'tripal_contact_user_contacts' => array(
  99. 'machine_name' => 'tripal_contact_user_contacts',
  100. 'human_name' => 'Contacts',
  101. 'description' => 'Information about persons, institutes, groups, organizations, etc.',
  102. 'link' => 'chado/contact'
  103. ),
  104. );
  105. }
  106. /**
  107. * Implements hook_theme().
  108. * Register themeing functions for this module
  109. *
  110. * @return
  111. * An array of themeing functions to register
  112. *
  113. * @ingroup tripal_contact
  114. */
  115. function tripal_contact_theme($existing, $type, $theme, $path) {
  116. $core_path = drupal_get_path('module', 'tripal_core');
  117. $items = array(
  118. 'node__chado_contact' => array(
  119. 'template' => 'node--chado-generic',
  120. 'render element' => 'node',
  121. 'base hook' => 'node',
  122. 'path' => "$core_path/theme/templates",
  123. ),
  124. 'tripal_contact_base' => array(
  125. 'variables' => array('node' => NULL),
  126. 'template' => 'tripal_contact_base',
  127. 'path' => "$path/theme/templates",
  128. ),
  129. 'tripal_contact_properties' => array(
  130. 'variables' => array('node' => NULL),
  131. 'template' => 'tripal_contact_properties',
  132. 'path' => "$path/theme/templates",
  133. ),
  134. 'tripal_contact_relationships' => array(
  135. 'variables' => array('node' => NULL),
  136. 'template' => 'tripal_contact_relationships',
  137. 'path' => "$path/theme/templates",
  138. ),
  139. 'tripal_contact_publications' => array(
  140. 'variables' => array('node' => NULL),
  141. 'template' => 'tripal_contact_publications',
  142. 'path' => "$path/theme/templates",
  143. ),
  144. 'tripal_contact_help' => array(
  145. 'template' => 'tripal_contact_help',
  146. 'variables' => array(NULL),
  147. 'path' => "$path/theme/templates",
  148. ),
  149. 'tripal_contact_teaser' => array(
  150. 'variables' => array('node' => NULL),
  151. 'template' => 'tripal_contact_teaser',
  152. 'path' => "$path/theme/templates",
  153. ),
  154. );
  155. return $items;
  156. }
  157. /**
  158. * Implements hook_block_info().
  159. *
  160. * @ingroup tripal_contact
  161. */
  162. function tripal_contact_block_info() {
  163. $blocks['contbase']['info'] = t('Tripal Contact Details');
  164. $blocks['contbase']['cache'] = 'DRUPAL_NO_CACHE';
  165. $blocks['contprops']['info'] = t('Tripal Contact Properties');
  166. $blocks['contprops']['cache'] = 'DRUPAL_NO_CACHE';
  167. $blocks['contrels']['info'] = t('Tripal Contact Relationships');
  168. $blocks['contrels']['cache'] = 'DRUPAL_NO_CACHE';
  169. $blocks['contpubs']['info'] = t('Tripal Contact Publications');
  170. $blocks['contpubs']['cache'] = 'DRUPAL_NO_CACHE';
  171. return $blocks;
  172. }
  173. /**
  174. * Implements hook_block_view().
  175. * @ingroup tripal_contact
  176. */
  177. function tripal_contact_block_view($delta = '') {
  178. if (user_access('access chado_contact content') and arg(0) == 'node' and is_numeric(arg(1))) {
  179. $nid = arg(1);
  180. $node = node_load($nid);
  181. $block = array();
  182. switch ($delta) {
  183. case 'contbase':
  184. $block['subject'] = t('Overview');
  185. $block['content'] = array(
  186. '#theme' => 'tripal_contact_base',
  187. '#nodes' => $node,
  188. '#title' => '',
  189. );
  190. break;
  191. case 'contprops':
  192. $block['subject'] = t('Properties');
  193. $block['content'] = array(
  194. '#theme' => 'tripal_contact_properties',
  195. '#nodes' => $node,
  196. '#title' => '',
  197. );
  198. break;
  199. case 'contrels':
  200. $block['subject'] = t('Relationships');
  201. $block['content'] = array(
  202. '#theme' => 'tripal_contact_relationships',
  203. '#nodes' => $node,
  204. '#title' => '',
  205. );
  206. break;
  207. case 'contpubs':
  208. $block['subject'] = t('Publications');
  209. $block['content'] = array(
  210. '#theme' => 'tripal_contact_publications',
  211. '#nodes' => $node,
  212. '#title' => '',
  213. );
  214. break;
  215. default :
  216. }
  217. return $block;
  218. }
  219. }
  220. /**
  221. * Implement hook_permission().
  222. *
  223. * @ingroup tripal_contact
  224. */
  225. function tripal_contact_permission() {
  226. return array(
  227. 'access chado_contact content' => array(
  228. 'title' => t('View Contacts'),
  229. 'description' => t('Allow users to view contact pages.'),
  230. ),
  231. 'create chado_contact content' => array(
  232. 'title' => t('Create Contacts'),
  233. 'description' => t('Allow users to create new contact pages.'),
  234. ),
  235. 'delete chado_contact content' => array(
  236. 'title' => t('Delete Contacts'),
  237. 'description' => t('Allow users to delete contact pages.'),
  238. ),
  239. 'edit chado_contact content' => array(
  240. 'title' => t('Edit Contacts'),
  241. 'description' => t('Allow users to edit contact pages.'),
  242. ),
  243. 'administer tripal contact' => array(
  244. 'title' => t('Administer Contacts'),
  245. 'description' => t('Allow users to administer all contacts.'),
  246. ),
  247. );
  248. }
  249. /**
  250. * Implementation of hook_form_alter().
  251. *
  252. * @ingroup tripal_contact
  253. */
  254. function tripal_contact_form_alter(&$form, &$form_state, $form_id) {
  255. if ($form_id == "chado_contact_node_form") {
  256. // turn of preview button for insert/updates
  257. $form['actions']['preview']['#access'] = FALSE;
  258. //remove the body field
  259. unset($form['body']);
  260. }
  261. }