You are here

function _datex_element_validate_callback in Datex 7.2

Form element validation callback.

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

1 string reference to '_datex_element_validate_callback'
datex_element_info_alter in ./datex_date.inc
Adds datex as a date form element validator.

File

./datex_date.inc, line 176
Provides Jalali support for date module.

Code

function _datex_element_validate_callback(&$element, &$form_state) {
  if (isset($element['#type']) && $element['#type'] == 'date_popup') {
    if (module_exists('datex_popup')) {
      return _datex_popup_element_validate_callback($element, $form_state);
    }
    else {
      return;
    }
  }
  if (isset($element['#instance']['widget']['settings']['datex_schema'])) {
    $schema = $element['#instance']['widget']['settings']['datex_schema'];
  }
  else {
    $schema = 'default';
  }
  $tz = $element['#date_timezone'];
  if (!($calendar = _datex_field_calendar($element['#granularity'], $schema, $tz))) {
    return;
  }
  $date = array();
  foreach ($element['#granularity'] as $granul) {
    $date[$granul] = $element[$granul]['#value'];
  }
  $calendar
    ->setDatetime($date);

  // $calendar->fixGranularities($element['#granularity']);
  foreach (array(
    'year' => 'Y',
    'month' => 'n',
    'day' => 'j',
  ) as $name => $format) {
    if (isset($element['#value'][$name])) {
      $value = $calendar
        ->xformat($format);
      $element['#value'][$name] = $value;
      $element[$name]['#value'] = $value;
    }
  }
  form_set_value($element, $element['#value'], $form_state);
  _datex_form_set_input($element, $element['#value'], $form_state);
}