function date_select_process in Date 5.2
Same name and namespace in other branches
- 6.2 date_api_elements.inc \date_select_process()
- 6 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'].
In regular FAPI processing $element['#value'] will contain a string value before the form is submitted, and an array during submission.
In regular FAPI processing $edit is empty until the form is submitted when it will contain an array.
When used as a Views widget, $edit is always empty, and the validation step is bypassed. $element['#value'] is the only available value, but it is a string before submission and an array afterward.
File
- ./
date_api_elements.inc, line 188 - 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 = NULL) {
$granularity = date_format_order($element['#date_format']);
if (empty($edit)) {
$edit = date_views_filter_value($element);
}
$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, $granularity);
}
elseif (!empty($element['#value'])) {
$date = date_make_date($element['#value'], $element['#date_timezone'], DATE_DATETIME, $granularity);
}
$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']);
$formats = array(
'year' => 'Y',
'month' => 'n',
'day' => 'j',
'hour' => 'H',
'minute' => 'i',
'second' => 's',
);
foreach (date_nongranularity($granularity) as $field) {
if ($field != 'timezone') {
$element[$field] = array(
'#type' => 'hidden',
'#value' => 0,
);
}
}
if (isset($element['#validate'])) {
array_push($element['#validate'], array(
'date_select_validate' => array(),
));
}
else {
$element['#validate'] = array(
'date_select_validate' => array(),
);
}
return $element;
}