function date_popup_process_date in Date 7
Same name and namespace in other branches
- 5.2 date_popup/date_popup.module \date_popup_process_date()
- 6.2 date_popup/date_popup.module \date_popup_process_date()
- 6 date_popup/date_popup.module \date_popup_process_date()
Process the date portion of the element.
1 call to date_popup_process_date()
- date_popup_element_process in date_popup/
date_popup.module - Javascript popup element processing. Add popup attributes to $element.
File
- date_popup/
date_popup.module, line 237 - A module to enable jquery calendar and time entry popups. Requires the Date API.
Code
function date_popup_process_date(&$element) {
$granularity = date_format_order($element['#date_format']);
$date_granularity = date_popup_date_granularity($element);
if (empty($date_granularity)) {
return array();
}
// The datepicker can't handle zero or negative values like 0:+1
// even though the Date API can handle them, so rework the value
// we pass to the datepicker to use defaults it can accept (such as +0:+1)
// date_range_string() adds the necessary +/- signs to the range string.
$this_year = date_format(date_now(), 'Y');
$date = new DateObject($element['#value']['date'], $element['#date_timezone'], date_popup_date_format($element));
$range = date_range_years($element['#date_year_range'], $date);
$year_range = date_range_string($range);
$settings = array(
'prevText' => '<' . t('Prev', array(), array(
'context' => 'date_nav',
)),
'nextText' => t('Next', array(), array(
'context' => 'date_nav',
)) . '>',
'currentText' => t('Today', array(), array(
'context' => 'date_nav',
)),
'changeMonth' => TRUE,
'changeYear' => TRUE,
'clearText' => t('Clear'),
'closeText' => t('Close'),
'firstDay' => intval(variable_get('date_first_day', 1)),
'dayNames' => date_week_days(TRUE),
'dayNamesShort' => date_week_days_abbr(TRUE, TRUE, 3),
'dayNamesMin' => date_week_days_abbr(TRUE, TRUE, 1),
'monthNames' => array_values(date_month_names(TRUE)),
'monthNamesShort' => array_values(date_month_names_abbr(TRUE)),
//'buttonImage' => base_path() . drupal_get_path('module', 'date_api') ."/images/calendar.png",
//'buttonImageOnly' => TRUE,
'autoPopUp' => 'focus',
'closeAtTop' => FALSE,
'speed' => 'immediate',
'dateFormat' => date_popup_format_to_popup(date_popup_date_format($element), 'datepicker'),
'yearRange' => $year_range,
// Custom setting, will be expanded in Drupal.behaviors.date_popup()
'fromTo' => isset($fromto),
);
// Create a unique id for each set of custom settings.
$id = date_popup_js_settings_id($element['#id'], 'datepicker', $settings);
// Manually build this element and set the value - this will prevent corrupting
// the parent value
$parents = array_merge($element['#parents'], array(
'date',
));
$sub_element = array(
'#type' => 'textfield',
'#default_value' => $element['#value']['date'],
'#id' => $id,
'#input' => FALSE,
'#size' => !empty($element['#size']) ? $element['#size'] : 20,
'#maxlength' => !empty($element['#maxlength']) ? $element['#maxlength'] : 30,
'#attributes' => $element['#attributes'],
'#parents' => $parents,
'#name' => array_shift($parents) . '[' . implode('][', $parents) . ']',
);
$sub_element['#value'] = $sub_element['#default_value'];
// TODO, figure out exactly when we want this description. In many places it is not desired.
$sub_element['#description'] = ' ' . t('Format: @date', array(
'@date' => date_format_date(date_now(), 'custom', date_popup_date_format($element)),
));
return $sub_element;
}