You are here

function date_text_process in Date 6.2

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

Text date input form.

Display all or part of a date in a single textfield.

The exact parts displayed in the field are those in #date_granularity. The display of each part comes from #date_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_text_process'
_date_api_elements in ./date_api_elements.inc
Implementation of hook_elements().

File

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

Code

function date_text_process($element, $edit, $form_state, $form) {
  $date = NULL;
  $granularity = date_format_order($element['#date_format']);

  // We sometimes get $edit without $edit['date'] from
  // Views exposed filters.
  if (!empty($edit) && is_array($edit) && !empty($edit['date'])) {
    $datetime = date_convert_from_custom($edit['date'], $element['#date_format']);
    $date = date_make_date($datetime, $element['#date_timezone'], DATE_DATETIME, $granularity);
  }
  elseif (!empty($element['#value'])) {
    $date = date_make_date($element['#value'], $element['#date_timezone'], DATE_DATETIME, $granularity);
  }
  $element['#tree'] = TRUE;
  $element['date']['#type'] = 'textfield';
  $element['date']['#weight'] = !empty($element['date']['#weight']) ? $element['date']['#weight'] : $element['#weight'];
  $element['date']['#default_value'] = is_object($date) ? date_format_date($date, 'custom', $element['#date_format']) : '';
  $element['date']['#attributes'] = array(
    'class' => (isset($element['#attributes']['class']) ? $element['#attributes']['class'] : '') . ' date-date',
  );
  $element['date']['#description'] = ' ' . t('Format: @date', array(
    '@date' => date_format_date(date_now(), 'custom', $element['#date_format']),
  ));

  // Keep the system from creating an error message for the sub-element.
  // We'll set our own message on the parent element.

  //$element['date']['#required'] = $element['#required'];
  $element['date']['#theme'] = 'date_textfield_element';
  if (isset($element['#element_validate'])) {
    array_push($element['#element_validate'], 'date_text_validate');
  }
  else {
    $element['#element_validate'] = array(
      'date_text_validate',
    );
  }
  if (!empty($element['#force_value'])) {
    $element['date']['#value'] = $element['date']['#default_value'];
  }
  return $element;
}