public function sio__annotation_widget::submit

3.x sio__annotation_widget.inc public sio__annotation_widget::submit($form, &$form_state, $entity_type, $entity, $langcode, $delta)

Overrides TripalFieldWidget::submit

See also

TripalFieldWidget::submit()

File

tripal_chado/includes/TripalFields/sio__annotation/sio__annotation_widget.inc, line 182

Class

sio__annotation_widget

Code

public function submit($form, &$form_state, $entity_type, $entity, $langcode, $delta) {
  $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'];
  $base_table = $this->instance['settings']['base_table'];

  // Get the FK that links to the base record.
  $schema = chado_get_schema($field_table);
  $pkey = $schema['primary key'][0];
  $fkey_lcolumn = key($schema['foreign keys'][$base_table]['columns']);
  $fkey_rcolumn = $schema['foreign keys'][$base_table]['columns'][$fkey_lcolumn];

  $vocabulary = chado_get_semweb_term('cvterm', 'cv_id');
  $accession = chado_get_semweb_term('dbxref', 'accession');
  $definition = chado_get_semweb_term('cvterm', 'definition');
  if (array_key_exists('is_not', $schema['fields'])) {
    $negation = chado_get_semweb_term($field_table, 'is_not');
  }

  $record_id = $form_state['values'][$field_name]['und'][$delta]['chado-' . $field_table . '__' . $pkey];
  $fk_value = $form_state['values'][$field_name]['und'][$delta]['chado-' . $field_table . '__' . $fkey_lcolumn];

  // If a publication ID was provided then make sure the form_state
  // value for the pub_id is set correctly.
  if (array_key_exists('pub_id', $schema['fields'])) {
    $pub_name = $form_state['values'][$field_name]['und'][$delta]['pub'];
    if ($pub_name) {
      $pub = chado_generate_var('pub', array('uniquename' => $pub_name));
      if ($pub) {
        $form_state['values'][$field_name][$langcode][$delta]['chado-' . $field_table . '__pub_id'] = $pub->pub_id;
      }
    }
    // Use the NULL pub.
    else {
      $pub = chado_get_publication(array('uniquename' => 'null'));
      $form_state['values'][$field_name][$langcode][$delta]['chado-' . $field_table . '__pub_id'] = $pub->pub_id;
    }
  }

  // Make sure the rank is set.
  if (array_key_exists('rank', $schema['fields'])) {
    $rank = $form_state['values'][$field_name]['und'][$delta]['_weight'];
    $form_state['values'][$field_name]['und'][$delta]['chado-' . $field_table . '__rank'] = $rank;
  }

  // Get the term that matches.
  $cvterm_name = $form_state['values'][$field_name]['und'][$delta]['cvterm_name'];
  $cv_id = $form_state['values'][$field_name]['und'][$delta]['cv_id'];
  $cvterm = chado_generate_var('cvterm', array(
    'cv_id' => $cv_id,
    'name' => $cvterm_name,
  ));
  if ($cvterm) {
    $form_state['values'][$field_name]['und'][$delta]['cvterm_name'] = '';
    $form_state['values'][$field_name]['und'][$delta]['chado-' . $field_table . '__cvterm_id'] = $cvterm->cvterm_id;
    $form_state['values'][$field_name]['und'][$delta]['value'] = $cvterm->cvterm_id;
  }
  // Remove all values so we can delete this record if there is no
  // cvterm.
  else {
    // There must be some value set.
    $form_state['values'][$field_name]['und'][$delta]['value'] = 'delete_me';
    $form_state['values'][$field_name]['und'][$delta]['chado-' . $field_table . '__cvterm_id'] = '';
    $form_state['values'][$field_name]['und'][$delta]['chado-' . $field_table . '__' . $fkey_lcolumn] = '';
    if (array_key_exists('rank', $schema['fields'])) {
      $form_state['values'][$field_name]['und'][$delta]['chado-' . $field_table . '__rank'] = '';
    }
    if (array_key_exists('pub_id', $schema['fields'])) {
      $form_state['values'][$field_name]['und'][$delta]['chado-' . $field_table . '__pub_id'] = '';
    }
    if (array_key_exists('is_not', $schema['fields'])) {
      $form_state['values'][$field_name]['und'][$delta]['chado-' . $field_table . '_is_not'] = '';
    }
  }
}