You are here

function date_combo_process in Date 6

Same name and namespace in other branches
  1. 5.2 date/date_elements.inc \date_combo_process()
  2. 6.2 date/date_elements.inc \date_combo_process()

Process an individual date element.

1 string reference to 'date_combo_process'
_date_elements in date/date_elements.inc
Implementation of hook_elements().

File

date/date_elements.inc, line 249
Date forms and form themes and validation.

Code

function date_combo_process($element, $edit, &$form_state, $form) {
  $field_name = $element['#field_name'];
  $field = $form['#field_info'][$field_name];
  $delta = $element['#delta'];
  $columns = $element['#columns'];
  if (isset($columns['rrule'])) {
    unset($columns['rrule']);
  }
  $from_field = 'value';
  $to_field = 'value2';
  $tz_field = 'timezone';
  $offset_field = 'offset';
  $offset_field2 = 'offset2';
  if ($field['todate'] != 'required' && !empty($element['#default_value'][$to_field]) && $element['#default_value'][$to_field] == $element['#default_value'][$from_field]) {
    unset($element['#default_value'][$to_field]);
  }
  $element[$from_field] = array(
    '#field' => $field,
    '#title' => t($field['widget']['label']),
    '#weight' => $field['widget']['weight'],
    '#description' => empty($field['todate']) ? t($field['widget']['description']) : '',
    '#required' => $field['required'] && $delta == 0 ? 1 : 0,
    '#default_value' => isset($element['#value'][$from_field]) ? $element['#value'][$from_field] : '',
    '#field' => $field,
    '#delta' => $delta,
    '#date_timezone' => $element['#date_timezone'],
    '#date_format' => date_limit_format(date_input_format($element, $field), $field['granularity']),
    '#date_text_parts' => (array) $field['widget']['text_parts'],
    '#date_increment' => $field['widget']['increment'],
    '#date_year_range' => $field['widget']['year_range'],
    '#date_label_position' => $field['widget']['label_position'],
  );
  $element[$from_field]['#description'] .= ' ' . t('Format: @date', array(
    '@date' => date($element[$from_field]['#date_format'], time()),
  ));

  // Give this element the right type, using a Date API
  // or a Date Popup element type.
  switch ($field['widget']['type']) {
    case 'date_select':
      $element[$from_field]['#type'] = 'date_select';
      break;
    case 'date_popup':
      $element[$from_field]['#type'] = 'date_popup';
      break;
    default:
      $element[$from_field]['#type'] = 'date_text';
      break;
  }

  // If this field uses the 'To', add matching element
  // for the 'To' date, and adapt titles to make it clear which
  // is the 'From' and which is the 'To'.
  if ($field['todate']) {
    $element[$from_field]['#title'] = t('From date');
    $element[$to_field] = $element[$from_field];
    $element[$to_field]['#title'] = t('To date');
    $element[$to_field]['#default_value'] = isset($element['#value'][$to_field]) ? $element['#value'][$to_field] : '';
    $element[$to_field]['#required'] = false;
    $element[$to_field]['#weight'] += 0.1;
    $element[$to_field]['#description'] = t('Empty \'To date\' values will use the \'From date\' values.');
    $element['#fieldset_description'] = t($field['widget']['description']);
  }

  // Make sure field info will be available to the validator which
  // does not get the values in $form.
  $form_state['#field_info'][$field['field_name']] = $field;
  return $element;
}