Browse Source

review and revise protocol field

Vlad Dracula 7 years ago
parent
commit
51788677e2

+ 19 - 20
tripal_chado/includes/TripalFields/sep__protocol/sep__protocol.inc

@@ -1,21 +1,15 @@
 <?php
+
 /**
  * @class
- * Purpose:
+ * Purpose: Provide a field for Protocol (typically the protocol_id column of a
+ *   Chado table).
  *
  * Data:
  * Assumptions:
  */
 class sep__protocol extends ChadoField {
 
-  // --------------------------------------------------------------------------
-  //                     EDITABLE STATIC CONSTANTS
-  //
-  // The following constants SHOULD be set for each descendant class.  They are
-  // used by the static functions to provide information to Drupal about
-  // the field and it's default widget and formatter.
-  // --------------------------------------------------------------------------
-
   // The default label for this field.
   public static $default_label = 'Protocol';
 
@@ -113,14 +107,12 @@ class sep__protocol extends ChadoField {
    */
   public function load($entity) {
 
-    // ChadoFields automatically load the chado column specified in the
-    // default settings above. If that is all you need then you don't even
-    // need to implement this function. However, if you need to add any
-    // additional data to be used in the display, you should add it here.
     parent::load($entity);
 
 
     $record = $entity->chado_record;
+    $settings = $this->instance['settings'];
+
 
     $field_name = $this->field['field_name'];
     $field_type = $this->field['type'];
@@ -128,23 +120,30 @@ class sep__protocol extends ChadoField {
     $field_column = $this->instance['settings']['chado_column'];
     $linker_field = 'chado-' . $field_table . '__protocol_id';
 
+    // Set some defaults for the empty record.
+    $entity->{$field_name}['und'][0] = [
+      'value' => [],
+    ];
+
+    if (!$record->protocol_id->protocol_id) {
+      return;
+    }
+
     $protocol_id = $record->protocol_id->protocol_id;
     $protocol_name = $record->protocol_id->name;
 
     $entity_id = $record->entity_id;
 
-    $entity->{$field_name}['und'][0]['value'] = array(
-     "protocol_id" => $protocol_id,
+    $entity->{$field_name}['und'][0]['value'] = [
+      "protocol_id" => $protocol_id,
       "protocol_name" => $protocol_name,
       "entity_id" => $entity_id,
-      "full_record" => $record,
-      "instance" => $this->instance
-    );
+    ];
 
-    // Is there a published entity for this organism?
+    // Is there a published entity for this protocol?
     if (property_exists($record->{$field_column}, 'entity_id')) {
       $entity->{$field_name}['und'][0]['value']['entity_id'] = 'TripalEntity:' . $record->{$field_column}->entity_id;
-   }
+    }
   }
 
 }

+ 11 - 10
tripal_chado/includes/TripalFields/sep__protocol/sep__protocol_formatter.inc

@@ -81,20 +81,21 @@ class sep__protocol_formatter extends ChadoFieldFormatter {
    *    hook_field_formatter_view() function.
    */
   public function view(&$element, $entity_type, $entity, $langcode, $items, $display) {
-
-    $protocol_id = $items[0]['value']["protocol_id"];
-    $protocol_name = $items[0]['value']["protocol_name"];
-    $content = $protocol_name;
-    list($entity_type, $entity_id) = explode(':', $items[0]['value']['entity_id']);
-    if ($entity_id) {
-      $content = l($protocol_name, 'bio_data/' . $entity_id);
+    if (count($items) > 0) {
+      $protocol_id = $items[0]['value']["protocol_id"];
+      $protocol_name = $items[0]['value']["protocol_name"];
+      $content = $protocol_name;
+      list($entity_type, $entity_id) = explode(':', $items[0]['value']['entity_id']);
+      if ($entity_id) {
+        $content = l($protocol_name, 'bio_data/' . $entity_id);
+      }
     }
 
-
-    $element[0] = array(
+    //cardinality for this field is 1
+    $element[0] = [
       '#type' => 'markup',
       '#markup' => $content,
-    );
+    ];
   }
 
 

+ 0 - 1
tripal_chado/includes/TripalFields/sep__protocol/sep__protocol_widget.inc

@@ -4,7 +4,6 @@
  * @class
  * Purpose:
  *
- * Allowing edit?
  * Data:
  * Assumptions:
  */