1 field.default.inc | field_default_validate($entity_type, $entity, $field, $instance, $langcode, $items, &$errors) |
Generic field validation handler.
Possible error codes:
- 'field_cardinality': The number of values exceeds the field cardinality.
Parameters
$entity_type: The type of $entity.
$entity: The entity for the operation.
$field: The field structure for the operation.
$instance: The instance structure for $field on $entity's bundle.
$langcode: The language associated to $items.
$items: $entity->{$field['field_name']}[$langcode], or an empty array if unset.
$errors: The array of errors, keyed by field name and by value delta, that have already been reported for the entity. The function should add its errors to this array. Each error is an associative array, with the following keys and values:
- 'error': an error code (should be a string, prefixed with the module name)
- 'message': the human readable message to be displayed.
See also
_hook_field_validate()
File
- core/
modules/ field/ field.default.inc, line 73 - Default 'implementations' of hook_field_*(): common field housekeeping.
Code
function field_default_validate($entity_type, $entity, $field, $instance, $langcode, $items, &$errors) {
// Filter out empty values.
$items = _field_filter_items($field, $items);
// Check that the number of values doesn't exceed the field cardinality.
// For form submitted values, this can only happen with 'multiple value'
// widgets.
if ($field['cardinality'] != FIELD_CARDINALITY_UNLIMITED && count($items) > $field['cardinality']) {
$errors[$field['field_name']][$langcode][0][] = array(
'error' => 'field_cardinality',
'message' => t('%name: this field cannot hold more than @count values.', array('%name' => $instance['label'], '@count' => $field['cardinality'])),
);
}
}