|
@@ -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;
|
|
|
}
|
|
|
}
|