Browse Source

Merge branch '762-relationship-widget-fixes' of github.com:tripal/tripal into 762-relationship-widget-fixes

Stephen Ficklin 6 years ago
parent
commit
d9c25118bc

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

@@ -294,7 +294,7 @@ class sbo__relationship extends ChadoField {
 
     // Retrieve the type.
     $type = $this->instance['settings']['base_table'];
-    if ((!$this->base_type_column == 'table_name') AND isset($relationship->{$this->subject_id_column}->{$this->base_type_column})) {
+    if (($this->base_type_column != 'table_name') AND isset($relationship->{$this->subject_id_column}->{$this->base_type_column})) {
       $type_object = $relationship->{$this->subject_id_column}->{$this->base_type_column};
       if (isset($type_object->name)) {
         $type = $type_object->name;
@@ -307,8 +307,6 @@ class sbo__relationship extends ChadoField {
     $record = [
       'rdfs:type' => $type,
       'schema:name' => implode(' ', $name),
-      // @todo support the entity and determine whether this is current one or not.
-      //'entity' => 'TripalEntity:' . $entity->id,
     ];
 
     // If the object has a uniquename then add that in for refernce.
@@ -352,7 +350,7 @@ class sbo__relationship extends ChadoField {
 
     // Retrieve the Type.
     $type = $this->instance['settings']['base_table'];
-    if ((!$this->base_type_column == 'table_name') AND isset($relationship->{$this->object_id_column}->{$this->base_type_column})) {
+    if (($this->base_type_column != 'table_name') AND isset($relationship->{$this->object_id_column}->{$this->base_type_column})) {
       $type_object = $relationship->{$this->object_id_column}->{$this->base_type_column};
       if (isset($type_object->name)) {
         $type = $type_object->name;
@@ -365,8 +363,6 @@ class sbo__relationship extends ChadoField {
     $record = [
       'rdfs:type' => $type,
       'schema:name' => implode(' ', $name),
-      // @todo support the entity and determine whether this is current one or not.
-      //'entity' => 'TripalEntity:' . $entity->id,
     ];
 
     // If the object has a unqiuename then add that in for reference.

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

@@ -82,8 +82,10 @@ class sbo__relationship_formatter extends ChadoFieldFormatter {
       }
 
       // Add bold font to the object and subject names.
-      $phrase = preg_replace("/$subject_type/", "<b>$subject_type</b>", $phrase);
-      $phrase = preg_replace("/$object_type/", "<b>$object_type</b>", $phrase);
+      // @todo add back in bolding...
+      // @todo Fix Current Bug: if type name is in the object name, wierd bolding happens.
+      // $phrase = preg_replace("/$subject_type/", "<b>$subject_type</b>", $phrase);
+      // $phrase = preg_replace("/$object_type/", "<b>$object_type</b>", $phrase);
 
       // Convert the object/subject to a link if an entity exists for it.
       if (array_key_exists('entity', $item['value']['local:relationship_object'])) {

+ 12 - 0
tripal_chado/includes/TripalFields/sbo__relationship/sbo__relationship_widget.inc

@@ -346,6 +346,18 @@ class sbo__relationship_widget extends ChadoFieldWidget {
       return;
     }
 
+    // Catch the case where a user is trying to remove a relationship.
+    if (!$type_name && !$subject_name && !$object_name) {
+      $form_state['values'][$field_name][$langcode][$delta]['chado-' . $field_table . '__' . $subject_id_key] = '';
+      $form_state['values'][$field_name][$langcode][$delta]['chado-' . $field_table . '__' . $object_id_key] = '';
+      $form_state['values'][$field_name][$langcode][$delta]['chado-' . $field_table . '__type_id'] = '';
+      $form_state['values'][$field_name][$langcode][$delta]['chado-' . $field_table . '__value'] = '';
+      if (array_key_exists('rank', $this->schema['fields'])) {
+        $form_state['values'][$field_name][$langcode][$delta]['chado-' . $field_table . '__rank'] = '';
+      }
+      return;
+    }
+
     // Do not proceed if subject ID or object ID does not exist
     if (!key_exists($subject_id_key, $fkeys[$base_table]['columns']) ||
         !key_exists($object_id_key, $fkeys[$base_table]['columns'])) {