function yamaps_field_validate in Yandex.Maps 7
Implements hook_field_validate().
File
- ./
yamaps.module, line 397 - Yandex Maps module main file.
Code
function yamaps_field_validate($entity_type, $entity, $field, $instance, $langcode, $items, &$errors) {
if ($field['type'] == 'field_yamaps') {
// Perform validation on empty coordinates only for field
// attached to entity.
if ($entity_type && $entity) {
if ($instance['required']) {
$items_total = count($items);
$items_empty = 0;
foreach ($items as $item) {
if (empty($item['coords'])) {
$items_empty++;
}
}
if ($items_total == $items_empty) {
$errors[$field['field_name']][$langcode][0][] = [
'error' => 'coords',
'message' => t('Cooordinates cannot be empty for required field "!field_name".', [
'!field_name' => $instance['label'],
]),
];
}
}
}
else {
// Validation for fields settings form.
foreach ($items as $delta => $item) {
if (empty($item['coords']) && $item['hide'] == 1) {
$errors[$field['field_name']][$langcode][$delta][] = [
'error' => 'coords',
'message' => t('"!field_name" with empty coordinates cannot be hidden by default.', [
'!field_name' => $instance['label'],
]),
];
}
}
}
}
}