You are here

function _date_api_element_info in Date 8

Same name and namespace in other branches
  1. 7.3 date_api/date_api_elements.inc \_date_api_element_info()
  2. 7 date_api/date_api_elements.inc \_date_api_element_info()
  3. 7.2 date_api/date_api_elements.inc \_date_api_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_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).

#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
Implements hook_element_info().

File

date_api/date_api_elements.inc, line 65
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_flexible' => 0,
    '#date_text_parts' => array(),
    '#date_increment' => 1,
    '#date_year_range' => '-3:+3',
    '#date_label_position' => 'above',
  );
  if (module_exists('ctools')) {
    $date_base['#pre_render'] = array(
      'ctools_dependent_pre_render',
    );
  }
  $type['date_timezone'] = array(
    '#input' => TRUE,
    '#tree' => TRUE,
    '#process' => array(
      'date_timezone_element_process',
    ),
    '#theme_wrappers' => array(
      'date_timezone',
    ),
    '#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',
    ),
  );
  $types['datelist'] = array(
    '#input' => TRUE,
    '#element_validate' => array(
      'datelist_validate',
    ),
    '#process' => array(
      'form_process_datelist',
    ),
    '#value_callback' => 'datelist_value_callback',
    '#theme' => 'datelist',
    '#theme_wrappers' => array(
      'form_element',
    ),
    '#date_date_format' => variable_get('date_format_short', 'm/d/Y - H:i'),
    '#date_year_range' => '1900:2050',
    '#date_increment' => 1,
    '#date_calendar' => 'gregorian',
  );
  return $type;
}