function date_popup_process_date in Date 6
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()
- 7 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_process in date_popup/
date_popup.module - Javascript popup element processing. Add popup attributes to $element.
File
- date_popup/
date_popup.module, line 177 - A module to enable jquery calendar and time entry popups. Requires the Date API.
Code
function date_popup_process_date(&$element, $edit = NULL, $date = NULL) {
$granularity = date_format_order($element['#date_format']);
$date_granularity = array_intersect($granularity, array(
'month',
'day',
'year',
));
$time_granularity = array_intersect($granularity, array(
'hour',
'minute',
'second',
));
$date_format = date_limit_format($element['#date_format'], $date_granularity);
if (empty($date_granularity)) {
return array();
}
// Center the range around the current year, but expand it far
// enough so it will pick up the year value in the field in case
// the value in the field is outside the initial range.
$this_year = date_format(date_now(), 'Y');
$value_year = is_object($date) ? date_format($date, 'Y') : $this_year;
if (!empty($value_year) && $this_year != $value_year) {
$range = explode(':', $element['#date_year_range']);
$min_year = min($value_year, $this_year + $range[0]);
$max_year = max($value_year, $this_year + $range[1]);
$year_range = sprintf('%+d', $min_year - $this_year) . ':' . sprintf('%+d', $max_year - $this_year);
}
else {
$year_range = $element['#date_year_range'];
}
$settings = "\n" . "nextText:'" . t('Next') . ">', \n" . "currentText:'" . t('Today') . "', \n" . "clearText:'" . t('Clear') . "', \n" . "closeText:'" . t('Close') . "', \n" . "firstDay:" . variable_get('date_first_day', 0) . ", \n" . "dayNames: new Array('" . implode("','", date_week_days_abbr(TRUE, TRUE, 1)) . "'), \n" . "monthNames:new Array('" . implode("','", date_month_names(TRUE)) . "'), \n" . "autoPopUp: 'focus', \n" . "closeAtTop:false, \n" . "speed: 'immediate', \n" . "dateFormat:'" . date_popup_format_to_popup($date_format) . "', \n" . "yearRange:'" . $year_range . "'\n" . "\n";
// This is just a placeholder to indicate the method to constrain from and to dates.
// Not yet implemented.
if (isset($fromto)) {
$settings . +", minDate: (input.id == 'dTo' ? getDate(\$('#dFrom').val()) : null), \n" . "maxDate: (input.id == 'dFrom' ? getDate(\$('#dTo').val()) : null) ";
}
drupal_add_js('// Global Killswitch
if (Drupal.jsEnabled) {
$(document).ready(function() {$(\'.jquery-calendar-' . $element['#id'] . '\').calendar({' . $settings . '});
})}', 'inline');
// Create a unique class for each element so we can use custom settings.
$class = date_popup_js_settings_class('jquery-calendar', 'calendar', $settings);
$sub_element = array(
'#type' => 'textfield',
'#default_value' => is_object($date) ? date_format($date, $date_format) : '',
'#attributes' => array(
'class' => $class,
),
'#size' => 20,
'#maxlength' => 20,
);
// TODO, figure out exactly when we want this description. In many places it is not desired.
$element['#description'] .= t(' Format: @date', array(
'@date' => date($date_format, time()),
));
return $sub_element;
}