You are here

function date_text_element_process in Date 7.2

Same name and namespace in other branches
  1. 7.3 date_api/date_api_elements.inc \date_text_element_process()
  2. 7 date_api/date_api_elements.inc \date_text_element_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.

1 string reference to 'date_text_element_process'
_date_api_element_info in date_api/date_api_elements.inc
Wrapper for hook_element_info().

File

date_api/date_api_elements.inc, line 322
Date API elements 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',
    ),
  );
  $now = date_example_date();
  $element['date']['#title'] = t('Date');
  $element['date']['#title_display'] = 'invisible';
  $date_args = array(
    '@date' => date_format_date(date_example_date(), 'custom', $element['#date_format']),
  );
  $element['date']['#description'] = ' ' . t('Format: @date', $date_args);
  $element['date']['#ajax'] = !empty($element['#ajax']) ? $element['#ajax'] : FALSE;

  // Make changes if instance is set to be rendered as a regular field.
  if (!empty($element['#instance']['widget']['settings']['no_fieldset']) && $element['#field']['cardinality'] == 1) {
    $element['date']['#title'] = check_plain($element['#instance']['label']);
    $element['date']['#title_display'] = $element['#title_display'];
    $element['date']['#required'] = $element['#required'];
  }

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

  // Trigger hook_date_text_process_alter().
  drupal_alter('date_text_process', $element, $form_state, $context);
  return $element;
}