Browse Source

Merge branch '7.x-3.x' of github.com:tripal/tripal into 7.x-3.x

Stephen Ficklin 7 years ago
parent
commit
2218af3e69

+ 5 - 0
tripal_chado/includes/TripalFields/uo__unit/uo__unit.inc

@@ -56,6 +56,11 @@ class uo__unit extends ChadoField {
 
     if ($record) {
       $entity->{$field_name}['und'][0]['value'] = $record->unittype_id->name;
+      $entity->{$field_name}['und'][0]['chado-' . $field_table . '__unittype_id'] = $record->unittype_id->cvterm_id;
+      $entity->{$field_name}['und'][0]['chado-cvterm__name'] = $record->unittype_id->name;
+      $entity->{$field_name}['und'][0]['chado-cvterm__definition'] = $record->unittype_id->definition;
+      $entity->{$field_name}['und'][0]['chado-cvterm__cv_id'] = $record->unittype_id->cv_id->cv_id;
+      $entity->{$field_name}['und'][0]['chado-cv__name'] = $record->unittype_id->cv_id->name;
     }
   }
 }

+ 42 - 1
tripal_chado/includes/TripalFields/uo__unit/uo__unit_widget.inc

@@ -16,6 +16,47 @@ class uo__unit_widget extends ChadoFieldWidget {
 
     parent::form($widget, $form, $form_state, $langcode, $items, $delta, $element);
 
-    // TODO: add a form for changing the unit types.
+    $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'];
+
+    $unittype_id = 0;
+    if (count($items) > 0 and array_key_exists('chado-' . $field_table . '__unittype_id', $items[0])) {
+      $unittype_id = $items[0]['chado-' . $field_table . '__unittype_id'];
+    }
+
+    $widget['value'] = array(
+      '#type' => 'value',
+      '#value' => array_key_exists($delta, $items) ? $items[$delta]['value'] : '',
+    );
+    $cv = tripal_get_cv(array('name' => 'featuremap_units'));
+    $options = tripal_get_cvterm_select_options($cv->cv_id);
+    unset($options[0]);
+    $widget['chado-' . $field_table . '__unittype_id'] = array(
+      '#type' => 'select',
+      '#title' => $element['#title'],
+      '#description' => $element['#description'],
+      '#options' => $options,
+      '#default_value' => $unittype_id,
+      '#empty_option' => '- Select a Unit -',
+      '#required' => $element['#required'],
+      '#weight' => isset($element['#weight']) ? $element['#weight'] : 0,
+      '#delta' => $delta,
+    );
+  }
+
+  /**
+   * @see TripalFieldWidget::validate()
+   */
+  public function validate($element, $form, &$form_state, $langcode, $delta) {
+
+    $field_name = $this->field['field_name'];
+    $field_table = $this->instance['settings']['chado_table'];
+
+    // Make sure the value is set to the organism_id
+    $unittype_id = $form_state['values'][$field_name]['und'][0]['chado-' . $field_table . '__unittype_id'];
+    $form_state['values'][$field_name]['und'][0]['value'] = $unittype_id;
   }
 }