tripal_example.module 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  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_permission() {
  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. 'administer 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/extension/[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' => 'Example module for help with development of new extension modules.',
  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/extension/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/extension/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/extension/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. // EXPLANATION: If your module defines a new node type that uses the default
  137. // table of contents (left-side bar of content panes on a page). Then a
  138. // 'TOC' link will automatically appear on the node page to allow for
  139. // customization of the TOC. However those customizations are only node
  140. // specific. To provide a tab in the module's administrative pages add the
  141. // following menu item. This menu will provide a form similar to the one
  142. // found on the node that allows the user to set global TOC settings for the
  143. // content type.
  144. $items['admin/tripal/chado/tripal_example/toc'] = array(
  145. 'title' => ' TOC',
  146. 'description' => 'Manage the table of contents for example nodes.',
  147. 'page callback' => 'drupal_get_form',
  148. 'page arguments' => array('tripal_core_content_type_toc_form', 'chado_example'),
  149. 'access arguments' => array('administer tripal example'),
  150. 'type' => MENU_LOCAL_TASK,
  151. 'file' => 'includes/tripal_core.toc.inc',
  152. 'file path' => drupal_get_path('module', 'tripal_core'),
  153. 'weight' => 3
  154. );
  155. return $items;
  156. }
  157. /**
  158. * Implements hook_views_api()
  159. *
  160. * This hook tells drupal that there is views support for
  161. * for this module which then automatically includes the tripal_db.views.inc
  162. * where all the views integration code is found.
  163. *
  164. * @ingroup tripal_example
  165. */
  166. function tripal_example_views_api() {
  167. return array(
  168. 'api' => 3.0,
  169. );
  170. }
  171. /**
  172. * We need to let drupal know about our theme functions and their arguments.
  173. * We create theme functions to allow users of the module to customize the
  174. * look and feel of the output generated in this module
  175. *
  176. * @ingroup tripal_example
  177. */
  178. function tripal_example_theme($existing, $type, $theme, $path) {
  179. $core_path = drupal_get_path('module', 'tripal_core');
  180. // EXPLANATION: this function defines all of the functions and templates
  181. // that this module needs to provide content. These details are provided
  182. // in the form of an array the indicates which functions or templates
  183. // provide content. Please see the Drupal theming guide for an in-depth
  184. // description for how theming works in Drupal:
  185. // https://drupal.org/documentation/theme
  186. $items = array(
  187. // EXPLANATION: If this module defines a new node type that displays
  188. // Chado data then we should use Tripal's default node template. This
  189. // template ensures that all content provided by Tripal and Tripal
  190. // extension modules has the same look and feel. It is designed to be
  191. // generic such that it won't intefer with the look-and-feel of the default
  192. // theme. This generic template will organize the node into a table
  193. // of contents found on the left-side of the page and place the content
  194. // in the center of the page. User's will cycle through content on the
  195. // page by clicking the links in the table of contents. If you do not want
  196. // to use the default Tripal template you can change this array to your
  197. // liking.
  198. 'node__chado_example' => array(
  199. 'template' => 'node--chado-generic',
  200. 'render element' => 'node',
  201. 'base hook' => 'node',
  202. 'path' => "$core_path/theme/templates",
  203. ),
  204. // EXPLANATION: the following defines all of the template files used for
  205. // this module. Templates are named with underscores separating words, and
  206. // correspond directly to a file with the extension '.tpl.php'. For example
  207. // the 'tripal_example_base' template will have a corresponding
  208. // tripal_example_base.tpl.php file where the display code is housed.
  209. // The only required templates are the 'base', 'help' and 'teaseer' templates.
  210. // The base template provides the basic information about the record in
  211. // in Chado. The 'help' template provides the adminstrative help documenation,
  212. // and the teaser provides a brief summary of the record that can be used
  213. // as short description of the record in aggregated lists.
  214. // the base template
  215. 'tripal_example_base' => array(
  216. 'variables' => array('node' => NULL),
  217. 'template' => 'tripal_example_base',
  218. 'path' => "$path/theme/templates",
  219. ),
  220. // the help template
  221. 'tripal_example_help' => array(
  222. 'template' => 'tripal_example_help',
  223. 'variables' => array(NULL),
  224. 'path' => "$path/theme/templates",
  225. ),
  226. // the teaser template.
  227. 'tripal_example_teaser' => array(
  228. 'variables' => array('node' => NULL),
  229. 'template' => 'tripal_example_teaser',
  230. 'path' => "$path/theme/templates",
  231. ),
  232. // EXPLANATION: Typically, a different template is created for each subset of data.
  233. // for example, most Chado tables have a 'XXXXprop', 'XXXX_cvterm',
  234. // 'XXXX_dbxref', 'XXXX_synonyms', 'XXXX_relationships' tables. Therefore,
  235. // a template is created to display data from each of these tables.
  236. 'tripal_example_properties' => array(
  237. 'variables' => array('node' => NULL),
  238. 'template' => 'tripal_example_properties',
  239. 'path' => "$path/theme/templates",
  240. ),
  241. 'tripal_example_references' => array(
  242. 'variables' => array('node' => NULL),
  243. 'template' => 'tripal_example_references',
  244. 'path' => "$path/theme/templates",
  245. ),
  246. 'tripal_example_relationships' => array(
  247. 'variables' => array('node' => NULL),
  248. 'template' => 'tripal_example_relationships',
  249. 'path' => "$path/theme/templates",
  250. ),
  251. // EXPLANATION: sometimes a module may want to add content to another
  252. // modules' node types. For example, the feature module does this by
  253. // adding a 'feature summary' data to an organism. To add data to another
  254. // module's node, the templates belong to this module and are
  255. // specified in the same way as above. However, the naming of the
  256. // template is changed to include the name of the module that supplies
  257. // the node type followed by our record name:
  258. // tripal_organism templates
  259. 'tripal_organism_examples' => array(
  260. 'variables' => array('node' => NULL),
  261. 'template' => 'tripal_organism_examples',
  262. 'path' => "$path/theme/templates",
  263. ),
  264. );
  265. return $items;
  266. }
  267. /**
  268. * Implements hook_help()
  269. *
  270. * Adds a help page to the module list
  271. */
  272. function tripal_example_help ($path, $arg) {
  273. // EXPLANATION: in the tripal_example_menu() function above we created
  274. // a menu item for the help documentation. The menu item specified
  275. // a function that should be called when the menu item is clicked. This
  276. // is that function. But, rather than place HTML code in this function
  277. // we want to have our help documentation in a template file. We
  278. // specified in the tripal_example_theme() function that we have a template
  279. // file so now we want to use get the contents of that template file and
  280. // return it.
  281. if ($path == 'admin/help#tripal_example') {
  282. return theme('tripal_example_help', array());
  283. }
  284. }
  285. /**
  286. * Implements hook_cron()
  287. *
  288. * @ingroup tripal_example
  289. */
  290. function tripal_example_cron() {
  291. // EXPLANATION: here we can add any code that needs to be executed when
  292. // the Drupal cron is run.
  293. }
  294. /**
  295. * Implementation of hook_form_alter()
  296. *
  297. * Allows a module to alter any form prior to it being rendered. For more
  298. * details about Drupal's Form API see this page:
  299. *
  300. * https://api.drupal.org/api/drupal/includes!form.inc/group/form_api/7
  301. *
  302. */
  303. function tripal_example_form_alter(&$form, &$form_state, $form_id) {
  304. if ($form_id == "chado_example_node_form") {
  305. // EXPLANATION: The hook_form_alter() Drupal hook is used to alter
  306. // a form before it is displayed. This allows any module to provide new
  307. // form elements or change the form that another module creates. We do
  308. // not need to alter a form created by another module, but we do want to
  309. // alter the form for our new node type. For example, all node types
  310. // will automatically have a 'Preview' button. For inserting or updating
  311. // data for Chado we don't really need a Preview button and it complicates
  312. // the form. So, we use the following code to disable the Preview button.
  313. // if you want to keep the preview button then remove this code.
  314. // turn of preview button for insert/updates
  315. $form['actions']['preview']['#access'] = FALSE;
  316. // EXPLANATION: Drupal always adds a 'body' field to all node types.
  317. // Our node type doens't use the 'body' field so we remove it from the form.
  318. unset($form['body']);
  319. }
  320. }