function date_text_process in Date 5.2
Same name and namespace in other branches
- 6.2 date_api_elements.inc \date_text_process()
- 6 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.
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 127 - 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 = 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'];
}
$datetime = date_convert_from_custom($edit['date'], $element['#date_format']);
$date = date_make_date($datetime, $element['#date_timezone'], DATE_DATETIME, $granularity);
}
elseif (!empty($element['#value'])) {
$date = date_make_date($element['#value'], $element['#date_timezone'], DATE_DATETIME, $granularity);
}
// 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';
$element['date']['#description'] .= ' ' . t('Format: @date', array(
'@date' => date($element['#date_format'], time()),
));
if (isset($element['#validate'])) {
array_push($element['#validate'], array(
'date_text_validate' => array(),
));
}
else {
$element['#validate'] = array(
'date_text_validate' => array(),
);
}
return $element;
}