1 date.elements.inc _date_element_info()

Implements hook_element_info().

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 reformatted back to 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_popup element will create two textfields, one for the date and one for the time. The date textfield will include a jQuery popup calendar date picker, and the time textfield uses a jQuery timepicker.

The date_timezone element will create a drop-down selector to pick a timezone name.

The date_year_range element will create two textfields (for users with JavaScript enabled they will appear as drop-down selectors with an option for custom text entry) to pick a range of years that will be passed to form submit handlers as a single string (e.g., -3:+3).

The date_combo element will create a 'start' and optional 'end' date, along with an optional 'timezone' column for date-specific timezones. Each 'start' and 'end' date will be constructed from date_select or date_text.

#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.

Additionally, the date_popup element supports the additional properties:

#datepicker_options An associative array representing the jQuery datepicker options you want to set for this element. Use the jQuery datepicker option names as keys. Defaults include:

  • changeMonth => TRUE
  • changeYear => TRUE
  • autoPopUp => 'focus'
  • closeAtTop => FALSE
  • speed => 'immediate'

File

core/modules/date/date.elements.inc, line 87
Date forms and form themes and validation.

Code

function _date_element_info() {
  $date_base = array(
    '#input' => TRUE,
    '#tree' => TRUE,
    '#date_timezone' => date_default_timezone(),
    '#date_flexible' => 0,
    '#date_format' => system_date_format_load('short'),
    '#date_text_parts' => array(),
    '#date_increment' => 1,
    '#date_year_range' => '-3:+3',
    '#date_label_position' => 'above',
  );
  $type['date_select'] = array(
    '#process' => array('date_select_element_process'),
    '#theme_wrappers' => array('date_select'),
    '#value_callback' => 'date_select_element_value_callback',
  ) + $date_base;
  $type['date_text'] = array(
    '#process' => array('date_text_element_process'),
    '#theme_wrappers' => array('date_text'),
    '#value_callback' => 'date_text_element_value_callback',
  ) + $date_base;
  $type['date_popup'] = array(
    '#datepicker_options' => array(),
    '#timepicker' => TRUE,
    '#process' => array('date_popup_element_process'),
    '#value_callback' => 'date_popup_element_value_callback',
    '#theme_wrappers' => array('date_popup'),
  ) + $date_base;
  $type['date_timezone'] = array(
    '#input' => TRUE,
    '#tree' => TRUE,
    '#process' => array('date_timezone_element_process'),
    '#theme_wrappers' => array('date_text'),
    '#value_callback' => 'date_timezone_element_value_callback',
  );
  $type['date_year_range'] = array(
    '#input' => TRUE,
    '#process' => array('date_year_range_element_process'),
    '#value_callback' => 'date_year_range_element_value_callback',
    '#element_validate' => array('date_year_range_validate'),
  );
  $type['date_combo'] = array(
    '#input' => TRUE,
    '#delta' => 0,
    '#columns' => array('value', 'value2', 'timezone', 'offset', 'offset2'),
    '#process' => array('date_combo_element_process'),
    '#element_validate' => array('date_combo_validate'),
    '#theme_wrappers' => array('date_combo'),
  );
  return $type;
}