tripal_example.chado_node.inc 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652
  1. <?php
  2. /**
  3. * @file
  4. * This file should contain all Drupal hooks for interacting with nodes.
  5. *
  6. */
  7. /**
  8. * Implementation of hook_node_info(). This hook provides information to drupal
  9. * about any node types that are being created by this module. If your module
  10. * does not create any node types then this function is not required.
  11. *
  12. * @ingroup tripal_example
  13. */
  14. function tripal_example_node_info() {
  15. $nodes = array();
  16. //$nodes['chado_example'] = array(
  17. // 'name' => t('Example'),
  18. // 'base' => 'chado_example',
  19. // 'description' => t('A example from the chado database'),
  20. // 'has_title' => TRUE,
  21. // 'locked' => TRUE
  22. // This section of the node type array specifies how Tripal will sync the node
  23. // types with data in Chado. When Drupal creates a node it has no way of
  24. // coordinating which node belongs to which record in Chado. Therefore,
  25. // Tripal maintains tables in the Drupal schema that maps Drupal nodes
  26. // to recrords in Chado. Syncing is the process of creating Drupal nodes
  27. // and linking them to the appropriate record.
  28. // 'chado_node_api' => array(
  29. // 'base_table' => 'example', // the base table name (e.g. feature, example, contact)
  30. // 'hook_prefix' => 'chado_example',// the node type hook prefix
  31. // 'record_type_title' => array(
  32. // 'singular' => t('Library'), // how to refer to the record
  33. // 'plural' => t('Libraries') // how to refer to the record in plurals
  34. // ),
  35. // 'sync_filters' => array(
  36. // 'type_id' => TRUE, // if the record has a type_id set to TRUE
  37. // 'organism_id' => TRUE // if the record has an organism_id set to TRUE
  38. // ),
  39. // )
  40. //);
  41. return $nodes;
  42. }
  43. /**
  44. * Implement hook_access(). This hook provides instructions to
  45. * drupal for which users can access the custom content types
  46. * created in the function above. The available permissions
  47. * are set in the chado_example_permissions() hook in the
  48. * tripal_example.module file. This hook is not needed
  49. * if no node types were defined in the hook_node_info() hook.
  50. *
  51. * @return
  52. * This function should return null if it does not specificially
  53. * deny access. This allows for other mechanisms to to deny
  54. * or reject access. If the return value is TRUE then access
  55. * is granted regardless of any other rules that might be implemented
  56. * by other modules.
  57. */
  58. function chado_example_node_access($node, $op, $account) {
  59. $node_type = $node;
  60. if (is_object($node)) {
  61. $node_type = $node->type;
  62. }
  63. if($node_type == 'chado_example') {
  64. if ($op == 'create') {
  65. if (!user_access('create chado_example content', $account)) {
  66. return NODE_ACCESS_DENY;
  67. }
  68. return NODE_ACCESS_ALLOW;
  69. }
  70. if ($op == 'update') {
  71. if (!user_access('edit chado_example content', $account)) {
  72. return NODE_ACCESS_DENY;
  73. }
  74. }
  75. if ($op == 'delete') {
  76. if (!user_access('delete chado_example content', $account)) {
  77. return NODE_ACCESS_DENY;
  78. }
  79. }
  80. if ($op == 'view') {
  81. if (!user_access('access chado_example content', $account)) {
  82. return NODE_ACCESS_DENY;
  83. }
  84. }
  85. }
  86. return NODE_ACCESS_IGNORE;
  87. }
  88. /**
  89. * Implementation of hook_form() when a node type of chado_example is defined.
  90. * If a node type is not defined then this function is not needed. The table
  91. * name in chado for this example module is named 'example' so there is a
  92. * corresponding example_id in that table (similar to feature.feature_id,
  93. * contact.contact_id, etc).
  94. *
  95. * @ingroup tripal_example
  96. */
  97. function chado_example_form($node, &$form_state) {
  98. $form = array();
  99. // Default values can come in the following ways:
  100. //
  101. // 1) as elements of the $node object. This occurs when editing an existing example
  102. // 2) in the $form_state['values'] array which occurs on a failed validation or
  103. // ajax callbacks from non submit form elements
  104. // 3) in the $form_state['input'[ array which occurs on ajax callbacks from submit
  105. // form elements and the form is being rebuilt
  106. //
  107. // set form field defaults
  108. // if we are editing an existing node then the example is already part of the node
  109. if (property_exists($node, 'example')) {
  110. // $example = $node->example;
  111. // $example = chado_expand_var($example, 'field', 'example.residues');
  112. // $example_id = $example->example_id;
  113. // $uniquename = $example->uniquename;
  114. // keep track of the example id
  115. //$form['example_id'] = array(
  116. // '#type' => 'value',
  117. // '#value' => $example_id,
  118. //);
  119. }
  120. // if we are re constructing the form from a failed validation or ajax callback
  121. // then use the $form_state['values'] values
  122. if (array_key_exists('values', $form_state)) {
  123. // $uniquename = $form_state['values']['uniquename'];
  124. }
  125. // if we are re building the form from after submission (from ajax call) then
  126. // the values are in the $form_state['input'] array
  127. if (array_key_exists('input', $form_state) and !empty($form_state['input'])) {
  128. // $uniquename = $form_state['input']['uniquename'];
  129. }
  130. // NOTE: if the table has a 'type_id' column, be sure to use the
  131. // tripal_get_default_cv('example', 'type_id') to get the site's
  132. // default vocabulary.
  133. // PROPERTIES FORM
  134. //---------------------------------------------
  135. // If there is a exampleprop table and you want to allow users to add/remove entries
  136. // from it through your node form then add this section to your own node form
  137. $prop_cv = tripal_get_default_cv('exampleprop', 'type_id');
  138. $cv_id = $prop_cv ? $prop_cv->cv_id : NULL;
  139. $details = array(
  140. 'property_table' => 'exampleprop', // the name of the prop table
  141. 'chado_id' => $example_id, // the value of example_id for this record
  142. 'cv_id' => $cv_id // the cv.cv_id of the cv governing exampleprop.type_id
  143. );
  144. // Adds the form elements to your current form
  145. chado_add_node_form_properties($form, $form_state, $details);
  146. // ADDITIONAL DBXREFS FORM
  147. //---------------------------------------------
  148. // If there is a example_dbxref table and you want to allow users to add/remove entries
  149. // from it through your node form then add this section to your own node form
  150. $details = array(
  151. 'linking_table' => 'example_dbxref', // the name of the _dbxref table
  152. 'base_foreign_key' => 'example_id', // the name of the key in your base chado table
  153. 'base_key_value' => $example_id // the value of example_id for this record
  154. );
  155. // Adds the form elements to your current form
  156. chado_add_node_form_dbxrefs($form, $form_state, $details);
  157. // RELATIONSHIPS FORM
  158. //---------------------------------------------
  159. // If there is a example_relationship table and you want to allow users to add/remove entries
  160. // from it through your node form then add this section to your own node form
  161. $rels_cv = tripal_get_default_cv('example_relationship', 'type_id');
  162. $cv_id = $rels_cv ? $rels_cv->cv_id : NULL;
  163. $details = array(
  164. 'relationship_table' => 'example_relationship', // the name of the _relationship table
  165. 'base_table' => 'example', // the name of your chado base table
  166. 'base_foreign_key' => 'example_id', // the name of the key in your base chado table
  167. 'base_key_value' => $example_id, // the value of example_id for this record
  168. 'nodetype' => 'example', // the human-readable name of your node type
  169. 'cv_id' => $cv_id // the cv.cv_id of the cv governing example_relationship.type_id
  170. );
  171. // Adds the form elements to your current form
  172. chado_add_node_form_relationships($form, $form_state, $details);
  173. // return the form
  174. return $form;
  175. }
  176. /**
  177. * Implementation of hook_validate
  178. *
  179. * This validation is being used for three activities:
  180. * CASE A: Update a node that exists in both drupal and chado
  181. * CASE B: Synchronizing a node from chado to drupal
  182. * CASE C: Inserting a new node that exists in niether drupal nor chado
  183. *
  184. * @param $node
  185. *
  186. *
  187. * @ingroup tripal_example
  188. */
  189. function chado_example_validate($node, $form, &$form_state) {
  190. // if this is a delete then don't validate
  191. if($node->op == 'Delete') {
  192. return;
  193. }
  194. // we are syncing if we do not have a node ID but we do have a example_id. We don't
  195. // need to validate during syncing so just skip it.
  196. if (is_null($node->nid) and property_exists($node, 'example_id') and $node->example_id != 0) {
  197. return;
  198. }
  199. // be sure to always trim text fields
  200. // $node->uniquename = trim($node->uniquename);
  201. // Validating for an update. If the 'nid' property is present in the node then
  202. // this is an update and validation can be different for updates
  203. if (property_exists($node, 'nid')) {
  204. // if there is a problem with a field then you can set an error on the form
  205. // form_set_error('uniquename', t("example update cannot proceed. The example name '$node->uniquename' is not unique for this organism. Please provide a unique name for this example."));
  206. }
  207. // Validating for an insert
  208. else {
  209. // if there is a problem with a field then you can set an error on the form
  210. // form_set_error('uniquename', t("example insert cannot proceed. The example name '$node->uniquename' already exists for this organism. Please provide a unique name for this example."));
  211. }
  212. }
  213. /**
  214. * Implementation of hook_insert(). This function is called after the
  215. * node is inserted into the database. We need it so that we can insert
  216. * appropriate fields as provided by the user into the database. And so that
  217. * we can link the new Drupal node to the data in Chado via the chado_example
  218. * linking table. We can get to this function also during "syncing".
  219. * With syncing, however, the data already exists in Chado and we do not want
  220. * to try to re-add it. But we do need to add an entry to the chado_example table
  221. * to link the Drupal node with the data in the 'example' table of Chado.
  222. *
  223. * This function is not required if the hook_node_info() does not define
  224. * any custom node types.
  225. *
  226. * @ingroup tripal_example
  227. */
  228. function chado_example_insert($node) {
  229. // be sure to always trim text fields
  230. //$node->uniquename = trim($node->uniquename);
  231. // if there is an example_id in the $node object then this must be a sync so
  232. // we can skip adding the example as it is already there, although
  233. // we do need to proceed with the rest of the insert
  234. if (!property_exists($node, 'example_id')) {
  235. // ADD TO CHADO
  236. // * Example Table *
  237. // perform the insert using the tripal_core_chado_insert function();
  238. //$values = array(
  239. // 'uniquename' => $node->uniquename,
  240. // 'residues' => $residues,
  241. //);
  242. //$example = chado_select_record('example', array('*'), $values);
  243. //if (!$example) {
  244. // drupal_set_message(t('Unable to add example.'), 'warning');
  245. // tripal_report_error('tripal_example', TRIPAL_WARNING, 'Insert example: Unable to create example where values: %values',
  246. // array('%values' => print_r($values, TRUE)));
  247. // return;
  248. //}
  249. // get the example_id for linking Drupal node with Chado data
  250. // $example_id = $example->example_id;
  251. // Only add to other chado tables if the base record was inserted properly
  252. if ($example_id > 0) {
  253. // * Properties Form *
  254. // If you implemented the properties form in chado_example_form then you need to
  255. // handle inserting these properties into your chado prop table.
  256. // $details = array(
  257. // 'property_table' => 'exampleprop', // the name of the prop table
  258. // 'base_table' => 'example', // the name of your chado base table
  259. // 'foreignkey_name' => 'example_id', // the name of the key in your base table
  260. // 'foreignkey_value' => $example_id // the value of the example_id key
  261. // );
  262. // chado_update_node_form_properties($node, $details);
  263. // * Additional DBxrefs Form *
  264. // If you implemented the dbxrefs form in chado_example_form then you need to
  265. // handle inserting these database references into your chado _dbxref table.
  266. // $details = array(
  267. // 'linking_table' => 'example_dbxref', // the name of your _dbxref table
  268. // 'foreignkey_name' => 'example_id', // the name of the key in your base table
  269. // 'foreignkey_value' => $example_id // the value of the example_id key
  270. // );
  271. // chado_update_node_form_dbxrefs($node, $details);
  272. // * Relationships Form *
  273. // If you implemented the relationships form in chado_example_form then you need to
  274. // handle inserting these relationships into your chado _relationship table.
  275. // $details = array(
  276. // 'relationship_table' => 'example_relationship', // name of the _relationship table
  277. // 'foreignkey_value' => $example_id // value of the example_id key
  278. // );
  279. // chado_update_node_form_relationships($node, $details);
  280. }
  281. }
  282. else {
  283. // the node has an example_id so get it for linking Drupal node with Chado data
  284. // $example_id = $node->example_id;
  285. }
  286. // Make sure the entry for this example doesn't already exist in the
  287. // chado_example table if it doesn't exist then we want to add it.
  288. // $check_org_id = chado_get_id_from_nid('example', $node->nid);
  289. //if (!$check_org_id) {
  290. // $record = new stdClass();
  291. // $record->nid = $node->nid;
  292. // $record->vid = $node->vid;
  293. // $record->example_id = $example_id;
  294. // drupal_write_record('chado_example', $record);
  295. //}
  296. }
  297. /**
  298. * Implementation of hook_update(). This function runs after the
  299. * node has been inserted into the Drupal schema and allows us to
  300. * update the record in Chado.
  301. *
  302. * This function is not required if the hook_node_info() does not define
  303. * any custom node types.
  304. *
  305. * @ingroup tripal_example
  306. */
  307. function chado_example_update($node) {
  308. // be sure to always trim text fields
  309. // $node->uniquename = trim($node->uniquename);
  310. // use the chado_update_record() function to update the record
  311. //$match = array(
  312. //'example_id' => $example_id,
  313. //);
  314. //$values = array(
  315. // 'uniquename' => $node->uniquename,
  316. //);
  317. //$options = array('return_record' => TRUE);
  318. //$status = chado_update_record('example', $match, $values, $options);
  319. //if (!$status) {
  320. // drupal_set_message(t('Unable to update example.'), 'warning');
  321. // tripal_report_error('tripal_example', TRIPAL_WARNING, 'Update example: Unable to update example where values: %values',
  322. // array('%values' => print_r($values, TRUE)));
  323. //}
  324. // * Properties Form *
  325. // If you implemented the properties form in chado_example_form then you need to
  326. // handle updating these properties into your chado prop table.
  327. // $details = array(
  328. // 'property_table' => 'exampleprop', // the name of the prop table
  329. // 'base_table' => 'example', // the name of your chado base table
  330. // 'foreignkey_name' => 'example_id', // the name of the key in your base table
  331. // 'foreignkey_value' => $example_id // the value of the example_id key
  332. // );
  333. // chado_update_node_form_properties($node, $details);
  334. // * Additional DBxrefs Form *
  335. // If you implemented the dbxrefs form in chado_example_form then you need to
  336. // handle updating these database references into your chado _dbxref table.
  337. // $details = array(
  338. // 'linking_table' => 'example_dbxref', // the name of your _dbxref table
  339. // 'foreignkey_name' => 'example_id', // the name of the key in your base table
  340. // 'foreignkey_value' => $example_id // the value of the example_id key
  341. // );
  342. // chado_update_node_form_dbxrefs($node, $details);
  343. // * Relationships Form *
  344. // If you implemented the relationships form in chado_example_form then you need to
  345. // handle updating these relationships into your chado _relationship table.
  346. // $details = array(
  347. // 'relationship_table' => 'example_relationship', // name of the _relationship table
  348. // 'foreignkey_value' => $example_id // value of the example_id key
  349. // );
  350. // chado_update_node_form_relationships($node, $details);
  351. }
  352. /**
  353. * Implementation of hook_delete(). This function runs after the
  354. * node has been deleted from the Drupal schema and allows us to
  355. * delete the corresponding recrod in Chado.
  356. *
  357. * This function is not required if the hook_node_info() does not define
  358. * any custom node types.
  359. *
  360. * @ingroup tripal_example
  361. */
  362. function chado_example_delete($node) {
  363. // get the example id from the node
  364. //$example_id = chado_get_id_from_nid('example', $node->nid);
  365. // if we don't have a example id for this node then this isn't a node of
  366. // type chado_example or the entry in the chado_example table was lost.
  367. if (!$example_id) {
  368. return;
  369. }
  370. // remove the entry in the chado_exapmle table linking the deleted
  371. // Drupal node with the data in chado
  372. // $sql_del = "DELETE FROM {chado_example} WHERE nid = :nid AND vid = :vid";
  373. // db_query($sql_del, array(':nid' => $node->nid, ':vid' => $node->vid));
  374. // Remove data from example tables of chado database. This will
  375. // cause a cascade delete and remove all data in referencing tables
  376. // for this example
  377. // chado_query("DELETE FROM {example} WHERE example_id = :example_id", array(':example_id' => $example_id));
  378. // inform the user that the data was deleted
  379. drupal_set_message(t("The example and all associated data were removed from Chado"));
  380. }
  381. /**
  382. * Implementation of hook_load(). This function is necessary to load
  383. * into the $node object the fields of the table form Chado. For example
  384. * for the feature table, the chado_feature_load() function adds in
  385. * a feature object which contains all of the fields and sub objects
  386. * for data in tables with foreign key relationships.
  387. *
  388. * This function is not required if the hook_node_info() does not define
  389. * any custom node types.
  390. *
  391. * @ingroup tripal_example
  392. */
  393. function chado_example_load($nodes) {
  394. // there may be multiple nodes that get passed in so we have to iterate through
  395. // them all
  396. foreach ($nodes as $nid => $node) {
  397. // find the example and add in the details
  398. //$example_id = chado_get_id_from_nid('example', $nid);
  399. // if the nid does not have a matching record then skip this node.
  400. // this can happen with orphaned nodes.
  401. //if (!$example_id) {
  402. // continue;
  403. //}
  404. // build the example variable by using the chado_generate_var() function
  405. //$values = array('example_id' => $example_id);
  406. //$example = chado_generate_var('example', $values);
  407. // for fields in the table that are of type 'text' you may want to include those
  408. // by default, the tripal_core_generate_chado_var does not include text fields as
  409. // they may be very large and including a large text field can slow the page load.
  410. // If you know a text field will never be large and it is important for the
  411. // other functions that will see the node to have access to a field you can
  412. // include it here using the chado_expand_var() function. In most
  413. // cases it is probably best to let the end-user decide if text fields should
  414. // be included by using this function in the templates.
  415. //$example = chado_expand_var($example, 'field', 'example.residues');
  416. // add the new example object to this node.
  417. //$nodes[$nid]->example = $example;
  418. }
  419. }
  420. /**
  421. * Implementation of hook_node_presave(). This node is useful for
  422. * making changes to the node prior to it being saved to the database.
  423. * One useful case for this is to set the title of a node. In some cases
  424. * such as for the organism module, the title will be set depending on
  425. * what genus and species is provided. This hook can allow the title to
  426. * be set using user supplied data before the node is saved. In practice
  427. * any change can be made to any fields in the node object.
  428. *
  429. * This function is not required. You probably won't need it if you
  430. * don't define a custom node type in the hook_node_info() function. But
  431. * it is node type agnostic, so you can use this function to change the
  432. * contents of any node regardless of it's type.
  433. *
  434. * @ingroup tripal_example
  435. */
  436. function tripal_example_node_presave($node) {
  437. /*
  438. // set the node title
  439. switch ($node->type) {
  440. case 'chado_example':
  441. // for a form submission the 'examplename' field will be set,
  442. // for a sync, we must pull from the example object
  443. if (property_exists($node, 'examplename')) {
  444. // set the title
  445. $node->title = $node->examplename;
  446. }
  447. else if (property_exists($node, 'example')) {
  448. $node->title = $node->example->name;
  449. }
  450. break;
  451. }
  452. */
  453. }
  454. /**
  455. * Implementation of hook node_insert(). This function is used
  456. * after any a node is inserted into the database. It is different
  457. * from the hook_insert() function above in that it is called after
  458. * any node is saved, regardlesss of it's type. This function is useful
  459. * for making changes to the database after a node is inserted when you
  460. * can't edit the hook_insert() function of a node not defined by this
  461. * module, or to access values of a node when have not yet been saved.
  462. * An example comes from the tripal_feature module where the URL alias
  463. * of a node cannot be set in the hook_insert() function. Therefore
  464. * the tripal_feature module uses this function to set the url path
  465. * of a newly inserted feature node.
  466. *
  467. * This function is not required. You probably won't need it if you
  468. * don't define a custom node type in the hook_node_info() function. But
  469. * it is node type agnostic, so you can use this function to do any
  470. * activity after insert of a node.
  471. *
  472. * @ingroup tripal_example
  473. */
  474. function tripal_example_node_insert($node) {
  475. // set the URL path after inserting. We do it here because we do not know the
  476. // example_id in the presave and cannot do it in the hook_insert()
  477. //switch ($node->type) {
  478. // case 'chado_example':
  479. // if (!$node->example_id) {
  480. // $sql = "SELECT * FROM {chado_example} WHERE nid = :nid";
  481. // $chado_example = db_query($sql, array(':nid' => $node->nid))->fetchObject();
  482. // $node->example_id = $chado_example->example_id;
  483. // }
  484. // // remove any previous alias
  485. // db_query("DELETE FROM {url_alias} WHERE source = :source", array(':source' => "node/$node->nid"));
  486. // // set the URL for this example page
  487. // $url_alias = tripal_example_get_example_url($node);
  488. // $path_alias = array("source" => "node/$node->nid", "alias" => $url_alias);
  489. // path_save($path_alias);
  490. // break;
  491. //}
  492. }
  493. /**
  494. * Implementation of hook node_update(). This function is used
  495. * after any a node is updated in the database. It is different
  496. * from the hook_update() function above in that it is called after
  497. * any node is updated, regardlesss of it's type. This function is useful
  498. * for making changes to the database after a node is updated when you
  499. * can't perform changes in the hook_upate() function of a node not defined by this
  500. * module, or to access values of a node when have not yet been updated.
  501. * An example comes from the tripal_feature module where the URL alias
  502. * of a node cannot be set in the hook_update() function. Therefore
  503. * the tripal_feature module uses this function to reset the url path
  504. * of an updated feature node.
  505. *
  506. * This function is not required. You probably won't need it if you
  507. * don't define a custom node type in the hook_node_info() function. But
  508. * it is node type agnostic, so you can use this function to do any
  509. * activity after insert of a node.
  510. *
  511. */
  512. function tripal_example_node_update($node) {
  513. // add items to other nodes, build index and search results
  514. switch ($node->type) {
  515. case 'chado_example':
  516. // remove any previous alias
  517. //db_query("DELETE FROM {url_alias} WHERE source = :source", array(':source' => "node/$node->nid"));
  518. // set the URL for this example page
  519. //$url_alias = tripal_example_get_example_url($node);
  520. //$path_alias = array("source" => "node/$node->nid", "alias" => $url_alias);
  521. //path_save($path_alias);
  522. break;
  523. }
  524. }
  525. /**
  526. * Implementation of hook_node_view(). This function allows you to
  527. * add custom content to any node page. It is node type agnostic.
  528. * Here we typically use it to add content to our custom node type or
  529. * to other Tripal node types. Typically for Tripal, a content "block"
  530. * (e.g. feature properties, feature dbxref, feature pub) has a corresponding
  531. * template file. Those template files are first defined to Drupal using
  532. * the hook_theme() function defined in the tripal_example.module file. Here
  533. * we can add items to a node's content by calling those templates as needed.
  534. *
  535. * @ingroup tripal_example
  536. */
  537. function tripal_example_node_view($node, $view_mode, $langcode) {
  538. switch ($node->type) {
  539. case 'chado_example':
  540. // there are different ways a node can be viewed. Primarily Tripal
  541. // supports full page view and teaser view.
  542. if ($view_mode == 'full') {
  543. // there is always a base template. This is the template that
  544. // is first shown when the example node type is first displayed
  545. //$node->content['tripal_example_base'] = array(
  546. // '#markup' => theme('tripal_example_base', array('node' => $node)),
  547. // '#tripal_toc_id' => 'base',
  548. // '#tripal_toc_title' => 'Overview',
  549. // '#weight' => -100,
  550. //);
  551. // we can add other templates as well.
  552. //$node->content['tripal_example_properties'] = array(
  553. // '#markup' => theme('tripal_example_properties', array('node' => $node)),
  554. // '#tripal_toc_id' => 'properties',
  555. // '#tripal_toc_title' => 'Properties',
  556. //);
  557. //$node->content['tripal_example_publications'] = array(
  558. // '#markup' => theme('tripal_example_publications', array('node' => $node)),
  559. // '#tripal_toc_id' => 'publications',
  560. // '#tripal_toc_title' => 'Publications',
  561. //);
  562. //$node->content['tripal_example_references'] = array(
  563. // '#markup' => theme('tripal_example_references', array('node' => $node)),
  564. // '#tripal_toc_id' => 'references',
  565. // '#tripal_toc_title' => 'Cross References',
  566. //);
  567. }
  568. // set the content for the teaser view
  569. if ($view_mode == 'teaser') {
  570. //$node->content['tripal_example_teaser'] = array(
  571. // '#value' => theme('tripal_example_teaser', array('node' => $node)),
  572. //);
  573. }
  574. break;
  575. // you can add custom content to any tripal node type by adding
  576. // content to the node in the same way as above.
  577. case 'chado_organism':
  578. break;
  579. case 'chado_library':
  580. break;
  581. case 'chado_stock':
  582. break;
  583. case 'chado_analysis':
  584. break;
  585. // ... etc
  586. }
  587. }