tripal_library.module 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  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_permisssion() {
  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. 'adminster 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_views_admin_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_views_api().
  107. *
  108. * Essentially this hook tells drupal that there is views support for
  109. * for this module which then includes tripal_db.views.inc where all the
  110. * views integration code is
  111. *
  112. * @ingroup tripal_library
  113. */
  114. function tripal_library_views_api() {
  115. return array(
  116. 'api' => 3.0,
  117. );
  118. }
  119. /**
  120. * Implements hook_theme().
  121. *
  122. * We need to let drupal know about our theme functions and their arguments.
  123. * We create theme functions to allow users of the module to customize the
  124. * look and feel of the output generated in this module
  125. *
  126. * @ingroup tripal_library
  127. */
  128. function tripal_library_theme($existing, $type, $theme, $path) {
  129. $core_path = drupal_get_path('module', 'tripal_core');
  130. $items = array(
  131. 'node__chado_library' => array(
  132. 'template' => 'node--chado-generic',
  133. 'render element' => 'node',
  134. 'base hook' => 'node',
  135. 'path' => "$core_path/theme",
  136. ),
  137. // tripal_library templates
  138. 'tripal_library_base' => array(
  139. 'variables' => array('node' => NULL),
  140. 'template' => 'tripal_library_base',
  141. 'path' => "$path/theme/tripal_library",
  142. ),
  143. 'tripal_library_properties' => array(
  144. 'variables' => array('node' => NULL),
  145. 'template' => 'tripal_library_properties',
  146. 'path' => "$path/theme/tripal_library",
  147. ),
  148. 'tripal_library_publications' => array(
  149. 'variables' => array('node' => NULL),
  150. 'template' => 'tripal_library_publications',
  151. 'path' => "$path/theme/tripal_library",
  152. ),
  153. 'tripal_library_references' => array(
  154. 'variables' => array('node' => NULL),
  155. 'template' => 'tripal_library_references',
  156. 'path' => "$path/theme/tripal_library",
  157. ),
  158. 'tripal_library_synonyms' => array(
  159. 'variables' => array('node' => NULL),
  160. 'template' => 'tripal_library_synonyms',
  161. 'path' => "$path/theme/tripal_library",
  162. ),
  163. 'tripal_library_terms' => array(
  164. 'variables' => array('node' => NULL),
  165. 'template' => 'tripal_library_terms',
  166. 'path' => "$path/theme/tripal_library",
  167. ),
  168. 'tripal_library_help' => array(
  169. 'template' => 'tripal_library_help',
  170. 'variables' => array(NULL),
  171. 'path' => "$path/theme",
  172. ),
  173. // teaser
  174. 'tripal_library_teaser' => array(
  175. 'variables' => array('node' => NULL),
  176. 'template' => 'tripal_library_teaser',
  177. 'path' => "$path/theme/tripal_library",
  178. ),
  179. // tripal_organism templates
  180. 'tripal_organism_libraries' => array(
  181. 'variables' => array('node' => NULL),
  182. 'template' => 'tripal_organism_libraries',
  183. 'path' => "$path/theme/tripal_organism",
  184. ),
  185. // tripal_feature templates
  186. 'tripal_feature_libraries' => array(
  187. 'variables' => array('node' => NULL),
  188. 'template' => 'tripal_feature_libraries',
  189. 'path' => "$path/theme/tripal_feature",
  190. ),
  191. );
  192. return $items;
  193. }
  194. /**
  195. * Implements hook_help().
  196. * Adds a help page to the module list
  197. *
  198. * @ingroup tripal_library
  199. */
  200. function tripal_library_help ($path, $arg) {
  201. if ($path == 'admin/help#tripal_library') {
  202. return theme('tripal_library_help', array());
  203. }
  204. }
  205. /**
  206. * Implements hook_block_info().
  207. *
  208. * @ingroup tripal_library
  209. */
  210. function tripal_library_block_info() {
  211. $blocks['libreferences']['info'] = t('Tripal Library Cross References');
  212. $blocks['libreferences']['cache'] = DRUPAL_NO_CACHE;
  213. $blocks['libbase']['info'] = t('Tripal Library Details');
  214. $blocks['libbase']['cache'] = DRUPAL_NO_CACHE;
  215. $blocks['libterms']['info'] = t('Tripal Library Terms');
  216. $blocks['libterms']['cache'] = DRUPAL_NO_CACHE;
  217. $blocks['libsynonyms']['info'] = t('Tripal Library Synonyms');
  218. $blocks['libsynonyms']['cache'] = DRUPAL_NO_CACHE;
  219. $blocks['libproperties']['info'] = t('Tripal Library Properties');
  220. $blocks['libproperties']['cache'] = DRUPAL_NO_CACHE;
  221. $blocks['featurelibs']['info'] = t('Tripal Feature Libraries');
  222. $blocks['featurelibs']['cache'] = DRUPAL_NO_CACHE;
  223. $blocks['orglibs']['info'] = t('Tripal Organism Libraries');
  224. $blocks['orglibs']['cache'] = DRUPAL_NO_CACHE;
  225. return $blocks;
  226. }
  227. /**
  228. * Implements hook_block_view().
  229. *
  230. * @ingroup tripal_library
  231. */
  232. function tripal_library_block_view($delta = '') {
  233. if (user_access('access chado_library content') and arg(0) == 'node' and is_numeric(arg(1))) {
  234. $nid = arg(1);
  235. $node = node_load($nid);
  236. $block = array();
  237. switch ($delta) {
  238. case 'libreferences':
  239. $block['subject'] = t('Cross References');
  240. $block['content'] = theme('tripal_library_references', $node);
  241. break;
  242. case 'libbase':
  243. $block['subject'] = t('Library Details');
  244. $block['content'] = theme('tripal_library_base', $node);
  245. break;
  246. case 'libsynonyms':
  247. $block['subject'] = t('Synonyms');
  248. $block['content'] = theme('tripal_library_synonyms', $node);
  249. break;
  250. case 'libproperties':
  251. $block['subject'] = t('Properties');
  252. $block['content'] = theme('tripal_library_properties', $node);
  253. break;
  254. case 'libterms':
  255. $block['subject'] = t('Library Terms');
  256. $block['content'] = theme('tripal_library_terms', $node);
  257. break;
  258. case 'featurelibs':
  259. $block['subject'] = t('Libraries');
  260. $block['content'] = theme('tripal_feature_libraries', $node);
  261. break;
  262. case 'orglibs':
  263. $block['subject'] = t('Libraries');
  264. $block['content'] = theme('tripal_organism_libraries', $node);
  265. break;
  266. default :
  267. }
  268. return $block;
  269. }
  270. }
  271. /**
  272. * Implementation of hook_form_alter().
  273. *
  274. * @param $form
  275. * @param $form_state
  276. * @param $form_id
  277. *
  278. * @ingroup tripal_library
  279. */
  280. function tripal_library_form_alter(&$form, &$form_state, $form_id) {
  281. if ($form_id == "chado_library_node_form") {
  282. // turn of preview button for insert/updates
  283. $form['actions']['preview']['#access'] = FALSE;
  284. //remove the body field
  285. unset($form['body']);
  286. }
  287. }