function openlayers_cck_validate in Openlayers 6
Same name and namespace in other branches
- 6.2 modules/openlayers_cck/openlayers_cck.module \openlayers_cck_validate()
FAPI validate function for custom element
1 string reference to 'openlayers_cck_validate'
- openlayers_cck_wkt_element_process in modules/
openlayers_cck/ openlayers_cck.module - Process an individual element.
File
- modules/
openlayers_cck/ openlayers_cck.module, line 438 - This file holds the main Drupal hook functions and private functions for the openlayers_cck module.
Code
function openlayers_cck_validate($element, &$form_state) {
// Transpose selections from field => delta to delta => field,
// turning multiple selected options into multiple parent elements.
// Immediate parent is the delta, need to get back to parent's parent
// to create multiple elements.
// Get field array
$field = $form_state['#field_info'][$element['#field_name']];
// Convert data to array of values
$items = _openlayers_cck_convert_form_data($element, $field);
// Set value in form
form_set_value($element, $items, $form_state);
// Check we don't exceed the allowed number of values.
if ($field['multiple'] >= 2) {
if (count($items) > $field['multiple']) {
$field_key = $element['#columns'][0];
form_error($element[$field_key], t('%name: this field cannot hold more than @count values.', array(
'%name' => $field['widget']['label'],
'@count' => $field['multiple'],
)));
}
}
}