You are here

function _date_api_element_info in Date 7

Same name and namespace in other branches
  1. 8 date_api/date_api_elements.inc \_date_api_element_info()
  2. 7.3 date_api/date_api_elements.inc \_date_api_element_info()
  3. 7.2 date_api/date_api_elements.inc \_date_api_element_info()

Implementation of 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 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_element_info()
date_api_element_info in date_api/date_api.module
Implement hook_element_info().

File

date_api/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_element_info() {
  $date_base = array(
    '#input' => TRUE,
    '#tree' => TRUE,
    '#date_timezone' => date_default_timezone(),
    '#date_flexible' => 0,
    '#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_element_process',
    ),
    '#theme_wrappers' => array(
      'date_select',
    ),
    '#value_callback' => 'date_select_element_value_callback',
  ));
  $type['date_text'] = array_merge($date_base, array(
    '#process' => array(
      'date_text_element_process',
    ),
    '#theme_wrappers' => array(
      'date_text',
    ),
    '#value_callback' => 'date_text_element_value_callback',
  ));
  $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',
  );
  return $type;
}