function calendar_systems_date_text_process_alter in Calendar Systems 7
Same name and namespace in other branches
- 8 calendar_systems.module \calendar_systems_date_text_process_alter()
- 7.2 calendar_systems.module \calendar_systems_date_text_process_alter()
Supporing date module's date_text element hook_date_text_process_alter
Parameters
$element:
$form_state:
$context:
File
- ./
calendar_systems.module, line 1081 - Contains Calendar Systems hook implementations and helpers.
Code
function calendar_systems_date_text_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);
if (isset($element['date'])) {
$element['date']['#description'] = ' ' . t('Format: @date', array(
'@date' => calendar_systems_format_date(time(), 'custom', $date_format),
));
}
$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_text_input_date($element, $element['#value']);
if ($date) {
$timestamp = $date
->format("U");
$element['#value']['date'] = $calendar
->smartGet(DATE_FORMAT_ISO, $timestamp);
$date_format = date_limit_format($date_format, $granularity);
$date_value = $calendar
->smartGet($date_format, $timestamp);
}
}
if (isset($date_value)) {
$element['date']['#value'] = $date_value;
}
}
}