You are here

function date_popup_process in Date 6

Same name and namespace in other branches
  1. 5.2 date_popup/date_popup.module \date_popup_process()
  2. 6.2 date_popup/date_popup.module \date_popup_process()

Javascript popup element processing. Add popup attributes to $element.

1 string reference to 'date_popup_process'
date_popup_elements in date_popup/date_popup.module
Implementation of hook_elements().

File

date_popup/date_popup.module, line 140
A module to enable jquery calendar and time entry popups. Requires the Date API.

Code

function date_popup_process($element, $edit, $form_state, $form) {
  date_popup_load();
  include_once drupal_get_path('module', 'date_api') . '/date_api_elements.inc';

  // There are some cases, like when using this as a Views form element,
  // where $edit is empty and $element['#value'] holds an array of input values.
  // This happens when the processing bypasses the element validation step
  // that resets the value from the date and time
  // subparts.
  $date = NULL;
  if (!empty($edit) || is_array($element['#value'])) {
    if (empty($edit)) {
      $edit = $element['#value'];
    }
    $input = $edit['date'] . (!empty($edit['time']) ? ' ' . $edit['time'] : '');
    $datetime = date_convert_from_custom($input, $element['#date_format']);
    $date = date_make_date($datetime, $element['#date_timezone'], DATE_DATETIME);
  }
  elseif (!empty($element['#value'])) {
    $date = date_make_date($element['#value'], $element['#date_timezone']);
  }

  // TODO keep an eye on this, commented out so it is possible to provide
  // blank initial value for required date.

  //elseif ($element['#required']) {

  //  $date = date_now($element['#date_timezone']);

  //}
  date_increment_round($date, $element['#date_increment']);
  $element['#tree'] = TRUE;
  $element['date'] = date_popup_process_date($element, $edit, $date);
  $element['time'] = date_popup_process_time($element, $edit, $date);
  return $element;
}