You are here

function _datex_webform_date_element_process in Datex 7.3

1 string reference to '_datex_webform_date_element_process'
datex_webfrm_form_alter in datex_webfrm/datex_webfrm.module
Implements hook_form_alter().

File

datex_webfrm/datex_webfrm.module, line 48

Code

function _datex_webform_date_element_process(&$el, &$fs, &$f) {
  $calendar = datex_factory();
  if (!$calendar) {
    return;
  }
  $req = $el['#webform_component']['required'];
  $year_now = intval($calendar
    ->format('Y'));
  $year_before = webform_strtodate('Y', $el['#webform_component']['extra']['start_date']);
  $calendar
    ->xSetDate($year_before, 1, 1);
  $year_before = intval($calendar
    ->format('Y'));
  $year_after = webform_strtodate('Y', $el['#webform_component']['extra']['end_date']);
  $calendar
    ->xSetDate($year_after, 1, 1);
  $year_after = intval($calendar
    ->format('Y'));
  $el['year']['#options'] = $req ? [] : [
    array_shift($el['year']['#options']),
  ];
  for ($year = $year_before; $year <= $year_after; $year++) {
    $el['year']['#options'][$year] = $year;
  }
  $one = array_shift($el['month']['#options']);
  $el['month']['#options'] = $calendar
    ->listOptions('monthNames', $el['#required']);
  array_shift($el['month']['#options']);
  if (!$req) {
    array_unshift($el['month']['#options'], $one);
  }
  return $el;
}