You are here

function datelist_value_callback in Date 8

Element value callback for datelist element.

1 string reference to 'datelist_value_callback'
_date_api_element_info in date_api/date_api_elements.inc
Implements hook_element_info().

File

date_api/date_api_elements.inc, line 381
Date API elements themes and validation. This file is only included during the edit process to reduce memory usage.

Code

function datelist_value_callback($element, $input = FALSE, &$form_state = array()) {
  $parts = date_format_order($element['#date_date_format']);
  $return = array_fill_keys($parts, '');
  $date = NULL;
  if ($input !== FALSE) {
    $date = datelist_get_input_date($element, $input);
  }
  elseif (!empty($element['#default_value'])) {
    $date = new \Drupal\Core\Datetime\DrupalDateTime($element['#default_value']);
  }
  if ($date instanceof \Drupal\Core\Datetime\DrupalDateTime && !$date
    ->hasErrors()) {
    $parse = date_parse($date);
    foreach ($parts as $part) {
      $return[$part] = $parse[$part];
    }
  }
  return $return;
}