You are here

function date_popup_element_value_callback in Date 7.3

Same name and namespace in other branches
  1. 7 date_popup/date_popup.module \date_popup_element_value_callback()
  2. 7.2 date_popup/date_popup.module \date_popup_element_value_callback()

Element value callback for date_popup element.

2 calls to date_popup_element_value_callback()
date_popup_process_date_part in date_popup/date_popup.module
Process the date portion of the element.
date_popup_process_time_part in date_popup/date_popup.module
Process the time portion of the element.
1 string reference to 'date_popup_element_value_callback'
date_popup_element_info in date_popup/date_popup.module
Implements hook_element_info().

File

date_popup/date_popup.module, line 271
A module to enable jQuery calendar and time entry popups.

Code

function date_popup_element_value_callback($element, $input = FALSE, &$form_state = array()) {
  $granularity = date_format_order($element['#date_format']);
  $has_time = date_has_time($granularity);
  $date = NULL;
  $return = $has_time ? array(
    'date' => '',
    'time' => '',
  ) : array(
    'date' => '',
  );

  // Normal input from submitting the form element. Check is_array() to skip
  // the string input values created by Views pagers. Those string values, if
  // present, should be interpreted as empty input.
  if ($input !== FALSE && is_array($input)) {
    $return = $input;
    $date = date_popup_input_date($element, $input);
  }
  elseif (!empty($element['#default_value'])) {
    $date = date_default_date($element);
  }

  // Date with errors won't re-display.
  if (date_is_date($date)) {
    $return['date'] = !$date->timeOnly ? date_format_date($date, 'custom', date_popup_date_format($element)) : '';
    $return['time'] = $has_time ? date_format_date($date, 'custom', date_popup_time_format($element)) : '';
  }
  elseif (!empty($input)) {
    $return = $input;
  }
  return $return;
}