You are here

function _datex_date_element_validate_callback in Datex 7

Form element validation callback.

Converts a Jalali date to Gregorian date just before actual validation of date element happens.

1 string reference to '_datex_date_element_validate_callback'
datex_date_element_info_alter in datex_date/datex_date.module
Adds datex as a date form element validator.

File

datex_date/datex_date.module, line 134
Provides Jalali support for date module.

Code

function _datex_date_element_validate_callback(&$element, &$form_state) {
  if (_datex_skip_language()) {
    return;
  }
  $y = $element['year']['#value'];
  $m = $element['month']['#value'];
  $d = $element['day']['#value'];
  $dates = DatexFormatter::toGregorian($y, $m, $d);
  foreach ($dates as $granularity => $value) {
    if (!$element[$granularity]['#value']) {
      $dates[$granularity] = 0;
    }
  }
  foreach (array(
    'hour',
    'minute',
    'second',
  ) as $granularity) {
    $dates[$granularity] = $element[$granularity]['#value'];
  }
  drupal_array_set_nested_value($form_state['values'], $element['#parents'], $dates);
  drupal_array_set_nested_value($form_state['input'], $element['#parents'], $dates);
}