function double_field_field_validate in Double Field 7
Same name and namespace in other branches
- 7.2 double_field.module \double_field_field_validate()
Implements hook_field_validate().
File
- ./
double_field.module, line 62 - Defines double text field type.
Code
function double_field_field_validate($entity_type, $entity, $field, $instance, $langcode, $items, &$errors) {
$settings = $instance['widget']['settings'];
if ($entity_type && $instance['required']) {
$error = array(
'error' => 'double_field_required',
'error_element' => array(
'first' => TRUE,
'second' => TRUE,
),
'message' => t('%name field is required.', array(
'%name' => $instance['label'],
)),
);
$field_is_empty = TRUE;
foreach ($items as $delta => $item) {
if ($item['first'] !== '' || $item['second'] !== '') {
$field_is_empty = FALSE;
$error['error_element']['first'] = $settings['first']['required'] && $item['first'] === '';
$error['error_element']['second'] = $settings['second']['required'] && $item['second'] === '';
if ($error['error_element']['first'] || $error['error_element']['second']) {
$errors[$field['field_name']][$langcode][$delta][] = $error;
}
}
}
if ($field_is_empty) {
$errors[$field['field_name']][$langcode][0][] = $error;
}
}
}