tripal_example.module 15 KB

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