Browse Source

protocol selector now displays

bradfordcondon 7 years ago
parent
commit
705640eb1d

+ 31 - 13
tripal_chado/includes/TripalFields/sep__protocol/sep__protocol.inc

@@ -36,16 +36,16 @@ class sep__protocol extends ChadoField {
   // Drupal will automatically change these settings for all fields.
   // Once instances exist for a field type then these settings cannot be
   // changed.
-  public static $default_settings = array(
+  public static $default_settings = [
     'storage' => 'field_chado_storage',
-     // It is expected that all fields set a 'value' in the load() function.
-     // In many cases, the value may be an associative array of key/value pairs.
-     // In order for Tripal to provide context for all data, the keys should
-     // be a controlled vocabulary term (e.g. rdfs:type). Keys in the load()
-     // function that are supported by the query() function should be
-     // listed here.
-     'searchable_keys' => array(),
-  );
+    // It is expected that all fields set a 'value' in the load() function.
+    // In many cases, the value may be an associative array of key/value pairs.
+    // In order for Tripal to provide context for all data, the keys should
+    // be a controlled vocabulary term (e.g. rdfs:type). Keys in the load()
+    // function that are supported by the query() function should be
+    // listed here.
+    'searchable_keys' => [],
+  ];
 
   // Provide a list of instance specific settings. These can be access within
   // the instanceSettingsForm.  When the instanceSettingsForm is submitted
@@ -54,7 +54,7 @@ class sep__protocol extends ChadoField {
   // If you override this variable in a child class be sure to replicate the
   // term_name, term_vocab, term_accession and term_fixed keys as these are
   // required for all TripalFields.
-  public static $default_instance_settings = array(
+  public static $default_instance_settings = [
     // The DATABASE name, as it appears in chado.db.  This also builds the link-out url.  In most cases this will simply be the CV name.  In some cases (EDAM) this will be the SUBONTOLOGY.
     'term_vocabulary' => 'sep',
     // The name of the term.
@@ -70,7 +70,7 @@ class sep__protocol extends ChadoField {
     // should have auto_attach set to FALSE so tha their values can be
     // attached asynchronously.
     'auto_attach' => FALSE,
-  );
+  ];
 
   // A boolean specifying that users should not be allowed to create
   // fields and instances of this field type through the UI. Such
@@ -84,7 +84,7 @@ class sep__protocol extends ChadoField {
   // the user but otherwise provides no data.
   public static $no_data = FALSE;
 
- /**
+  /**
    * Loads the field values from the underlying data store.
    *
    * @param $entity
@@ -118,5 +118,23 @@ class sep__protocol extends ChadoField {
     // 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'];
+    $field_table = $this->instance['settings']['chado_table'];
+    $field_column = $this->instance['settings']['chado_column'];
+    $linker_field = 'chado-' . $field_table . '__organism_id';
+
+    $protocol_id = $record->protocol_id;
+
+    $entity->{$field_name}['und'][0]['value'] = array(
+     "protocol_id" => $protocol_id,
+
+    );
   }
-}
+
+}

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

@@ -1,4 +1,5 @@
 <?php
+
 /**
  * @class
  * Purpose:
@@ -12,12 +13,12 @@ class sep__protocol_formatter extends ChadoFieldFormatter {
   public static $default_label = 'Protocol';
 
   // The list of field types for which this formatter is appropriate.
-  public static $field_types = array('sep__protocol');
+  public static $field_types = ['sep__protocol'];
 
   // The list of default settings for this formatter.
-  public static $default_settings = array(
+  public static $default_settings = [
     'setting1' => 'default_value',
-  );
+  ];
 
   /**
    * Provides the field's setting form.
@@ -68,14 +69,14 @@ class sep__protocol_formatter extends ChadoFieldFormatter {
    *  into a CSV file will always be identical.  The view need not show all
    *  of the data in the 'values' array.
    *
-   *  @param $element
-   *  @param $entity_type
-   *  @param $entity
-   *  @param $langcode
-   *  @param $items
-   *  @param $display
+   * @param $element
+   * @param $entity_type
+   * @param $entity
+   * @param $langcode
+   * @param $items
+   * @param $display
    *
-   *  @return
+   * @return
    *    An element array compatible with that returned by the
    *    hook_field_formatter_view() function.
    */
@@ -83,8 +84,16 @@ class sep__protocol_formatter extends ChadoFieldFormatter {
 
     // Get the settings
     $settings = $display['settings'];
+
+    $entity_id = "something";
+
+    if (count($items) > 0) {
+      $content = l("Protocol Name goes here", 'bio_data/' . $entity_id);
+    }
+
   }
 
+
   /**
    * Provides a summary of the formatter settings.
    *

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

@@ -1,4 +1,5 @@
 <?php
+
 /**
  * @class
  * Purpose:
@@ -13,7 +14,7 @@ class sep__protocol_widget extends ChadoFieldWidget {
   public static $default_label = 'Protocol';
 
   // The list of field types for which this formatter is appropriate.
-  public static $field_types = array('sep__protocol');
+  public static $field_types = ['sep__protocol'];
 
   /**
    * Provides the form for editing of this field.
@@ -72,6 +73,37 @@ class sep__protocol_widget extends ChadoFieldWidget {
    */
   public function form(&$widget, &$form, &$form_state, $langcode, $items, $delta, $element) {
     parent::form($widget, $form, $form_state, $langcode, $items, $delta, $element);
+
+
+    $settings = $this->field['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';
+
+    dpm($this->field);
+    dpm($this->instance);
+
+    $protocols = [];
+    //options are all Contacts
+    $sql = "SELECT * FROM {protocol}";
+    $results = chado_query($sql);
+    foreach ($results as $protocol) {
+      $protocols[$protocol->protocol_id] = $protocol->name;
+    }
+
+    $widget[$linker_field] = [
+      '#type' => 'select',
+      '#title' => $element['#title'],
+      '#description' => $element['#description'],
+      '#options' => $protocols,
+      '#empty_option' => '- Select a Protocol -',
+      '#required' => $element['#required'],
+      '#weight' => isset($element['#weight']) ? $element['#weight'] : 0,
+      '#delta' => $delta,
+    ];
+
   }
 
   /**