public function data__sequence_widget::form

3.x data__sequence_widget.inc public data__sequence_widget::form(&$widget, &$form, &$form_state, $langcode, $items, $delta, $element)

Overrides TripalFieldWidget::form

See also

TripalFieldWidget::form()

File

tripal_chado/includes/TripalFields/data__sequence/data__sequence_widget.inc, line 14

Class

data__sequence_widget

Code

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'];

  // Get the field defaults.
  $residues = '';
  if (count($items) > 0 and array_key_exists('value', $items[0])) {
    $residues = $items[0]['value'];
  }
  if (array_key_exists('values', $form_state) and 
    array_key_exists($field_name, $form_state['values'])) {
    $residues = $form_state['values'][$field_name][$langcode][$delta]['value'];
  }

  $widget['value'] = array(
    '#type' => 'value',
    '#value' => $residues,
  );

  $widget['chado-' . $field_table . '__' . $field_column] = array(
    '#type' => 'textarea',
    '#title' => $element['#title'],
    '#description' => $element['#description'],
    '#weight' => isset($element['#weight']) ? $element['#weight'] : 0,
    '#default_value' => $residues,
    '#delta' => $delta,
    '#cols' => 30,
  );
}