public function local__contact_widget::validate

3.x local__contact_widget.inc public local__contact_widget::validate($element, $form, &$form_state, $langcode, $delta)

Overrides TripalFieldWidget::validate

See also

TripalFieldWidget::submit()

File

tripal_chado/includes/TripalFields/local__contact/local__contact_widget.inc, line 89

Class

local__contact_widget

Code

public function validate($element, $form, &$form_state, $langcode, $delta) {
  $field_name = $this->field['field_name'];
  $field_type = $this->field['type'];
  $base_table = $this->instance['settings']['base_table'];
  $field_table = $this->instance['settings']['chado_table'];
  $chado_column = $this->instance['settings']['chado_column'];
  $instance = $this->instance;

  // Get information about this contact linke rtable.
  $schema = chado_get_schema($field_table);
  $pkey = $schema['primary key'][0];

  // Get the name from the form state.
  $name = $form_state['values'][$field_name]['und'][$delta]['name'];

  // Set the linker field appropriately.
  if ($field_table == 'biomaterial') {
    $linker_field = 'chado-biomaterial__biosourceprovider_id';
  }
  else {
    $linker_field = 'chado-' . $field_table . '__contact_id';
  }

  // If the user provided a name then we want to set the foreign key
  // value to be the chado_record_id
  if ($name) {
    $contact = chado_generate_var('contact', array('name' => $name));
    if ($contact) {
      $form_state['values'][$field_name]['und'][$delta][$linker_field] = $contact->contact_id;
      $form_state['values'][$field_name]['und'][$delta]['value'] = $name;
    }
  }
  // If no name is provided then we want to set the field for deletion.
  else {
    $form_state['values'][$field_name]['und'][$delta][$linker_field] = '';
  }
}