Browse Source

correct field

bradfordcondon 7 years ago
parent
commit
4cd76b1c6c

+ 11 - 3
tripal_chado/includes/TripalFields/sep__protocol/sep__protocol.inc

@@ -121,20 +121,28 @@ class sep__protocol extends ChadoField {
 
 
     $record = $entity->chado_record;
-    $settings = $this->instance['settings'];
 
     $field_name = $this->field['field_name'];
     $field_type = $this->field['type'];
     $field_table = $this->instance['settings']['chado_table'];
     $field_column = $this->instance['settings']['chado_column'];
-    $linker_field = 'chado-' . $field_table . '__organism_id';
+    $linker_field = 'chado-' . $field_table . '__protocol_id';
 
     $protocol_id = $record->protocol_id;
+    $protocol_name = $record->name;
 
     $entity->{$field_name}['und'][0]['value'] = array(
      "protocol_id" => $protocol_id,
-
+      "protocol_name" => $protocol_name,
+      "full_record" => $record,
+      "field" => $this->field,
+      "instance" => $this->instance
     );
+
+    // Is there a published entity for this organism?
+    if (property_exists($record->{$field_column}, 'entity_id')) {
+      $entity->{$field_name}['und'][0]['value']['entity_id'] = 'TripalEntity:' . $record->{$field_column}->entity_id;
+   }
   }
 
 }

+ 12 - 6
tripal_chado/includes/TripalFields/sep__protocol/sep__protocol_formatter.inc

@@ -82,15 +82,21 @@ class sep__protocol_formatter extends ChadoFieldFormatter {
    */
   public function view(&$element, $entity_type, $entity, $langcode, $items, $display) {
 
-    // Get the settings
-    $settings = $display['settings'];
+    dpm($items);
+    $protocol_id = $items[0]['value']["protocol_id"];
+    $protocol_name = $items[0]['value']["protocol_name"];
+    $entity_id = $items[0]['value']["entity_id"];
+    $content = $protocol_name;
 
-    $entity_id = "something";
-
-    if (count($items) > 0) {
-      $content = l("Protocol Name goes here", 'bio_data/' . $entity_id);
+    if ($entity_id) {
+      $content = l($protocol_name, 'bio_data/' . $entity_id);
     }
 
+
+    $element[0] = array(
+      '#type' => 'markup',
+      '#markup' => $content,
+    );
   }
 
 

+ 7 - 3
tripal_chado/includes/TripalFields/sep__protocol/sep__protocol_widget.inc

@@ -80,20 +80,22 @@ class sep__protocol_widget extends ChadoFieldWidget {
     $field_type = $this->field['type'];
     $field_table = $this->instance['settings']['chado_table'];
     $field_column = $this->instance['settings']['chado_column'];
-    $linker_field = 'chado-' . $field_table . '__organism_id';
+    $linker_field = 'chado-' . $field_table . '__protocol_id';
 
     dpm($this->field);
     dpm($this->instance);
 
     $protocols = [];
-    //options are all Contacts
+    //options are all protocols
+    //It could be argued that options should only be protocols where protocol_type matches the bundle base table.
+
     $sql = "SELECT * FROM {protocol}";
     $results = chado_query($sql);
     foreach ($results as $protocol) {
       $protocols[$protocol->protocol_id] = $protocol->name;
     }
 
-    $widget[$linker_field] = [
+    $widget['value'] = [
       '#type' => 'select',
       '#title' => $element['#title'],
       '#description' => $element['#description'],
@@ -116,6 +118,8 @@ class sep__protocol_widget extends ChadoFieldWidget {
    * fields must be used to set the 'value' field.
    */
   public function validate($element, $form, &$form_state, $langcode, $delta) {
+
+    dpm($form_state);
   }
 
   /**