tripal_library.module 9.6 KB

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