function fapi_validation_element_process in Form API Validation 8
Same name and namespace in other branches
- 7.2 fapi_validation.module \fapi_validation_element_process()
- 7 fapi_validation.module \fapi_validation_element_process()
Process element validators and filters.
Allows both #validators and #filters values. Run on form rendering. Only adds filters and validators on form submission if the values have been provided. Saves us from appending a check to every single item on submission.
1 string reference to 'fapi_validation_element_process'
- fapi_validation_element_info_alter in ./
fapi_validation.module - Implements hook_element_info_alter().
File
- ./
fapi_validation.module, line 33 - Form API validation module
Code
function fapi_validation_element_process($element, FormStateInterface $form_state) {
if (!empty($element['#filters'])) {
// @TODO: Determine how nescessary this step is. Seems unnescessarily complex given the If below doesn't have it.
// Check if element validate is already empty, and if so make variable for merging in values an empty array.
$element_validate = empty($element['#element_validate']) ? array() : $element['#element_validate'];
$element['#element_validate'] = array_merge(array(
'fapi_validate_element_filter',
), $element_validate);
}
if (!empty($element['#validators'])) {
$element['#element_validate'][] = 'fapi_validate_element_validate';
}
return $element;
}