Jelajahi Sumber

Merge pull request #1168 from dsenalik/20210211sbo__relationship

20210211sbo  relationship
Stephen Ficklin 4 tahun lalu
induk
melakukan
a4f88da4fe

+ 1 - 1
tripal_chado/api/modules/tripal_chado.pub.api.inc

@@ -315,7 +315,7 @@ function chado_autocomplete_pub($string = '') {
   ";
   $pubs = chado_query($sql, [':str' => $string . '%']);
   while ($pub = $pubs->fetchObject()) {
-    $val = $pub->title . " [id:" . $pub->pub_id . "]";
+    $val = $pub->title . " [id: " . $pub->pub_id . "]";
     $items[$val] = $pub->title;
   }
 

+ 15 - 2
tripal_chado/includes/TripalFields/sbo__relationship/sbo__relationship.inc

@@ -248,15 +248,20 @@ class sbo__relationship extends ChadoField {
       case 'quantification_relationship':
       case 'element_relationship':
       case 'project_relationship':
+        $this->base_name_columns = ['name'];
+        $this->base_type_column = 'table_name';
+        break;
+
       case 'pub_relationship':
+        $this->base_name_columns = ['title'];
         $this->base_type_column = 'table_name';
-        $this->base_name_columns = ['name'];
-      break;
+        break;
 
       case 'organism_relationship':
         $this->base_name_columns = ['genus', 'species'];
         $this->base_type_column = 'table_name';
         break;
+
       case 'phylonode_relationship':
         $this->base_name_columns = ['label'];
         $this->base_type_column = 'table_name';
@@ -266,6 +271,7 @@ class sbo__relationship extends ChadoField {
         $this->base_name_columns = ['name'];
         $this->base_type_column = 'type_id';
         break;
+
       default:
         // @todo update this to use the schema.
         $this->base_name_columns = ['name'];
@@ -419,6 +425,13 @@ class sbo__relationship extends ChadoField {
     // @todo grab these separately like it was before.
     $subject_pkey = $object_pkey = $this->base_schema['primary key'][0];
 
+    // A publication title can exceed the character limit for chado_expand_var()
+    // so make sure it has been added.
+    // TODO Should this step be generalized to other content type that could have a long name?
+    if (in_array('pub.title', $relationship->expandable_fields)) {
+      $relationship = chado_expand_var($relationship, 'field', 'pub.title', []);
+    }
+
     $entity->{$field_name}['und'][$delta]['value'] = [
       'local:relationship_subject' => $this->getRelationshipSubject($relationship),
       'local:relationship_type' => $relationship->type_id->name,

+ 2 - 2
tripal_chado/includes/TripalFields/schema__publication/schema__publication_widget.inc

@@ -58,7 +58,7 @@ class schema__publication_widget extends ChadoFieldWidget {
       $pub_id = tripal_get_field_item_keyval($items, $delta, $pub_item_id, $pub_id);
       if ($pub_id) {
         $pub = chado_get_publication(['pub_id' => $pub_id]);
-        $title = $pub->title . ' [id:' . $pub->pub_id . ']';
+        $title = $pub->title . ' [id: ' . $pub->pub_id . ']';
       }
     }
 
@@ -122,7 +122,7 @@ class schema__publication_widget extends ChadoFieldWidget {
     $title = $form_state['values'][$field_name]['und'][$delta]['pub_title'];
     if ($title) {
       $matches = [];
-      if (preg_match('/^.*\[id:(\d+)]$/', $title, $matches)) {
+      if (preg_match('/^.*\[id: (\d+)]$/', $title, $matches)) {
         $pub_id = $matches[1];
         $pub = chado_generate_var('pub', ['pub_id' => $pub_id]);
         $form_state['values'][$field_name]['und'][$delta]['chado-' . $field_table . '__pub_id'] = $pub->pub_id;