فهرست منبع

Publication Field: Ensure not rendered if no publications are attached.

Lacey Sanderson 6 سال پیش
والد
کامیت
a7b338e17f

+ 17 - 10
tripal_chado/includes/TripalFields/schema__publication/schema__publication.inc

@@ -83,13 +83,18 @@ class schema__publication extends ChadoField {
     $field_table = $this->instance['settings']['chado_table'];
     $field_column = $this->instance['settings']['chado_column'];
     $base_table = $this->instance['settings']['base_table'];
-    
+
     // These fields are used when the publications come through a linker table.
     $pkey = '';
     $fkey_lcolumn = '';
     $fkey_rcolumn = '';
-    $linker_table = '';   
-    
+    $linker_table = '';
+
+    // If we don't have a chado record return before creating a stub for this field!
+    if (!$record) {
+      return;
+    }
+
     // If the field table and the base table are not the same thing then
     // we are going through a linker table.
     if ($field_table != $base_table) {
@@ -116,10 +121,6 @@ class schema__publication extends ChadoField {
         'chado-' . $field_table . '__' . $field_column => '',
       );
     }
-    
-    if (!$record) {
-      return;
-    }
 
     // Get the list of publications
     $pubs = array();
@@ -132,7 +133,7 @@ class schema__publication extends ChadoField {
         $i = 0;
         foreach ($record->$linker_table as $index => $linker) {
           $pub = $linker->pub_id;
-          $pubs[$pub->pub_id] = $pub;          
+          $pubs[$pub->pub_id] = $pub;
         }
       }
     }
@@ -142,7 +143,13 @@ class schema__publication extends ChadoField {
         $pubs[$pub->pub_id] = $pub;
       }
     }
-    
+
+    // Ensure we don't have a value if there are no publications.
+    // This is needed due to stubbing out the field above.
+    if (sizeof($pubs) == 0) {
+      unset($entity->{$field_name});
+    }
+
     $i = 0;
     foreach ($pubs as $pub_id => $pub) {
       $pub_details = chado_get_minimal_pub_info($pub);
@@ -163,4 +170,4 @@ class schema__publication extends ChadoField {
       $i++;
     }
   }
-}
+}

+ 5 - 0
tripal_chado/includes/TripalFields/schema__publication/schema__publication_formatter.inc

@@ -15,6 +15,11 @@ class schema__publication_formatter extends ChadoFieldFormatter {
     $list_items = array();
     $chado_table = $this->instance['settings']['chado_table'];
 
+    // If there are no items, we don't want to return any markup.
+    if (empty($items)) {
+      return;
+    }
+
     foreach ($items as $delta => $item) {
 
       $title = isset($item['value']['TPUB:0000039']) ? $item['value']['TPUB:0000039'] : '';