Browse Source

Update pub search links to point to entities if they exist

Chun-Huai Cheng 7 years ago
parent
commit
bcd3503812
1 changed files with 14 additions and 2 deletions
  1. 14 2
      legacy/tripal_pub/includes/tripal_pub.pub_search.inc

+ 14 - 2
legacy/tripal_pub/includes/tripal_pub.pub_search.inc

@@ -67,8 +67,20 @@ function tripal_pub_search_page() {
       // if we have the citation then use it, otherwise, just use the title
       $title = htmlspecialchars($pub->title);
       $result = $title;
-      if ($pub->nid) {
-        $result = l($title ,'node/' . $pub->nid, array('attributes' => array('target' => '_blank')));
+      $link = NULL;
+      // tripal v2 link (node)
+      $nid = chado_get_nid_from_id ('pub', $pub->pub_id);
+      if ($nid) {
+        $link = "/node/$nid";
+      }
+      // try tripal v3 link (entity), if it exists, update the link to entity
+      $entity_id = tripal_get_chado_entity_id ('pub', $pub->pub_id);
+      if ($entity_id) {
+        $link = "/bio_data/$entity_id";
+      }
+      
+      if ($link) {
+        $result = l($title , $link, array('attributes' => array('target' => '_blank')));
       }
       if ($citation_rec->value) {
         $citation = htmlspecialchars($citation_rec->value);