function date_select_element_value_callback in Date 7.2
Same name and namespace in other branches
- 7.3 date_api/date_api_elements.inc \date_select_element_value_callback()
- 7 date_api/date_api_elements.inc \date_select_element_value_callback()
Element value callback for date_select element.
1 string reference to 'date_select_element_value_callback'
- _date_api_element_info in date_api/
date_api_elements.inc - Wrapper for hook_element_info().
File
- date_api/
date_api_elements.inc, line 449 - Date API elements themes and validation.
Code
function date_select_element_value_callback($element, $input = FALSE, &$form_state = array()) {
$return = array(
'year' => '',
'month' => '',
'day' => '',
'hour' => '',
'minute' => '',
'second' => '',
);
$date = NULL;
if ($input !== FALSE) {
$return = $input;
$date = date_select_input_date($element, $input);
}
elseif (!empty($element['#default_value'])) {
$date = date_default_date($element);
}
$granularity = date_format_order($element['#date_format']);
$formats = array(
'year' => 'Y',
'month' => 'n',
'day' => 'j',
'hour' => 'H',
'minute' => 'i',
'second' => 's',
);
foreach ($granularity as $field) {
if ($field != 'timezone') {
if (date_is_date($date)) {
$return[$field] = $date
->format($formats[$field]);
}
else {
$return = array();
}
}
}
return $return;
}