function _date_api_elements in Date 6
Same name and namespace in other branches
- 5.2 date_api_elements.inc \_date_api_elements()
- 6.2 date_api_elements.inc \_date_api_elements()
Implementation of hook_elements().
Parameters for date form elements, designed to have sane defaults so any or all can be omitted.
Fill the element #default_value with a date in datetime format, (YYYY-MM-DD HH:MM:SS), adjusted to the proper local timezone.
NOTE - Converting a date stored in the database from UTC to the local zone and converting it back to UTC before storing it is not handled by this element and must be done in pre-form and post-form processing!!
The date_select element will create a collection of form elements, with a separate select or textfield for each date part. The whole collection will get re-formatted back into a date value of the requested type during validation.
The date_text element will create a textfield that can contain a whole date or any part of a date as text. The user input value will be re-formatted back into a date value of the requested type during validation.
The date_timezone element will create a drop-down selector to pick a timezone name.
#date_timezone The local timezone to be used to create this date.
#date_format A format string that describes the format and order of date parts to display in the edit form for this element. This makes it possible to show date parts in a custom order, or to leave some of them out. Be sure to add 'A' or 'a' to get an am/pm selector. Defaults to the short site default format.
#date_label_position Handling option for date part labels, like 'Year', 'Month', and 'Day', can be 'above' the date part, 'within' it, or 'none', default is 'above'. The 'within' option shows the label as the first option in a select list or the default value for an empty textfield, taking up less screen space.
#date_increment Increment minutes and seconds by this amount, default is 1.
#date_year_range The number of years to go back and forward in a year selector, default is -3:+3 (3 back and 3 forward).
#date_text_parts Array of date parts that should use textfields instead of selects i.e. array('year') will format the year as a textfield and other date parts as drop-down selects.
1 call to _date_api_elements()
- date_api_elements in ./
date_api.module - Implementation of hook_elements().
File
- ./
date_api_elements.inc, line 60 - Date API elements themes and validation. This file is only included during the edit process to reduce memory usage.
Code
function _date_api_elements() {
$date_base = array(
'#input' => TRUE,
'#tree' => TRUE,
'#date' => NULL,
'#date_timezone' => date_default_timezone_name(),
'#date_format' => variable_get('date_format_short', 'm/d/Y - H:i'),
'#date_text_parts' => array(),
'#date_increment' => 1,
'#date_year_range' => '-3:+3',
'#date_label_position' => 'above',
);
$type['date_select'] = array_merge($date_base, array(
'#process' => array(
'date_select_process',
),
'#element_validate' => array(
'date_select_validate',
),
));
$type['date_text'] = array_merge($date_base, array(
'#process' => array(
'date_text_process',
),
'#element_validate' => array(
'date_text_validate',
),
));
$type['date_timezone'] = array(
'#input' => TRUE,
'#tree' => TRUE,
'#process' => array(
'date_timezone_process',
),
'#element_validate' => array(
'date_timezone_validate',
),
);
return $type;
}