public function data__accession_widget::validate
3.x data__accession_widget.inc | public data__accession_widget::validate($element, $form, &$form_state, $langcode, $delta) |
Overrides TripalFieldWidget::validate
See also
File
- tripal_chado/
includes/ TripalFields/ data__accession/ data__accession_widget.inc, line 86
Class
Code
public function validate($element, $form, &$form_state, $langcode, $delta) {
$field_name = $this->field['field_name'];
$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'];
$dbxref_id = $form_state['values'][$field_name]['und'][$delta]['chado-' . $field_table . '__dbxref_id'];
$db_id = $form_state['values'][$field_name]['und'][$delta]['db_id'];
$accession = $form_state['values'][$field_name]['und'][$delta]['accession'];
// If user did not select a database, we want to remove dbxref_id from the
// field. We use '__NULL__' because this field is part of the base table
// and this tells the Chado backend to insert a null rather than an empty
// string.
if (!$db_id) {
$form_state['values'][$field_name]['und'][$delta]['chado-' . $field_table . '__dbxref_id'] = '__NULL__';
}
// If the dbxref_id does not match the db_id + accession then the user
// has selected a new dbxref record and we need to update the hidden
// value accordingly.
if ($db_id and $accession) {
$dbxref = chado_generate_var('dbxref', array('db_id' => $db_id, 'accession' => $accession));
if ($dbxref and $dbxref->dbxref_id != $dbxref_id) {
$form_state['values'][$field_name]['und'][$delta]['chado-' . $field_table . '__dbxref_id'] = $dbxref->dbxref_id;
$form_state['values'][$field_name]['und'][$delta]['value'] = $dbxref->dbxref_id;
}
}
}