You are here

function date_select_element_process in Date 7

Same name and namespace in other branches
  1. 7.3 date_api/date_api_elements.inc \date_select_element_process()
  2. 7.2 date_api/date_api_elements.inc \date_select_element_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'].

1 string reference to 'date_select_element_process'
_date_api_element_info in date_api/date_api_elements.inc
Implementation of hook_element_info().

File

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

Code

function date_select_element_process($element, $form_state, $form) {
  $date = NULL;
  $granularity = date_format_order($element['#date_format']);
  $input_exists = NULL;
  $input = drupal_array_get_nested_value($form_state['input'], $element['#parents'], $input_exists);
  if (is_array($element['#default_value'])) {
    $date = date_select_input_date($element, $element['#default_value']);
  }
  elseif (!empty($element['#default_value'])) {
    $date = date_default_date($element);
  }
  $element['#tree'] = TRUE;
  $element['#theme_wrappers'] = array(
    'date_select',
  );
  $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;
}