tripal_library.chado_node.inc 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720
  1. <?php
  2. /**
  3. * @file
  4. * Implements the library node content type
  5. */
  6. /**
  7. * Implements hook_node_info().
  8. *
  9. * Provide information to drupal about the node types that we're creating
  10. * in this module
  11. *
  12. * @ingroup tripal_legacy_library
  13. */
  14. function tripal_library_node_info() {
  15. $nodes = [];
  16. $nodes['chado_library'] = [
  17. 'name' => t('Library (Tripal v2 legacy)'),
  18. 'base' => 'chado_library',
  19. 'description' => t('A library from the chado database'),
  20. 'has_title' => TRUE,
  21. 'locked' => TRUE,
  22. 'chado_node_api' => [
  23. 'base_table' => 'library',
  24. 'hook_prefix' => 'chado_library',
  25. 'record_type_title' => [
  26. 'singular' => t('Library'),
  27. 'plural' => t('Libraries'),
  28. ],
  29. 'sync_filters' => [
  30. 'type_id' => TRUE,
  31. 'organism_id' => TRUE,
  32. ],
  33. ],
  34. ];
  35. return $nodes;
  36. }
  37. /**
  38. * Implements hook_form().
  39. *
  40. * When editing or creating a new node of type 'chado_library' we need
  41. * a form. This function creates the form that will be used for this.
  42. *
  43. * @ingroup tripal_legacy_library
  44. */
  45. function chado_library_form($node, &$form_state) {
  46. $form = [];
  47. // Default values can come in the following ways:
  48. //
  49. // 1) as elements of the $node object. This occurs when editing an existing library
  50. // 2) in the $form_state['values'] array which occurs on a failed validation or
  51. // ajax callbacks from non submit form elements
  52. // 3) in the $form_state['input'] array which occurs on ajax callbacks from submit
  53. // form elements and the form is being rebuilt
  54. //
  55. // set form field defaults
  56. $library_id = NULL;
  57. $libraryname = '';
  58. $uniquename = '';
  59. $library_type = '';
  60. $organism_id = '';
  61. $description = '';
  62. // if we are editing an existing node then the library is already part of the node
  63. if (property_exists($node, 'library')) {
  64. $library = $node->library;
  65. $library_id = $library->library_id;
  66. $libraryname = $library->name;
  67. $uniquename = $library->uniquename;
  68. $library_type = $library->type_id->cvterm_id;
  69. $organism_id = $library->organism_id->organism_id;
  70. $libprop = chado_get_property(
  71. ['table' => 'library', 'id' => $library->library_id],
  72. ['type_name' => 'Library Description', 'cv_name' => 'library_property']
  73. );
  74. $description = $libprop->value;
  75. // keep track of the library id if we have. If we do have one then
  76. // this is an update as opposed to an insert.
  77. $form['library_id'] = [
  78. '#type' => 'value',
  79. '#value' => $library_id,
  80. ];
  81. }
  82. // if we are re constructing the form from a failed validation or ajax callback
  83. // then use the $form_state['values'] values
  84. if (array_key_exists('values', $form_state)) {
  85. $libraryname = $form_state['values']['libraryname'];
  86. $uniquename = $form_state['values']['uniquename'];
  87. $library_type = $form_state['values']['library_type'];
  88. $organism_id = $form_state['values']['organism_id'];
  89. $description = $form_state['values']['description'];
  90. }
  91. // if we are re building the form from after submission (from ajax call) then
  92. // the values are in the $form_state['input'] array
  93. if (array_key_exists('input', $form_state) and !empty($form_state['input'])) {
  94. $libraryname = $form_state['input']['libraryname'];
  95. $uniquename = $form_state['input']['uniquename'];
  96. $library_type = $form_state['input']['library_type'];
  97. $organism_id = $form_state['input']['organism_id'];
  98. $description = $form_state['input']['description'];
  99. }
  100. $form['libraryname'] = [
  101. '#type' => 'textfield',
  102. '#title' => t('Library Name'),
  103. '#description' => t('Please enter the name for this library. Library names should be recognizable but do not need to be unique.'),
  104. '#required' => TRUE,
  105. '#default_value' => $libraryname,
  106. ];
  107. $form['uniquename'] = [
  108. '#type' => 'textfield',
  109. '#title' => t('Unique Name'),
  110. '#description' => t('Please enter a unique name for this library. This can be any value used to uniquely identify a library.'),
  111. '#required' => TRUE,
  112. '#default_value' => $uniquename,
  113. ];
  114. // get the list of library types
  115. $lt_cv = tripal_get_default_cv("library", "type_id");
  116. $types = tripal_get_cvterm_default_select_options('library', 'type_id', 'library types');
  117. $types[0] = 'Select a Type';
  118. $lt_message = tripal_set_message("To add additional items to the library type drop down list,
  119. add a term to the " .
  120. l($lt_cv->name . " controlled vocabulary",
  121. "admin/tripal/loaders/chado_vocabs/chado_cv/" . $lt_cv->cv_id . "/cvterm/add",
  122. ['attributes' => ['target' => '_blank']]
  123. ),
  124. TRIPAL_INFO, ['return_html' => TRUE]
  125. );
  126. $form['library_type'] = [
  127. '#title' => t('Library Type'),
  128. '#type' => t('select'),
  129. '#description' => t("Choose the library type."),
  130. '#required' => TRUE,
  131. '#default_value' => $library_type,
  132. '#options' => $types,
  133. '#suffix' => $lt_message,
  134. ];
  135. // get the list of organisms
  136. $sql = "SELECT * FROM {organism}";
  137. $org_rset = chado_query($sql);
  138. $organisms = [];
  139. $organisms[''] = '';
  140. while ($organism = $org_rset->fetchObject()) {
  141. $organisms[$organism->organism_id] =
  142. "$organism->genus $organism->species ($organism->common_name)";
  143. }
  144. $form['organism_id'] = [
  145. '#title' => t('Organism'),
  146. '#type' => t('select'),
  147. '#description' => t("Choose the organism with which this library is associated."),
  148. '#required' => TRUE,
  149. '#default_value' => $organism_id,
  150. '#options' => $organisms,
  151. ];
  152. $form['description'] = [
  153. '#type' => 'text_format',
  154. '#title' => t('Library Description'),
  155. '#description' => t('A brief description of the library'),
  156. '#required' => TRUE,
  157. '#default_value' => $description,
  158. ];
  159. // PROPERTIES FORM
  160. //---------------------------------------------
  161. $prop_cv = tripal_get_default_cv('libraryprop', 'type_id');
  162. $cv_id = $prop_cv ? $prop_cv->cv_id : NULL;
  163. $details = [
  164. // The name of the prop table.
  165. 'property_table' => 'libraryprop',
  166. // The value of library_id for this record.
  167. 'chado_id' => $library_id,
  168. // The cv.cv_id of the cv governing libraryprop.type_id.
  169. 'cv_id' => $cv_id,
  170. ];
  171. // If the default is the 'library_property' vocabulary then we want
  172. // to exclude the 'Library Description' term since it has it's own form
  173. // element above
  174. if ($prop_cv->name == 'library_property') {
  175. // Generate our own select list so we can exclude the description element
  176. $select_options = [];
  177. $cv_result = chado_select_record('cv', ['cv_id'], ['name' => 'library_property']);
  178. $cv_id = $cv_result[0]->cv_id;
  179. $select_options = tripal_get_cvterm_select_options($cv_id);
  180. $descrip_id = array_search('Library Description', $select_options);
  181. unset($select_options[$descrip_id]);
  182. $details['select_options'] = $select_options;
  183. }
  184. // Adds the form elements to your current form
  185. chado_add_node_form_properties($form, $form_state, $details);
  186. // ADDITIONAL DBXREFS FORM
  187. //---------------------------------------------
  188. $details = [
  189. // The name of the _dbxref table.
  190. 'linking_table' => 'library_dbxref',
  191. // The name of the key in your base chado table.
  192. 'base_foreign_key' => 'library_id',
  193. // The value of library_id for this record.
  194. 'base_key_value' => $library_id,
  195. ];
  196. // Adds the form elements to your current form
  197. chado_add_node_form_dbxrefs($form, $form_state, $details);
  198. return $form;
  199. }
  200. /**
  201. * Implements hook_validate().
  202. *
  203. * Validates submission of form when adding or updating a library node
  204. *
  205. * @ingroup tripal_legacy_library
  206. */
  207. function chado_library_validate($node, $form, &$form_state) {
  208. // We only want to validate when the node is saved.
  209. // Since this validate can be called on AJAX and Deletion of the node
  210. // we need to make this check to ensure queries are not executed
  211. // without the proper values.
  212. if (property_exists($node, "op") and $node->op != 'Save') {
  213. return;
  214. }
  215. // we are syncing if we do not have a node ID but we do have a featuremap_id. We don't
  216. // need to validate during syncing so just skip it.
  217. if (!property_exists($node, 'nid') and property_exists($node, 'library_id') and $node->library_id != 0) {
  218. return;
  219. }
  220. // trim white space from text fields
  221. $node->libraryname = property_exists($node, 'libraryname') ? trim($node->libraryname) : '';
  222. $node->uniquename = property_exists($node, 'uniquename') ? trim($node->uniquename) : '';
  223. $lib = 0;
  224. // check to make sure the unique name on the library is unique
  225. // before we try to insert into chado.
  226. if (property_exists($node, 'library_id')) {
  227. $sql = "
  228. SELECT *
  229. FROM {library}
  230. WHERE uniquename = :uname AND NOT library_id = :library_id
  231. ";
  232. $lib = chado_query($sql, [
  233. ':uname' => $node->uniquename,
  234. ':library_id' => $node->library_id,
  235. ])->fetchObject();
  236. }
  237. else {
  238. $sql = "SELECT * FROM {library} WHERE uniquename = :uname";
  239. $lib = chado_query($sql, [':uname' => $node->uniquename])->fetchObject();
  240. }
  241. if ($lib) {
  242. form_set_error('uniquename', t('The unique library name already exists. Please choose another'));
  243. }
  244. }
  245. /**
  246. * Implements hook_insert().
  247. *
  248. * When a new chado_library node is created we also need to add information
  249. * to our chado_library table. This function is called on insert of a new node
  250. * of type 'chado_library' and inserts the necessary information.
  251. *
  252. * @ingroup tripal_legacy_library
  253. */
  254. function chado_library_insert($node) {
  255. $library_id = '';
  256. // if there is an library_id in the $node object then this must be a sync so
  257. // we can skip adding the library as it is already there, although
  258. // we do need to proceed with insertion into the chado/drupal linking table.
  259. if (!property_exists($node, 'library_id')) {
  260. $node->libraryname = trim($node->libraryname);
  261. $node->uniquename = trim($node->uniquename);
  262. $node->description = trim($node->description['value']);
  263. $values = [
  264. 'name' => $node->libraryname,
  265. 'uniquename' => $node->uniquename,
  266. 'organism_id' => $node->organism_id,
  267. 'type_id' => $node->library_type,
  268. ];
  269. $library = chado_insert_record('library', $values);
  270. if (!$library) {
  271. drupal_set_message(t('Unable to add library.', 'warning'));
  272. watchdog('tripal_library', 'Insert library: Unable to create library where values: %values',
  273. ['%values' => print_r($values, TRUE)], WATCHDOG_ERROR);
  274. return;
  275. }
  276. $library_id = $library['library_id'];
  277. // * Properties Form *
  278. // add the description property
  279. $properties = chado_retrieve_node_form_properties($node);
  280. $descrip_id = tripal_get_cvterm([
  281. 'name' => 'Library Description',
  282. 'cv_id' => ['name' => 'library_property'],
  283. ]);
  284. $properties[$descrip_id->cvterm_id][0] = $node->description;
  285. $details = [
  286. 'property_table' => 'libraryprop',
  287. // the name of the prop table
  288. 'base_table' => 'library',
  289. // the name of your chado base table
  290. 'foreignkey_name' => 'library_id',
  291. // the name of the key in your base table
  292. 'foreignkey_value' => $library_id
  293. // the value of the library_id key
  294. ];
  295. chado_update_node_form_properties($node, $details, $properties);
  296. // * Additional DBxrefs Form *
  297. $details = [
  298. 'linking_table' => 'library_dbxref',
  299. // the name of your _dbxref table
  300. 'foreignkey_name' => 'library_id',
  301. // the name of the key in your base table
  302. 'foreignkey_value' => $library_id
  303. // the value of the library_id key
  304. ];
  305. chado_update_node_form_dbxrefs($node, $details);
  306. }
  307. else {
  308. $library_id = $node->library_id;
  309. }
  310. // Make sure the entry for this library doesn't already exist in the
  311. // chado_library table if it doesn't exist then we want to add it.
  312. $check_org_id = chado_get_id_from_nid('library', $node->nid);
  313. if (!$check_org_id) {
  314. $record = new stdClass();
  315. $record->nid = $node->nid;
  316. $record->vid = $node->vid;
  317. $record->library_id = $library_id;
  318. drupal_write_record('chado_library', $record);
  319. }
  320. }
  321. /**
  322. * Implements hook_update().
  323. *
  324. * @ingroup tripal_legacy_library
  325. */
  326. function chado_library_update($node) {
  327. $node->libraryname = trim($node->libraryname);
  328. $node->uniquename = trim($node->uniquename);
  329. $node->description = trim($node->description['value']);
  330. // update the library record
  331. $library_id = chado_get_id_from_nid('library', $node->nid);
  332. $match = [
  333. 'library_id' => $library_id,
  334. ];
  335. $values = [
  336. 'name' => $node->libraryname,
  337. 'uniquename' => $node->uniquename,
  338. 'organism_id' => $node->organism_id,
  339. 'type_id' => $node->library_type,
  340. ];
  341. $status = chado_update_record('library', $match, $values);
  342. if (!$status) {
  343. drupal_set_message(t('Unable to update library.', 'warning'));
  344. watchdog('tripal_library', 'Update library: Unable to update library where values: %values',
  345. ['%values' => print_r($values, TRUE)], WATCHDOG_ERROR);
  346. }
  347. // * Properties Form *
  348. // add the description property
  349. $properties = chado_retrieve_node_form_properties($node);
  350. $descrip_id = tripal_get_cvterm([
  351. 'name' => 'Library Description',
  352. 'cv_id' => ['name' => 'library_property'],
  353. ]);
  354. $properties[$descrip_id->cvterm_id][0] = $node->description;
  355. $details = [
  356. 'property_table' => 'libraryprop',
  357. // the name of the prop table
  358. 'base_table' => 'library',
  359. // the name of your chado base table
  360. 'foreignkey_name' => 'library_id',
  361. // the name of the key in your base table
  362. 'foreignkey_value' => $library_id
  363. // the value of the library_id key
  364. ];
  365. chado_update_node_form_properties($node, $details, $properties);
  366. // * Additional DBxrefs Form *
  367. $details = [
  368. 'linking_table' => 'library_dbxref',
  369. // the name of your _dbxref table
  370. 'foreignkey_name' => 'library_id',
  371. // the name of the key in your base table
  372. 'foreignkey_value' => $library_id
  373. // the value of the library_id key
  374. ];
  375. chado_update_node_form_dbxrefs($node, $details);
  376. }
  377. /**
  378. * Implements hook_load().
  379. *
  380. * When a node is requested by the user this function is called to allow us
  381. * to add auxiliary data to the node object.
  382. *
  383. * @ingroup tripal_legacy_library
  384. */
  385. function chado_library_load($nodes) {
  386. foreach ($nodes as $nid => $node) {
  387. // get the feature details from chado
  388. $library_id = chado_get_id_from_nid('library', $node->nid);
  389. // if the nid does not have a matching record then skip this node.
  390. // this can happen with orphaned nodes.
  391. if (!$library_id) {
  392. continue;
  393. }
  394. $values = ['library_id' => $library_id];
  395. $library = chado_generate_var('library', $values);
  396. // the uniquename field is a text field so we need to expand it
  397. $library = chado_expand_var($library, 'field', 'library.uniquename');
  398. $nodes[$nid]->library = $library;
  399. // Now get the title
  400. $node->title = chado_get_node_title($node);
  401. }
  402. }
  403. /**
  404. * Implements hook_delete().
  405. *
  406. * Delete data from drupal and chado databases when a node is deleted
  407. *
  408. * @ingroup tripal_legacy_library
  409. */
  410. function chado_library_delete(&$node) {
  411. $library_id = chado_get_id_from_nid('library', $node->nid);
  412. // if we don't have a library id for this node then this isn't a node of
  413. // type chado_library or the entry in the chado_library table was lost.
  414. if (!$library_id) {
  415. return;
  416. }
  417. // Remove data from {chado_library}, {node} and {node_revisions} tables of
  418. // drupal database
  419. $sql_del = "DELETE FROM {chado_library} WHERE nid = :nid AND vid = :vid";
  420. db_query($sql_del, [':nid' => $node->nid, ':vid' => $node->vid]);
  421. $sql_del = "DELETE FROM {node_revision} WHERE nid = :nid AND vid = :vid";
  422. db_query($sql_del, [':nid' => $node->nid, ':vid' => $node->vid]);
  423. $sql_del = "DELETE FROM {node} WHERE nid = :nid AND vid = :vid";
  424. db_query($sql_del, [':nid' => $node->nid, ':vid' => $node->vid]);
  425. // Remove data from library and libraryprop tables of chado database as well
  426. chado_query("DELETE FROM {libraryprop} WHERE library_id = :library_id", [':library_id' => $library_id]);
  427. chado_query("DELETE FROM {library} WHERE library_id = :library_id", [':library_id' => $library_id]);
  428. }
  429. /**
  430. * Implement hook_node_access().
  431. *
  432. * This hook allows node modules to limit access to the node types they define.
  433. *
  434. * @param $node
  435. * The node on which the operation is to be performed, or, if it does not yet
  436. * exist, the type of node to be created
  437. *
  438. * @param $op
  439. * The operation to be performed
  440. *
  441. * @param $account
  442. * A user object representing the user for whom the operation is to be
  443. * performed
  444. *
  445. * @return
  446. * If the permission for the specified operation is not set then return FALSE.
  447. * If the permission is set then return NULL as this allows other modules to
  448. * disable access. The only exception is when the $op == 'create'. We will
  449. * always return TRUE if the permission is set.
  450. *
  451. * @ingroup tripal_legacy_library
  452. */
  453. function tripal_library_node_access($node, $op, $account) {
  454. $node_type = $node;
  455. if (is_object($node)) {
  456. $node_type = $node->type;
  457. }
  458. if ($node_type == 'chado_library') {
  459. if ($op == 'create') {
  460. if (!user_access('create chado_library content', $account)) {
  461. return NODE_ACCESS_DENY;
  462. }
  463. return NODE_ACCESS_ALLOW;
  464. }
  465. if ($op == 'update') {
  466. if (!user_access('edit chado_library content', $account)) {
  467. return NODE_ACCESS_DENY;
  468. }
  469. }
  470. if ($op == 'delete') {
  471. if (!user_access('delete chado_library content', $account)) {
  472. return NODE_ACCESS_DENY;
  473. }
  474. }
  475. if ($op == 'view') {
  476. if (!user_access('access chado_library content', $account)) {
  477. return NODE_ACCESS_DENY;
  478. }
  479. }
  480. return NODE_ACCESS_IGNORE;
  481. }
  482. }
  483. /**
  484. * Implements hook_node_view(). Acts on all content types
  485. *
  486. * @ingroup tripal_legacy_library
  487. */
  488. function tripal_library_node_view($node, $view_mode, $langcode) {
  489. switch ($node->type) {
  490. case 'chado_library':
  491. if ($view_mode == 'full') {
  492. $node->content['tripal_library_base'] = [
  493. '#theme' => 'tripal_library_base',
  494. '#node' => $node,
  495. '#tripal_toc_id' => 'base',
  496. '#tripal_toc_title' => 'Overview',
  497. '#weight' => -100,
  498. ];
  499. $node->content['tripal_library_features'] = [
  500. '#theme' => 'tripal_library_features',
  501. '#node' => $node,
  502. '#tripal_toc_id' => 'features',
  503. '#tripal_toc_title' => 'Features',
  504. ];
  505. $node->content['tripal_library_properties'] = [
  506. '#theme' => 'tripal_library_properties',
  507. '#node' => $node,
  508. '#tripal_toc_id' => 'properties',
  509. '#tripal_toc_title' => 'Properties',
  510. ];
  511. $node->content['tripal_library_publications'] = [
  512. '#theme' => 'tripal_library_publications',
  513. '#node' => $node,
  514. '#tripal_toc_id' => 'publications',
  515. '#tripal_toc_title' => 'Publications',
  516. ];
  517. $node->content['tripal_library_references'] = [
  518. '#theme' => 'tripal_library_references',
  519. '#node' => $node,
  520. '#tripal_toc_id' => 'references',
  521. '#tripal_toc_title' => 'Cross References',
  522. ];
  523. $node->content['tripal_library_synonyms'] = [
  524. '#theme' => 'tripal_library_synonyms',
  525. '#node' => $node,
  526. '#tripal_toc_id' => 'synonyms',
  527. '#tripal_toc_title' => 'Synonyms',
  528. ];
  529. $node->content['tripal_library_terms'] = [
  530. '#theme' => 'tripal_library_terms',
  531. '#node' => $node,
  532. '#tripal_toc_id' => 'terms',
  533. '#tripal_toc_title' => 'Annotated Terms',
  534. ];
  535. }
  536. if ($view_mode == 'teaser') {
  537. $node->content['tripal_library_teaser'] = [
  538. '#theme' => 'tripal_library_teaser',
  539. '#node' => $node,
  540. ];
  541. }
  542. break;
  543. case 'chado_organism':
  544. if ($view_mode == 'full') {
  545. $node->content['tripal_organism_libraries'] = [
  546. '#theme' => 'tripal_organism_libraries',
  547. '#node' => $node,
  548. '#tripal_toc_id' => 'libraries',
  549. '#tripal_toc_title' => 'Libraries',
  550. ];
  551. }
  552. break;
  553. case 'chado_feature':
  554. if ($view_mode == 'full') {
  555. $node->content['tripal_feature_libraries'] = [
  556. '#theme' => 'tripal_feature_libraries',
  557. '#node' => $node,
  558. '#tripal_toc_id' => 'libraries',
  559. '#tripal_toc_title' => 'Libraries',
  560. ];
  561. }
  562. break;
  563. }
  564. }
  565. /**
  566. * Implements hook_node_presave(). Acts on all node content types.
  567. *
  568. * @ingroup tripal_legacy_library
  569. */
  570. function tripal_library_node_presave($node) {
  571. switch ($node->type) {
  572. // This step is for setting the title for the Drupal node. This title
  573. // is permanent and thus is created to be unique. Title changes provided
  574. // by tokens are generated on the fly dynamically, but the node title
  575. // seen in the content listing needs to be set here. Do not call
  576. // the chado_get_node_title() function here to set the title as the node
  577. // object isn't properly filled out and the function will fail.
  578. case 'chado_library':
  579. // for a form submission the 'libraryname' field will be set,
  580. // for a sync, we must pull from the library object
  581. if (property_exists($node, 'libraryname')) {
  582. // set the title
  583. $node->title = $node->libraryname;
  584. }
  585. else {
  586. if (property_exists($node, 'library')) {
  587. $node->title = $node->library->name;
  588. }
  589. }
  590. break;
  591. }
  592. }
  593. /**
  594. * Implements hook_node_insert().
  595. * Acts on all content types.
  596. *
  597. * @ingroup tripal_legacy_library
  598. */
  599. function tripal_library_node_insert($node) {
  600. switch ($node->type) {
  601. case 'chado_library':
  602. $library_id = chado_get_id_from_nid('library', $node->nid);
  603. $values = ['library_id' => $library_id];
  604. $library = chado_generate_var('library', $values);
  605. $library = chado_expand_var($library, 'field', 'library.uniquename');
  606. $node->library = $library;
  607. // Now get the title
  608. $node->title = chado_get_node_title($node);
  609. // Now use the API to set the path.
  610. chado_set_node_url($node);
  611. break;
  612. }
  613. }
  614. /**
  615. * Implements hook_node_update().
  616. * Acts on all content types.
  617. *
  618. * @ingroup tripal_legacy_library
  619. */
  620. function tripal_library_node_update($node) {
  621. switch ($node->type) {
  622. case 'chado_library':
  623. // Now get the title
  624. $node->title = chado_get_node_title($node);
  625. // Now use the API to set the path.
  626. chado_set_node_url($node);
  627. break;
  628. }
  629. }
  630. /**
  631. * Implements [content_type]_chado_node_default_title_format().
  632. *
  633. * Defines a default title format for the Chado Node API to set the titles on
  634. * Chado library nodes based on chado fields.
  635. */
  636. function chado_library_chado_node_default_title_format() {
  637. return '[library.name], [library.uniquename] ([library.type_id>cvterm.name])';
  638. }
  639. /**
  640. * Implements hook_chado_node_default_url_format().
  641. *
  642. * Designates a default URL format for library nodes.
  643. */
  644. function chado_library_chado_node_default_url_format() {
  645. return '/library/[library.organism_id>organism.genus]/[library.organism_id>organism.species]/[library.type_id>cvterm.name]/[library.uniquename]';
  646. }