You are here

function date_select_process in Date 6.2

Same name and namespace in other branches
  1. 5.2 date_api_elements.inc \date_select_process()
  2. 6 date_api_elements.inc \date_select_process()

Flexible date/time drop-down selector.

Splits date into a collection of date and time sub-elements, one for each date part. Each sub-element can be either a textfield or a select, based on the value of ['#date_settings']['text_fields'].

The exact parts displayed in the field are those in #date_granularity. The display of each part comes from ['#date_settings']['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.

Views widget processing now receives the same values as normal FAPI processing (that was not true in Views 1).

1 string reference to 'date_select_process'
_date_api_elements in ./date_api_elements.inc
Implementation of hook_elements().

File

./date_api_elements.inc, line 187
Date API elements themes and validation. This file is only included during the edit process to reduce memory usage.

Code

function date_select_process($element, $edit, $form_state, $form) {
  $date = NULL;
  $granularity = date_format_order($element['#date_format']);
  if (!empty($edit)) {
    $date = date_make_date($edit, $element['#date_timezone'], DATE_ARRAY, $granularity);
  }
  elseif (!empty($element['#value'])) {
    $date = date_make_date($element['#value'], $element['#date_timezone'], DATE_DATETIME, $granularity);
  }
  $element['#tree'] = TRUE;
  date_increment_round($date, $element['#date_increment']);
  $element += (array) date_parts_element($element, $date, $element['#date_format']);

  // Store a hidden value for all date parts not in the current display.
  $granularity = date_format_order($element['#date_format']);
  $formats = array(
    'year' => 'Y',
    'month' => 'n',
    'day' => 'j',
    'hour' => 'H',
    'minute' => 'i',
    'second' => 's',
  );
  foreach (date_nongranularity($granularity) as $field) {
    if ($field != 'timezone') {
      $element[$field] = array(
        '#type' => 'value',
        '#value' => 0,
      );
    }
  }
  if (isset($element['#element_validate'])) {
    array_push($element['#element_validate'], 'date_select_validate');
  }
  else {
    $element['#element_validate'] = array(
      'date_select_validate',
    );
  }
  return $element;
}