function date_select_element_value_callback in Date 7
Same name and namespace in other branches
- 7.3 date_api/date_api_elements.inc \date_select_element_value_callback()
- 7.2 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 - Implementation of hook_element_info().
File
- date_api/
date_api_elements.inc, line 297 - Date API elements themes and validation. This file is only included during the edit process to reduce memory usage.
Code
function date_select_element_value_callback($element, $input = FALSE, &$form_state) {
$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') {
$return[$field] = is_object($date) ? $date
->format($formats[$field]) : '';
}
}
return $return;
}