1 field.attach.inc | field_attach_validate($entity_type, $entity, $options = array()) |
Perform field validation against the field data in an entity.
This function does not perform field widget validation on form submissions. It is intended to be called during API save operations. Use field_attach_form_validate() to validate form submissions.
Parameters
$entity_type: The type of $entity; e.g. 'node' or 'user'.
$entity: The entity with fields to validate.
array $options: An associative array of additional options. See _field_invoke() for details.
Throws
FieldValidationException If validation errors are found, a FieldValidationException is thrown. The 'errors' property contains the array of errors, keyed by field name, language and delta.
Related topics
File
- core/
modules/ field/ field.attach.inc, line 737 - Field attach API, allowing entities (nodes, users, ...) to be 'fieldable'.
Code
function field_attach_validate($entity_type, $entity, $options = array()) {
// Validate $options since this is a new parameter added after Drupal 7 was
// released.
$options = is_array($options) ? $options : array();
$errors = array();
// Check generic, field-type-agnostic errors first.
$null = NULL;
_field_invoke_default('validate', $entity_type, $entity, $errors, $null, $options);
// Check field-type specific errors.
_field_invoke('validate', $entity_type, $entity, $errors, $null, $options);
// Let other modules validate the entity.
// Avoid module_invoke_all() to let $errors be taken by reference.
foreach (module_implements('field_attach_validate') as $module) {
$function = $module . '_field_attach_validate';
$function($entity_type, $entity, $errors);
}
if ($errors) {
throw new FieldValidationException($errors);
}
}