function mobile_number_field_validate in Mobile Number 7
Implements hook_field_validate().
File
- ./
mobile_number.module, line 508 - mobile_number.module
Code
function mobile_number_field_validate($entity_type, $entity, $field, $instance, $langcode, $items, &$errors) {
$unique = $field['settings']['unique'];
$duplicates = FALSE;
$numbers = array();
if ($unique) {
foreach ($items as $delta => $value) {
if (!empty($value['value'])) {
if ($unique == MOBILE_NUMBER_UNIQUE_YES) {
if (!empty($numbers[$value['value']])) {
$duplicates = TRUE;
}
$numbers[$value['value']] = TRUE;
}
if ($unique == MOBILE_NUMBER_UNIQUE_YES_VERIFIED && $value['verified']) {
if (!empty($all_numbers[$value['value']])) {
$duplicates = TRUE;
}
$numbers[$value['value']] = TRUE;
}
$all_numbers[$value['value']] = TRUE;
}
if ($duplicates) {
$errors[$field['field_name']][$langcode][$delta][] = array(
'error' => 'duplicates',
'message' => t('%field requires unique numbers but there are duplicate values in the field.', array(
'%field' => $instance['label'],
)),
);
}
}
}
}