tripal_example.module 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. <?php
  2. /**
  3. * @file
  4. * This file contains all Drupal hooks for the module other than any
  5. * node hooks and block hooks. Those go in the [module name].chado_node.inc file
  6. * and [module_name].blocks.inc respectively
  7. *
  8. */
  9. // EXPLANATION: include any files needed for this module. That includes any
  10. // API file, the theme file, or include files.
  11. require('api/tripal_example.api.inc');
  12. require('theme/tripal_example.theme.inc');
  13. require('includes/tripal_example.admin.inc');
  14. require('includes/tripal_example.chado_node.inc');
  15. /**
  16. * Implementation of hook_permissions()
  17. *
  18. * Set the permission types that this module uses.
  19. *
  20. * @ingroup tripal_example
  21. */
  22. function tripal_example_permisssions() {
  23. // EXPLANATION: here we want to setup any of the permission types
  24. // that this module needs. Our exmample module creates a new
  25. // chado node type called 'chado_example'. Therefore, we need
  26. // permissions to view, edit, delete, create our new node type. Additionally,
  27. // we want to add a permission that allows for administration of this
  28. // module. These permissions will appear in the 'People' -> 'Permissions'
  29. // configuration page and allow the site admin to specify which user roles
  30. // are allowed to perform specific actions.
  31. return array(
  32. 'access chado_example content' => array(
  33. 'title' => t('View Examples'),
  34. 'description' => t('Allow users to view example pages.'),
  35. ),
  36. 'create chado_example content' => array(
  37. 'title' => t('Create Examples'),
  38. 'description' => t('Allow users to create new example pages.'),
  39. ),
  40. 'delete chado_example content' => array(
  41. 'title' => t('Delete Examples'),
  42. 'description' => t('Allow users to delete example pages.'),
  43. ),
  44. 'edit chado_example content' => array(
  45. 'title' => t('Edit Examples'),
  46. 'description' => t('Allow users to edit example pages.'),
  47. ),
  48. 'adminster tripal example' => array(
  49. 'title' => t('Administer Examples'),
  50. 'description' => t('Allow users to administer all examples.'),
  51. ),
  52. );
  53. }
  54. /**
  55. * Implements hook_menu()
  56. *
  57. * Specifies menu items and URLs used by this module.
  58. *
  59. * @ingroup tripal_example
  60. */
  61. function tripal_example_menu() {
  62. $items = array();
  63. // EXPLANATION: the $items array should be popluated to contain a list of
  64. // menu items or URL callbacks that our module needs.
  65. // all Tripal Extension modules shoudl provide at least these menu items:
  66. // * A menu item for an administrative home page
  67. // * A menu item for 'Help' documentation
  68. // * A menu item for a module configuration page
  69. //
  70. // Additionally, if your module defines a custom node type that is linked
  71. // to a record in Chado:
  72. // * A menu item for syncing drupal nodes with Chado records.
  73. //
  74. // EXPLANATION: all extension modules should have an administrative menu item
  75. // with the path set to 'admin/tripal/extesion/[module name]'. This will
  76. // place the menu item in the 'Tripal' -> 'Extesion Modules' page. Because this
  77. // is an administrative menu item we must be sure to set the 'access arguments'
  78. // to be 'administer tripal example' which is a permission type we created
  79. // in the tripal_example_permissions() function above.
  80. $items['admin/tripal/extension/tripal_example'] = array(
  81. 'title' => 'Examples',
  82. 'description' => 'Any example.',
  83. 'page callback' => 'tripal_example_admin_examples_listing',
  84. 'access arguments' => array('administer tripal example'),
  85. 'type' => MENU_NORMAL_ITEM,
  86. );
  87. // EXPLANATION: all extension modules should provide help documentation to
  88. // describe the functionality of the module and any installation or setup
  89. // tasks that may be required. The menu 'type' is MENU_LOCAL_TASK so that
  90. // the link appears in a tab on the extension module's administrative page.
  91. // here the 'page callback' specifies that we are using Drupal's theme
  92. // function and the 'page_arguments' indicate the name of the template file
  93. // Thus, all help documentation should be provided in the
  94. // [module name]/theme/tripal_example_help.tpl.php file.
  95. $items['admin/tripal/chado/tripal_example/help'] = array(
  96. 'title' => 'Help',
  97. 'description' => 'Basic Description of Tripal Library Module Functionality',
  98. 'page callback' => 'theme',
  99. 'page arguments' => array('tripal_example_help'),
  100. 'access arguments' => array('administer tripal example'),
  101. 'type' => MENU_LOCAL_TASK,
  102. 'weight' => 10
  103. );
  104. // EXPLANATION: all extension modules should provide a configuration page.
  105. // Even if your module does not need configuration the menu item and page
  106. // should be created. This helps users recognize that the module is installed
  107. // and working. The configuration page can simply state that no
  108. // configuration settings are available. Typically a form is provided for the
  109. // module's configuration settings. Therefore the 'page callback' uses the
  110. // drupal_get_form() function and the 'page argument' indicates the form
  111. // to call is named 'tripal_eample_admin'. The function that describes
  112. // to form is in the includes/tripal_example.admin.inc file.
  113. $items['admin/tripal/chado/tripal_example/configuration'] = array(
  114. 'title' => 'Settings',
  115. 'description' => 'Configure the Tripal Library module',
  116. 'page callback' => 'drupal_get_form',
  117. 'page arguments' => array('tripal_example_admin'),
  118. 'access arguments' => array('administer tripal example'),
  119. 'type' => MENU_LOCAL_TASK,
  120. 'weight' => 5
  121. );
  122. // EXPLANATION: If your module defines a new chado node type and that node
  123. // type directly links to a record in Chado, then you can use the Tripal API
  124. // to quickly provide syncing functionality. See the API documentation here
  125. // for more information on how that is setup:
  126. // http://api.tripal.info/api/tripal/tripal_core%21api%21tripal_core.chado_nodes.api.inc/function/chado_node_sync_form/2.x
  127. $items['admin/tripal/chado/tripal_example/sync'] = array(
  128. 'title' => ' Sync',
  129. 'description' => 'Create pages on this site for examples stored in Chado',
  130. 'page callback' => 'drupal_get_form',
  131. 'page arguments' => array('chado_node_sync_form', 'tripal_example', 'chado_example'),
  132. 'access arguments' => array('administer tripal example'),
  133. 'type' => MENU_LOCAL_TASK,
  134. 'weight' => 2
  135. );
  136. return $items;
  137. }
  138. /**
  139. * Implements hook_views_api()
  140. *
  141. * This hook tells drupal that there is views support for
  142. * for this module which then automatically includes the tripal_db.views.inc
  143. * where all the views integration code is found.
  144. *
  145. * @ingroup tripal_example
  146. */
  147. function tripal_example_views_api() {
  148. return array(
  149. 'api' => 3.0,
  150. );
  151. }
  152. /**
  153. * We need to let drupal know about our theme functions and their arguments.
  154. * We create theme functions to allow users of the module to customize the
  155. * look and feel of the output generated in this module
  156. *
  157. * @ingroup tripal_example
  158. */
  159. function tripal_example_theme($existing, $type, $theme, $path) {
  160. $core_path = drupal_get_path('module', 'tripal_core');
  161. // EXPLANATION: this function defines all of the functions and templates
  162. // that this module needs to provide content. These details are provided
  163. // in the form of an array the indicates which functions or templates
  164. // provide content. Please see the Drupal theming guide for an in-depth
  165. // description for how theming works in Drupal:
  166. // https://drupal.org/documentation/theme
  167. $items = array(
  168. // EXPLANATION: If this module defines a new node type that displays
  169. // Chado data then we should use Tripal's default node template. This
  170. // template ensures that all content provided by Tripal and Tripal
  171. // extension modules has the same look and feel. It is designed to be
  172. // generic such that it won't intefer with the look-and-feel of the default
  173. // theme. This generic template will organize the node into a table
  174. // of contents found on the left-side of the page and place the content
  175. // in the center of the page. User's will cycle through content on the
  176. // page by clicking the links in the table of contents. If you do not want
  177. // to use the default Tripal template you can change this array to your
  178. // liking.
  179. 'node__chado_example' => array(
  180. 'template' => 'node--chado-generic',
  181. 'render element' => 'node',
  182. 'base hook' => 'node',
  183. 'path' => "$core_path/theme/templates",
  184. ),
  185. // EXPLANATION: the following defines all of the template files used for
  186. // this module. Templates are named with underscores separating words, and
  187. // correspond directly to a file with the extension '.tpl.php'. For example
  188. // the 'tripal_example_base' template will have a corresponding
  189. // tripal_example_base.tpl.php file where the display code is housed.
  190. // The only required templates are the 'base', 'help' and 'teaseer' templates.
  191. // The base template provides the basic information about the record in
  192. // in Chado. The 'help' template provides the adminstrative help documenation,
  193. // and the teaser provides a brief summary of the record that can be used
  194. // as short description of the record in aggregated lists.
  195. // the base template
  196. 'tripal_example_base' => array(
  197. 'variables' => array('node' => NULL),
  198. 'template' => 'tripal_example_base',
  199. 'path' => "$path/theme/templates",
  200. ),
  201. // the help template
  202. 'tripal_example_help' => array(
  203. 'template' => 'tripal_example_help',
  204. 'variables' => array(NULL),
  205. 'path' => "$path/theme",
  206. ),
  207. // the teaser template.
  208. 'tripal_example_teaser' => array(
  209. 'variables' => array('node' => NULL),
  210. 'template' => 'tripal_example_teaser',
  211. 'path' => "$path/theme/templates",
  212. ),
  213. // EXPLANATION: Typically, a different template is created for each subset of data.
  214. // for example, most Chado tables have a 'XXXXprop', 'XXXX_cvterm',
  215. // 'XXXX_dbxref', 'XXXX_synonyms', 'XXXX_relationships' tables. Therefore,
  216. // a template is created to display data from each of these tables.
  217. 'tripal_example_properties' => array(
  218. 'variables' => array('node' => NULL),
  219. 'template' => 'tripal_example_properties',
  220. 'path' => "$path/theme/templates",
  221. ),
  222. 'tripal_example_publications' => array(
  223. 'variables' => array('node' => NULL),
  224. 'template' => 'tripal_example_publications',
  225. 'path' => "$path/theme/templates",
  226. ),
  227. 'tripal_example_references' => array(
  228. 'variables' => array('node' => NULL),
  229. 'template' => 'tripal_example_references',
  230. 'path' => "$path/theme/templates",
  231. ),
  232. 'tripal_example_synonyms' => array(
  233. 'variables' => array('node' => NULL),
  234. 'template' => 'tripal_example_synonyms',
  235. 'path' => "$path/theme/templates",
  236. ),
  237. 'tripal_example_terms' => array(
  238. 'variables' => array('node' => NULL),
  239. 'template' => 'tripal_example_terms',
  240. 'path' => "$path/theme/templates",
  241. ),
  242. // EXPLANATION: sometimes a module may want to add content to another
  243. // modules' node types. For example, the feature module does this by
  244. // adding a 'feature summary' data to an organism. To add data to another
  245. // module's node, the templates belong to this module and are
  246. // specified in the same way as above. However, the naming of the
  247. // template is changed to include the name of the module that supplies
  248. // the node type followed by our record name:
  249. // tripal_organism templates
  250. 'tripal_organism_examples' => array(
  251. 'variables' => array('node' => NULL),
  252. 'template' => 'tripal_organism_examples',
  253. 'path' => "$path/theme/templates",
  254. ),
  255. // tripal_feature templates
  256. 'tripal_feature_examples' => array(
  257. 'variables' => array('node' => NULL),
  258. 'template' => 'tripal_feature_examples',
  259. 'path' => "$path/theme/templates",
  260. ),
  261. );
  262. return $items;
  263. }
  264. /**
  265. * Implements hook_help()
  266. *
  267. * Adds a help page to the module list
  268. */
  269. function tripal_example_help ($path, $arg) {
  270. // EXPLANATION: in the tripal_example_menu() function above we created
  271. // a menu item for the help documentation. The menu item specified
  272. // a function that should be called when the menu item is clicked. This
  273. // is that function. But, rather than place HTML code in this function
  274. // we want to have our help documentation in a template file. We
  275. // specified in the tripal_example_theme() function that we have a template
  276. // file so now we want to use get the contents of that template file and
  277. // return it.
  278. if ($path == 'admin/help#tripal_example') {
  279. return theme('tripal_example_help', array());
  280. }
  281. }
  282. /**
  283. * Implements hook_cron()
  284. *
  285. * @ingroup tripal_example
  286. */
  287. function tripal_example_cron() {
  288. // EXPLANATION: here we can add any code that needs to be executed when
  289. // the Drupal cron is run.
  290. }
  291. /**
  292. * Implementation of hook_form_alter()
  293. *
  294. * Allows a module to alter any form prior to it being rendered. For more
  295. * details about Drupal's Form API see this page:
  296. *
  297. * https://api.drupal.org/api/drupal/includes!form.inc/group/form_api/7
  298. *
  299. */
  300. function tripal_example_form_alter(&$form, &$form_state, $form_id) {
  301. if ($form_id == "chado_example_node_form") {
  302. // EXPLANATION: The hook_form_alter() Drupal hook is used to alter
  303. // a form before it is displayed. This allows any module to provide new
  304. // form elements or change the form that another module creates. We do
  305. // not need to alter a form created by another module, but we do want to
  306. // alter the form for our new node type. For example, all node types
  307. // will automatically have a 'Preview' button. For inserting or updating
  308. // data for Chado we don't really need a Preview button and it complicates
  309. // the form. So, we use the following code to disable the Preview button.
  310. // if you want to keep the preview button then remove this code.
  311. // turn of preview button for insert/updates
  312. $form['actions']['preview']['#access'] = FALSE;
  313. // EXPLANATION: Drupal always adds a 'body' field to all node types.
  314. // Our node type doens't use the 'body' field so we remove it from the form.
  315. unset($form['body']);
  316. }
  317. }