function field_default_form_errors in Drupal 7
Transfer field-level validation errors to widgets.
1 call to field_default_form_errors()
- field_ui_field_edit_form_validate in modules/
field_ui/ field_ui.admin.inc - Form validation handler for field_ui_field_edit_form().
1 invocation of field_default_form_errors()
- field_attach_form_validate in modules/
field/ field.attach.inc - Perform field validation against form-submitted field values.
File
- modules/
field/ field.form.inc, line 400 - Field forms management.
Code
function field_default_form_errors($entity_type, $entity, $field, $instance, $langcode, $items, $form, &$form_state) {
$field_state = field_form_get_state($form['#parents'], $field['field_name'], $langcode, $form_state);
if (!empty($field_state['errors'])) {
// Locate the correct element in the form.
$element = drupal_array_get_nested_value($form_state['complete form'], $field_state['array_parents']);
// Only set errors if the element is accessible.
if (!isset($element['#access']) || $element['#access']) {
$function = $instance['widget']['module'] . '_field_widget_error';
$function_exists = function_exists($function);
$multiple_widget = field_behaviors_widget('multiple values', $instance) != FIELD_BEHAVIOR_DEFAULT;
foreach ($field_state['errors'] as $delta => $delta_errors) {
// For multiple single-value widgets, pass errors by delta.
// For a multiple-value widget, pass all errors to the main widget.
$error_element = $multiple_widget ? $element : $element[$delta];
foreach ($delta_errors as $error) {
if ($function_exists) {
$function($error_element, $error, $form, $form_state);
}
else {
// Make sure that errors are reported (even incorrectly flagged) if
// the widget module fails to implement hook_field_widget_error().
form_error($error_element, $error['message']);
}
}
}
// Reinitialize the errors list for the next submit.
$field_state['errors'] = array();
field_form_set_state($form['#parents'], $field['field_name'], $langcode, $form_state, $field_state);
}
}
}