You are here

function date_popup_element_value_callback in Date 7

Same name and namespace in other branches
  1. 7.3 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.

1 string reference to 'date_popup_element_value_callback'
date_popup_element_info in date_popup/date_popup.module
Implement hook_element_info().

File

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

Code

function date_popup_element_value_callback($element, $input = FALSE, &$form_state) {
  $granularity = date_format_order($element['#date_format']);
  $has_time = date_has_time($granularity);
  $date = NULL;
  $return = $has_time ? array(
    'date' => '',
    'time' => '',
  ) : array(
    'date' => '',
  );
  if ($input !== FALSE) {
    $return = $input;
    $date = date_popup_input_date($element, $input);
  }
  elseif (!empty($element['#default_value'])) {
    $date = date_default_date($element);
  }
  $return['date'] = is_object($date) && !$date->timeOnly ? $date
    ->format(date_popup_date_format($element)) : '';
  $return['time'] = is_object($date) && $has_time ? $date
    ->format(date_popup_time_format($element)) : '';
  return $return;
}