1 date.elements.inc date_text_element_process($element, &$form_state, $form)

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.

File

core/modules/date/date.elements.inc, line 350
Date forms and form themes and validation.

Code

function date_text_element_process($element, &$form_state, $form) {
  if (date_hidden_element($element)) {
    return $element;
  }

  $element['#tree'] = TRUE;
  $element['#theme_wrappers'] = array('date_text');
  $element['date']['#value'] = isset($element['#value']['date']) ? $element['#value']['date'] : '';
  $element['date']['#type'] = 'textfield';
  $element['date']['#weight'] = !empty($element['date']['#weight']) ? $element['date']['#weight'] : $element['#weight'];
  $element['date']['#attributes'] = array('class' => isset($element['#attributes']['class']) ? $element['#attributes']['class'] += array('date-date') : array('date-date'));
  $element['date']['#description'] = ' ' . t('Format: @date', array('@date' => date_format_date(date_example_date(), 'custom', $element['#date_format'])));
  $element['date']['#ajax'] = !empty($element['#ajax']) ? $element['#ajax'] : FALSE;
  $element['date']['#title_display'] = $element['#date_label_position'] == 'above' ? 'before' : 'invisible';

  // Make changes if instance is set to be rendered as a regular field.
  if (empty($element['#date_title_printed'])) {
    $element['date']['#title'] = $element['#title'];
    $element['date']['#title_display'] = 'before';
    $element['#date_title_printed'] = TRUE;
  }

  // Remove the title from the overall element but put it on the date part so
  // it is available for validation errors.
  $element['#date_title'] = $element['#title'];
  $element['#title'] = NULL;

  // Move the #required property from the parent to the child date element.
  $element['date']['#required'] = !empty($element['#required']);

  // Keep the system from creating an error message for the sub-element.
  // We'll set our own message on the parent 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'];
  }

  $context = array(
    'form' => $form,
  );
  backdrop_alter('date_text_process', $element, $form_state, $context);

  return $element;
}