function date_text_process in Date 6
Same name and namespace in other branches
- 5.2 date_api_elements.inc \date_text_process()
- 6.2 date_api_elements.inc \date_text_process()
Text date input form.
Display all or part of a date in a single textfield.
The exact parts displayed in the field are those in #date_granularity. The display of each part comes from #date_format.
1 string reference to 'date_text_process'
- _date_api_elements in ./
date_api_elements.inc - Implementation of hook_elements().
File
- ./
date_api_elements.inc, line 115 - Date API elements themes and validation. This file is only included during the edit process to reduce memory usage.
Code
function date_text_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'];
}
$datetime = date_convert_from_custom($edit['date'], $element['#date_format']);
$date = date_make_date($datetime, $element['#date_timezone'], DATE_DATETIME);
}
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']);
//}
// Don't overwrite values already added to $element['date'] in case
// using something like jscalendar that needs to set custom values.
$element['#tree'] = TRUE;
$element['date']['#type'] = 'textfield';
$element['date']['#weight'] = !empty($element['date']['#weight']) ? $element['date']['#weight'] : $element['#weight'];
$element['date']['#default_value'] = is_object($date) ? date_format($date, $element['#date_format']) : '';
$element['date']['#attributes']['class'] = $element['date']['#attributes']['class'] . ' date-date';
// Keep the system from creating an error message for the sub-element.
// We'll set our own message on the parent element.
//$element['date']['#required'] = $element['#required'];
$element['date']['#theme'] = 'date_textfield_element';
return $element;
}