tripal_library.module 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. <?php
  2. /**
  3. * @file
  4. * Integrates the Chado Library module with Drupal Nodes & Views
  5. */
  6. /**
  7. * @defgroup tripal_library Library Module
  8. * @ingroup tripal_modules
  9. * @{
  10. * Integrates the Chado Library module with Drupal Nodes & Views
  11. * @}
  12. */
  13. require_once 'api/tripal_library.DEPRECATED.inc';
  14. require_once 'theme/tripal_library.theme.inc';
  15. require_once 'includes/tripal_library.admin.inc';
  16. require_once 'includes/tripal_library.chado_node.inc';
  17. /**
  18. * Implements hook_permission().
  19. *
  20. * Set the permission types that the chado module uses. Essentially we
  21. * want permissionis that protect creation, editing and deleting of chado
  22. * data objects
  23. *
  24. * @ingroup tripal_library
  25. */
  26. function tripal_library_permission() {
  27. return array(
  28. 'access chado_library content' => array(
  29. 'title' => t('View Libraries'),
  30. 'description' => t('Allow users to view library pages.'),
  31. ),
  32. 'create chado_library content' => array(
  33. 'title' => t('Create Libraries'),
  34. 'description' => t('Allow users to create new library pages.'),
  35. ),
  36. 'delete chado_library content' => array(
  37. 'title' => t('Delete Libraries'),
  38. 'description' => t('Allow users to delete library pages.'),
  39. ),
  40. 'edit chado_library content' => array(
  41. 'title' => t('Edit Libraries'),
  42. 'description' => t('Allow users to edit library pages.'),
  43. ),
  44. 'administer tripal library' => array(
  45. 'title' => t('Administer Libraries'),
  46. 'description' => t('Allow users to administer all libraries.'),
  47. ),
  48. );
  49. }
  50. /**
  51. * Implements hook_menu().
  52. *
  53. * Menu items are automatically added for the new node types created
  54. * by this module to the 'Create Content' Navigation menu item. This function
  55. * adds more menu items needed for this module.
  56. *
  57. * @ingroup tripal_library
  58. */
  59. function tripal_library_menu() {
  60. $items = array();
  61. // The administative settings menu
  62. $items['admin/tripal/chado/tripal_library'] = array(
  63. 'title' => 'Libraries',
  64. 'description' => 'Any biological library. Examples of genomic libraries include BAC, cDNA, FOSMID, etc.',
  65. 'page callback' => 'tripal_library_admin_libraries_listing',
  66. 'access arguments' => array('administer tripal library'),
  67. 'type' => MENU_NORMAL_ITEM,
  68. );
  69. $items['admin/tripal/chado/tripal_library/help'] = array(
  70. 'title' => 'Help',
  71. 'description' => 'Basic Description of Tripal Library Module Functionality',
  72. 'page callback' => 'theme',
  73. 'page arguments' => array('tripal_library_help'),
  74. 'access arguments' => array('administer tripal library'),
  75. 'type' => MENU_LOCAL_TASK,
  76. 'weight' => 10
  77. );
  78. $items['admin/tripal/chado/tripal_library/configuration'] = array(
  79. 'title' => 'Settings',
  80. 'description' => 'Configure the Tripal Library module',
  81. 'page callback' => 'drupal_get_form',
  82. 'page arguments' => array('tripal_library_admin'),
  83. 'access arguments' => array('administer tripal library'),
  84. 'type' => MENU_LOCAL_TASK,
  85. 'weight' => 5
  86. );
  87. $items['admin/tripal/chado/tripal_library/sync'] = array(
  88. 'title' => ' Sync',
  89. 'description' => 'Create pages on this site for libraries stored in Chado',
  90. 'page callback' => 'drupal_get_form',
  91. 'page arguments' => array('chado_node_sync_form', 'tripal_library', 'chado_library'),
  92. 'access arguments' => array('administer tripal library'),
  93. 'type' => MENU_LOCAL_TASK,
  94. 'weight' => 2
  95. );
  96. $items['admin/tripal/chado/tripal_library/views/libraries/enable'] = array(
  97. 'title' => 'Enable Library Administrative View',
  98. 'page callback' => 'tripal_enable_view',
  99. 'page arguments' => array('tripal_library_admin_libraries', 'admin/tripal/chado/tripal_library'),
  100. 'access arguments' => array('administer tripal library'),
  101. 'type' => MENU_CALLBACK,
  102. );
  103. return $items;
  104. }
  105. /**
  106. * Implements hook_search_biological_data_views().
  107. *
  108. * Adds the described views to the "Search Data" Page created by Tripal Views
  109. */
  110. function tripal_library_search_biological_data_views() {
  111. return array(
  112. 'tripal_library_user_library' => array(
  113. 'machine_name' => 'tripal_library_user_library',
  114. 'human_name' => 'Libraries',
  115. 'description' => 'Biological library including BAC, cDNA, FOSMID, etc.',
  116. 'link' => 'chado/library'
  117. ),
  118. );
  119. }
  120. /**
  121. * Implements hook_views_api().
  122. *
  123. * Essentially this hook tells drupal that there is views support for
  124. * for this module which then includes tripal_db.views.inc where all the
  125. * views integration code is
  126. *
  127. * @ingroup tripal_library
  128. */
  129. function tripal_library_views_api() {
  130. return array(
  131. 'api' => 3.0,
  132. );
  133. }
  134. /**
  135. * Implements hook_theme().
  136. *
  137. * We need to let drupal know about our theme functions and their arguments.
  138. * We create theme functions to allow users of the module to customize the
  139. * look and feel of the output generated in this module
  140. *
  141. * @ingroup tripal_library
  142. */
  143. function tripal_library_theme($existing, $type, $theme, $path) {
  144. $core_path = drupal_get_path('module', 'tripal_core');
  145. $items = array(
  146. 'node__chado_library' => array(
  147. 'template' => 'node--chado-generic',
  148. 'render element' => 'node',
  149. 'base hook' => 'node',
  150. 'path' => "$core_path/theme/templates",
  151. ),
  152. // tripal_library templates
  153. 'tripal_library_base' => array(
  154. 'variables' => array('node' => NULL),
  155. 'template' => 'tripal_library_base',
  156. 'path' => "$path/theme/templates",
  157. ),
  158. 'tripal_library_features' => array(
  159. 'variables' => array('node' => NULL),
  160. 'template' => 'tripal_library_features',
  161. 'path' => "$path/theme/templates",
  162. ),
  163. 'tripal_library_properties' => array(
  164. 'variables' => array('node' => NULL),
  165. 'template' => 'tripal_library_properties',
  166. 'path' => "$path/theme/templates",
  167. ),
  168. 'tripal_library_publications' => array(
  169. 'variables' => array('node' => NULL),
  170. 'template' => 'tripal_library_publications',
  171. 'path' => "$path/theme/templates",
  172. ),
  173. 'tripal_library_references' => array(
  174. 'variables' => array('node' => NULL),
  175. 'template' => 'tripal_library_references',
  176. 'path' => "$path/theme/templates",
  177. ),
  178. 'tripal_library_synonyms' => array(
  179. 'variables' => array('node' => NULL),
  180. 'template' => 'tripal_library_synonyms',
  181. 'path' => "$path/theme/templates",
  182. ),
  183. 'tripal_library_terms' => array(
  184. 'variables' => array('node' => NULL),
  185. 'template' => 'tripal_library_terms',
  186. 'path' => "$path/theme/templates",
  187. ),
  188. 'tripal_library_help' => array(
  189. 'template' => 'tripal_library_help',
  190. 'variables' => array(NULL),
  191. 'path' => "$path/theme/templates",
  192. ),
  193. // teaser
  194. 'tripal_library_teaser' => array(
  195. 'variables' => array('node' => NULL),
  196. 'template' => 'tripal_library_teaser',
  197. 'path' => "$path/theme/templates",
  198. ),
  199. // tripal_organism templates
  200. 'tripal_organism_libraries' => array(
  201. 'variables' => array('node' => NULL),
  202. 'template' => 'tripal_organism_libraries',
  203. 'path' => "$path/theme/templates",
  204. ),
  205. // tripal_feature templates
  206. 'tripal_feature_libraries' => array(
  207. 'variables' => array('node' => NULL),
  208. 'template' => 'tripal_feature_libraries',
  209. 'path' => "$path/theme/templates",
  210. ),
  211. );
  212. return $items;
  213. }
  214. /**
  215. * Implements hook_help().
  216. * Adds a help page to the module list
  217. *
  218. * @ingroup tripal_library
  219. */
  220. function tripal_library_help ($path, $arg) {
  221. if ($path == 'admin/help#tripal_library') {
  222. return theme('tripal_library_help', array());
  223. }
  224. }
  225. /**
  226. * Implements hook_block_info().
  227. *
  228. * @ingroup tripal_library
  229. */
  230. function tripal_library_block_info() {
  231. $blocks['libreferences']['info'] = t('Tripal Library Cross References');
  232. $blocks['libreferences']['cache'] = DRUPAL_NO_CACHE;
  233. $blocks['libbase']['info'] = t('Tripal Library Details');
  234. $blocks['libbase']['cache'] = DRUPAL_NO_CACHE;
  235. $blocks['libterms']['info'] = t('Tripal Library Terms');
  236. $blocks['libterms']['cache'] = DRUPAL_NO_CACHE;
  237. $blocks['libsynonyms']['info'] = t('Tripal Library Synonyms');
  238. $blocks['libsynonyms']['cache'] = DRUPAL_NO_CACHE;
  239. $blocks['libproperties']['info'] = t('Tripal Library Properties');
  240. $blocks['libproperties']['cache'] = DRUPAL_NO_CACHE;
  241. $blocks['featurelibs']['info'] = t('Tripal Feature Libraries');
  242. $blocks['featurelibs']['cache'] = DRUPAL_NO_CACHE;
  243. $blocks['orglibs']['info'] = t('Tripal Organism Libraries');
  244. $blocks['orglibs']['cache'] = DRUPAL_NO_CACHE;
  245. return $blocks;
  246. }
  247. /**
  248. * Implements hook_block_view().
  249. *
  250. * @ingroup tripal_library
  251. */
  252. function tripal_library_block_view($delta = '') {
  253. if (user_access('access chado_library content') and arg(0) == 'node' and is_numeric(arg(1))) {
  254. $nid = arg(1);
  255. $node = node_load($nid);
  256. $block = array();
  257. switch ($delta) {
  258. case 'libreferences':
  259. $block['subject'] = t('Cross References');
  260. $block['content'] = theme('tripal_library_references', $node);
  261. break;
  262. case 'libbase':
  263. $block['subject'] = t('Library Details');
  264. $block['content'] = theme('tripal_library_base', $node);
  265. break;
  266. case 'libsynonyms':
  267. $block['subject'] = t('Synonyms');
  268. $block['content'] = theme('tripal_library_synonyms', $node);
  269. break;
  270. case 'libproperties':
  271. $block['subject'] = t('Properties');
  272. $block['content'] = theme('tripal_library_properties', $node);
  273. break;
  274. case 'libterms':
  275. $block['subject'] = t('Library Terms');
  276. $block['content'] = theme('tripal_library_terms', $node);
  277. break;
  278. case 'featurelibs':
  279. $block['subject'] = t('Libraries');
  280. $block['content'] = theme('tripal_feature_libraries', $node);
  281. break;
  282. case 'orglibs':
  283. $block['subject'] = t('Libraries');
  284. $block['content'] = theme('tripal_organism_libraries', $node);
  285. break;
  286. default :
  287. }
  288. return $block;
  289. }
  290. }
  291. /**
  292. * Implementation of hook_form_alter().
  293. *
  294. * @param $form
  295. * @param $form_state
  296. * @param $form_id
  297. *
  298. * @ingroup tripal_library
  299. */
  300. function tripal_library_form_alter(&$form, &$form_state, $form_id) {
  301. if ($form_id == "chado_library_node_form") {
  302. // turn of preview button for insert/updates
  303. $form['actions']['preview']['#access'] = FALSE;
  304. //remove the body field
  305. unset($form['body']);
  306. }
  307. }