Ver Fonte

Merge pull request #373 from tripal/chadoprops-norender-whenempty

Bug Fix: Ensure that empty chado property fields are not rendered.
Stephen Ficklin há 6 anos atrás
pai
commit
00df54223d

+ 11 - 1
tripal_chado/includes/TripalFields/chado_linker__prop/chado_linker__prop.inc

@@ -124,6 +124,16 @@ class chado_linker__prop extends ChadoField {
         );
       }
     }
+
+    // Ensure there are no values if there are no properties.
+    // This is necessary to make sure the field is not rendered when there are no properies.
+    // @todo: We should revisit this in the future as none of the other fields do this.
+    //        It was added here to make it easier to detect when the field was empty
+    //        but in hindsight, we would just check $entity->{$field_name}['und'][$i]['value']
+    //        in the formatter.
+    if (empty($properties)) {
+      unset($entity->{$field_name});
+    }
   }
 
   /**
@@ -168,4 +178,4 @@ class chado_linker__prop extends ChadoField {
     $this->queryJoinOnce($query, $prop_linker, $alias, "base.$bpkey = $alias.$bpkey AND $alias.type_id = $cvterm->cvterm_id", "LEFT OUTER");
     $query->orderBy("$alias.value", $order['direction']);
   }
-}
+}

+ 5 - 0
tripal_chado/includes/TripalFields/chado_linker__prop/chado_linker__prop_formatter.inc

@@ -29,6 +29,11 @@ class chado_linker__prop_formatter extends ChadoFieldFormatter {
       $list[$index] = $item['value'];
     }
 
+    // Also need to make sure to not return markup if the field is empty.
+    if (empty($list)) {
+      return;
+    }
+
     // If more than one value has been found display all values in an unordered
     // list.
     if (count($list) > 1) {