function datex_popup_date_popup_process_alter in Datex 7.2
Same name and namespace in other branches
- 7.3 datex_popup/datex_popup.module \datex_popup_date_popup_process_alter()
Implements hook_date_popup_process_alter().
File
- datex_popup/
datex_popup.module, line 90
Code
function datex_popup_date_popup_process_alter(&$element, &$form_state, $context) {
$schema = variable_get('datex_schema');
$langcode = $GLOBALS['language']->language;
list($field_schema, $g) = _datex_popup_get_element_info($element);
if (!($calendar = _datex_field_calendar($g, $field_schema))) {
$calendar = new DateTime();
}
static $global_settings_not_added = TRUE;
if ($global_settings_not_added) {
$settings['datex']['global']['langcode'] = $GLOBALS['language']->language;
$settings['datex']['global']['direction'] = $GLOBALS['language']->direction;
$global_settings_not_added = FALSE;
}
switch (_datex_get_calendar_name_from_name($field_schema)) {
case 'jalali':
_datex_api_add_l10n('persian', $langcode == 'fa' ? 'fa' : NULL);
break;
default:
break;
}
$range = explode(':', $element['#date_year_range']);
$y = $calendar
->format('Y');
$timestamp = strtotime(empty($element['#default_value']) ? 'now' : $element['#default_value']);
$limited_format = date_limit_format($element['#date_format'], date_popup_date_granularity($element));
$calendar
->setTimestamp($timestamp);
if (!empty($element['date']['#default_value'])) {
$date = $calendar
->format($limited_format);
if (!empty($element['date']['#value']) && $element['date']['#value'] == $element['date']['#default_value']) {
$element['date']['#value'] = $date;
}
$element['date']['#default_value'] = $date;
}
$name = 'datex_' . str_replace('-', '_', $element['#id']);
$settings['datex']['fields'][$element['#id']] = array(
'calendar' => isset($schema[$field_schema][$langcode]) ? $schema[$field_schema][$langcode] : 'default',
'defaultValue' => $timestamp,
'yearRange' => $y + $range[0] . ':' . ($y + $range[1]),
'format' => _datex_popup_picker_format($limited_format),
'defaultYear' => $calendar
->format('Y'),
'defaultMonth' => $calendar
->format('m'),
'defaultDay' => $calendar
->format('j'),
'altField' => $element['#id'] . '-' . str_replace('_', '-', $name),
'altFormat' => 'yyyy-mm-dd',
);
drupal_add_js($settings, 'setting');
// So we can easily track input time by user without depending on the format of field.
if (!isset($element[$name])) {
$element[$name] = array(
'#type' => 'textfield',
'#default_value' => $calendar
->format('Y-m-d'),
'#prefix' => '<div class="datex_hidden_element">',
'#suffix' => '</div>',
);
}
}