public function data__accession::validate
3.x data__accession.inc | public data__accession::validate($entity_type, $entity, $langcode, $items, &$errors) |
Overrides TripalField::validate
See also
File
- tripal_chado/
includes/ TripalFields/ data__accession/ data__accession.inc, line 124
Class
Code
public function validate($entity_type, $entity, $langcode, $items, &$errors) {
// If we don't have an entity then we don't want to validate. The case
// where this could happen is when a user is editing the field settings
// and trying to set a default value. In that case there's no entity and
// we don't want to validate. There will always be an entity for creation
// and update operations of a content type.
if (!$entity) {
return;
}
$field_name = $this->field['field_name'];
$settings = $this->field['settings'];
$field_type = $this->field['type'];
$field_table = $this->instance['settings']['chado_table'];
$field_column = $this->instance['settings']['chado_column'];
// Get the field values.
foreach ($items as $delta => $values) {
$db_id = $values['db_id'];
$accession = $values['accession'];
// Make sure that if a database ID is provided that an accession is also
// provided. Here we use the form_set_error function rather than the
// form_error function because the form_error will add a red_highlight
// around all of the fields in the fieldset which is confusing as it's not
// clear to the user what field is required and which isn't. Therefore,
// we borrow the code from the 'form_error' function and append the field
// so that the proper field is highlighted on error.
if (!$db_id and $accession) {
$errors[$field_name][$delta]['und'][] = array(
'message' => t("A database and the accession must both be provided for the primary cross reference."),
'error' => 'chado_base__dbxref',
);
}
if ($db_id and !$accession) {
$errors[$field_name][$delta]['und'][] = array(
'message' => t("A database and the accession must both be provided for the primary cross reference."),
'error' => 'chado_base__dbxref',
);
}
if (!$db_id and !$accession) {
$errors[$field_name][$delta]['und'][] = array(
'message' => t("A database and the accession must both be provided for the primary cross reference."),
'error' => 'chado_base__dbxref',
);
}
}
}