function commerce_file_limit_duration_element_validate in Commerce File 7
FAPI element validate callback for limit integer element type.
1 string reference to 'commerce_file_limit_duration_element_validate'
- commerce_file_element_info in includes/
commerce_file.elements.inc - Implements hook_element_info().
File
- includes/
commerce_file.elements.inc, line 259 - Commerce File form elements
Code
function commerce_file_limit_duration_element_validate($element, &$form_state) {
$data = $element['#value'];
$value = NULL;
if (empty($data)) {
return;
}
if ($data['mode'] == 'value') {
// process entered value
$duration = $data['value'];
// validate as not empty here since #required on value would require for all modes
if (!isset($duration['value']) || _commerce_file_element_value_is_empty($duration['value'])) {
form_error($element, t('%name field is required.', array(
'%name' => $element['#title'],
)));
return;
}
// set seconds to store
$value = $duration['value'];
if (!empty($duration['unit'])) {
$value *= $duration['unit'];
}
// ensure integer value stored
$value = intval($value);
}
else {
// set value to the mode key
$value = $data['mode'];
}
// Consolidate into one value.
form_set_value($element, $value, $form_state);
}