public function FlexiformElementField::formValidate in Flexiform 7
Validate this element.
This is effectively the same as field_attach_form_validate passed with the field_name options, except that we have replaced _field_invoke and _field_invoke_default with our own methods to make sure the correct field settings get used.
Overrides FlexiformElement::formValidate
See also
File
- includes/
element/ field.element.inc, line 457 - Contains FlexiformElementField class.
Class
- FlexiformElementField
- Class for Field API elements.
Code
public function formValidate($form, &$form_state, $entity, $language = LANGUAGE_NONE) {
$entity = clone $entity;
$form_elements = $this
->extractFormElements($form);
$this
->fieldInvokeDefault('extract_form_values', $entity, $form_elements, $form_state);
try {
$errors = array();
$null = NULL;
$this
->fieldInvokeDefault('validate', $entity, $errors, $null);
$this
->fieldInvoke('validate', $entity, $errors, $null);
// Let other modules validate the entity.
foreach (module_implements('field_attach_validate') as $module) {
$function = $module . '_field_attach_validate';
$function($this
->getEntityType(), $entity, $errors);
}
if ($errors) {
throw new FieldValidationException($errors);
}
} catch (FieldValidationException $e) {
// Pass field-level validation errors back to widgets for accurate error
// flagging.
foreach ($e->errors as $field_name => $field_errors) {
foreach ($field_errors as $langcode => $errors) {
$field_state = field_form_get_state($form_elements['#parents'], $field_name, $langcode, $form_state);
$field_state['errors'] = $errors;
field_form_set_state($form_elements['#parents'], $field_name, $langcode, $form_state, $field_state);
}
}
$this
->fieldInvokeDefault('form_errors', $entity, $form_elements, $form_state);
}
}