tripal_example.module

This file contains all Drupal hooks for the module other than any node hooks and block hooks. Those go in the [module name].chado_node.inc file and [module_name].blocks.inc respectively

File

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