function date_select_process in Date 6
Same name and namespace in other branches
- 5.2 date_api_elements.inc \date_select_process()
- 6.2 date_api_elements.inc \date_select_process()
Flexible date/time drop-down selector.
Splits date into a collection of date and time sub-elements, one for each date part. Each sub-element can be either a textfield or a select, based on the value of ['#date_settings']['text_fields'].
The exact parts displayed in the field are those in #date_granularity. The display of each part comes from ['#date_settings']['format'].
1 string reference to 'date_select_process'
- _date_api_elements in ./
date_api_elements.inc - Implementation of hook_elements().
File
- ./
date_api_elements.inc, line 163 - Date API elements themes and validation. This file is only included during the edit process to reduce memory usage.
Code
function date_select_process($element, $edit, $form_state, $form) {
// There are some cases, like when using this as a Views form element,
// where $edit is empty and $element['#value'] holds an array of input values.
// This happens when the processing bypasses the element validation step
// that resets the value from the date and time
// subparts.
$date = NULL;
if (!empty($edit) || is_array($element['#value'])) {
if (empty($edit)) {
$edit = $element['#value'];
}
$date = date_make_date($edit, $element['#date_timezone'], DATE_ARRAY);
}
elseif (!empty($element['#value'])) {
$date = date_make_date($element['#value'], $element['#date_timezone']);
}
// TODO keep an eye on this, commented out so it is possible to provide
// blank initial value for required date.
//elseif ($element['#required']) {
// $date = date_now($element['#date_timezone']);
//}
$element['#tree'] = TRUE;
date_increment_round($date, $element['#date_increment']);
$element += (array) date_parts_element($element, $date, $element['#date_format']);
// Store a hidden value for all date parts not in the current display.
$granularity = date_format_order($element['#date_format']);
foreach (date_nongranularity($granularity) as $field) {
$formats = array(
'year' => 'Y',
'month' => 'n',
'day' => 'j',
'hour' => 'H',
'minute' => 'i',
'second' => 's',
);
$element[$field] = array(
'#type' => 'hidden',
'#value' => is_object($date) ? intval(date_format($date, $formats[$field])) : 0,
);
}
return $element;
}