function datex_popup_date_popup_process_alter in Datex 7.3
Same name and namespace in other branches
- 7.2 datex_popup/datex_popup.module \datex_popup_date_popup_process_alter()
Implements hook_date_popup_process_alter().
File
- datex_popup/
datex_popup.module, line 229
Code
function datex_popup_date_popup_process_alter(&$element, &$fs) {
$greg = FALSE;
$calendar = _datex_date_field_calendar($element, TRUE, 'en');
if (!$calendar) {
$calendar = datex_factory(NULL, NULL, 'en');
if (!$calendar) {
$calendar = datex_factory(NULL, 'en', 'en');
}
$greg = $calendar
->getCalendarName() !== 'persian';
}
$date_fmt = date_popup_date_format($element);
$time_fmt = date_popup_time_format($element);
$dg = date_popup_date_granularity($element);
$tg = date_popup_time_granularity($element);
$input = _datex_get_fs($element, $fs, NULL, TRUE);
$has_date_input = $input && isset($input['date']) && !empty($input['date']);
$has_time_input = $input && isset($input['time']) && !empty($input['time']);
$has_default = !empty($element['#default_value']);
$def = date_default_date($element);
$has_month = in_array('month', $dg);
$has_day = in_array('day', $dg);
list($from, $to) = date_range_years($element['#date_year_range']);
$from = _datex_popup_year_to_timestamp($calendar, $from, $greg) . '000';
$to = _datex_popup_year_to_timestamp($calendar, $to, $greg) . '000';
if (!$greg && !$has_month) {
$def
->setDate($def
->format('Y'), 6, $def
->format('j'));
}
if (!$greg && !$has_day) {
$def
->setDate($def
->format('Y'), $def
->format('n'), 25);
}
$calendar
->setTimestamp($def
->getTimestamp());
// ____________________________________________ INFO GATHERED, NOW THE ACTUAL
$extra = [
'min' => $from,
'max' => $to,
'has-init' => 0,
#$has_default || $has_date_input ? 1 : 0,
'has-month' => in_array('month', $dg, TRUE),
'has-day' => in_array('day', $dg, TRUE),
'value' => $calendar
->xFormat('Y-n-j'),
'tp' => $calendar
->getCalendarName(),
'init' => $calendar
->getTimestamp() . '000',
'has-minute' => in_array('minute', $tg, TRUE),
];
if ($calendar
->getCalendarName() === 'persian') {
$element['date']['#description'] = 'Eg 1390/02/24';
$extra['tp'] = 'persian';
}
else {
$element['date']['#description'] = 'Eg 2015/02/24';
$extra['tp'] = 'gregorian';
}
if (!isset($element['date']['#attributes'])) {
$element['date']['#attributes'] = [];
}
if (!isset($element['time']['#attributes'])) {
$element['time']['#attributes'] = [];
}
foreach ([
'date',
'time',
] as $key) {
$element[$key]['#attributes']['autocomplete'] = 'off';
foreach ($extra as $name => $value) {
$element[$key]['#attributes']['data-datex-' . $name] = $value;
}
}
if ($has_date_input) {
$element['#value']['date'] = $input['date'];
$element['date']['#value'] = $input['date'];
}
elseif (!empty($element['date']['#value'])) {
$element['date']['#value'] = $calendar
->format('Y/n/j');
}
}