function calendar_systems_date_popup_process_alter in Calendar Systems 7.2
Same name and namespace in other branches
- 8 calendar_systems.module \calendar_systems_date_popup_process_alter()
- 7 calendar_systems.module \calendar_systems_date_popup_process_alter()
Supporing date module's date_popup element hook_date_popup_process_alter
Parameters
$element:
$form_state:
$context:
File
- ./
calendar_systems.module, line 1019 - Contains Calendar Systems hook implementations and helpers.
Code
function calendar_systems_date_popup_process_alter(&$element, &$form_state, $context) {
if (!isset($element['#calendar_system'])) {
if (!empty($element['#field']['settings']['calendar_system'])) {
$element['#calendar_system'] = $element['#field']['settings']['calendar_system'];
}
else {
$element['#calendar_system'] = calendar_systems_get_calendar_system_name();
}
}
if ($element['#calendar_system'] != 'default') {
$calendar = calendar_systems_get_calendar_instance($element['#calendar_system']);
$date_format = $element['#date_format'];
$granularity = _calendar_systems_get_granularity_from_format($date_format);
$date_value = $element['#default_value'];
$date_value = $element['#value']['date'];
if (isset($element['date'])) {
$element['date']['#description'] = ' ' . t('E.g., @date', array(
'@date' => calendar_systems_format_date(time(), 'custom', date_popup_date_format($element)),
));
}
$value_path = $element['#parents'];
$value_path[] = 'date';
$submitted_value = drupal_array_get_nested_value($form_state['input'], $value_path);
if (!empty($element['#value']) && empty($submitted_value)) {
$date = date_popup_input_date($element, $element['#value']);
if ($date) {
$timestamp = $date
->format("U");
$element['#value']['date'] = $calendar
->smartGet(DATE_FORMAT_ISO, $timestamp);
$date_format = date_part_format('date', $date_format);
$date_value = $calendar
->smartGet($date_format, $timestamp);
}
}
$date_granularity = _calendar_systems_get_granularity_part('date', $granularity);
$granularity_css = 'granularity_' . implode('_', $date_granularity);
$class_name = 'calendar_systems_js_date_picker_date_module';
if (empty($element['date']['#attributes']['class'])) {
$element['date']['#attributes']['class'] = array();
}
$date_format_considering_granularity = date_limit_format($date_format, $date_granularity);
$element['date']['#description'] = str_replace(date($date_format_considering_granularity), $calendar
->smartGet($date_format_considering_granularity), $element['date']['#description']);
$element['date']['#attributes']['class'] = array_merge(@$element['date']['#attributes']['class'], array(
$class_name,
));
$element['date']['#attributes']['class'][] = $granularity_css;
$element['date']['#id'] = $element['#id'] . '_calendar_systems';
if ($date_value) {
$element['date']['#value'] = $date_value;
}
calendar_systems_attach_js_date_picker($element['date'], $date_format_considering_granularity);
}
}