Browse Source

Merge pull request #912 from tripal/911_relationship_widget_name_fixes

fix bug for names of tables without type_id.  Fix bug where names wit…
Lacey-Anne Sanderson 5 years ago
parent
commit
7fbe44115b

+ 8 - 13
tripal_chado/includes/TripalFields/sbo__relationship/sbo__relationship.inc

@@ -239,34 +239,29 @@ class sbo__relationship extends ChadoField {
     $this->base_type_column = 'table_name';
     switch ($instance['settings']['chado_table']) {
 
+      // TODO: note that Chado 1.4 will add types to, at least,
+      // project and analysis, at which point you should use the default instead.
       case 'acquisition_relationship':
       case 'analysis_relationship':
       case 'biomaterial_relationship':
       case 'cell_line_relationship':
       case 'quantification_relationship':
-        $this->base_type_column = 'table_name';
-        break;
       case 'element_relationship':
-        // RELATIONSHIP->subject_id_key->feature_id->name;
-        $this->base_name_columns = ['name'];
+      case 'project_relationship':
+      case 'pub_relationship':
         $this->base_type_column = 'table_name';
-        break;
+        $this->base_name_columns = ['name'];
+      break;
+
       case 'organism_relationship':
         $this->base_name_columns = ['genus', 'species'];
         $this->base_type_column = 'table_name';
         break;
-      case 'project_relationship':
-        $this->base_name_columns = ['name'];
-        $this->base_type_column = 'table_name';
-        break;
       case 'phylonode_relationship':
         $this->base_name_columns = ['label'];
         $this->base_type_column = 'table_name';
         break;
-      case 'pub_relationship':
-        $this->base_name_columns = ['name'];
-        $this->base_type_column = 'table_name';
-        break;
+
       case 'contact':
         $this->base_name_columns = ['name'];
         $this->base_type_column = 'type_id';

+ 3 - 2
tripal_chado/includes/TripalFields/sbo__relationship/sbo__relationship_formatter.inc

@@ -96,16 +96,17 @@ class sbo__relationship_formatter extends ChadoFieldFormatter {
       // Convert the object/subject to a link if an entity exists for it.
       if (array_key_exists('entity', $item['value']['local:relationship_object'])) {
         list($entity_type, $object_entity_id) = explode(':', $item['value']['local:relationship_object']['entity']);
+
         if ($object_entity_id != $entity->id) {
           $link = l($object_name, 'bio_data/' . $object_entity_id);
-          $phrase = preg_replace("/$object_name/", $link, $phrase);
+          $phrase = str_replace($object_name, $link, $phrase);
         }
       }
       if (array_key_exists('entity', $item['value']['local:relationship_subject'])) {
         list($entity_type, $subject_entity_id) = explode(':', $item['value']['local:relationship_subject']['entity']);
         if ($subject_entity_id != $entity->id) {
           $link = l($subject_name, 'bio_data/' . $subject_entity_id);
-          $phrase = preg_replace("/$subject_name/", $link, $phrase);
+          $phrase = str_replace($subject_name, $link, $phrase);
         }
       }