date_popup_process_date

5 date_popup.module date_popup_process_date(&$element, $edit = NULL, $date = NULL)
6 date_popup.module date_popup_process_date(&$element, $edit = NULL, $date = NULL)

Process the date portion of the element.

1 call to date_popup_process_date()

File

contributions/date/date_popup/date_popup.module, line 283
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 = $element['#granularity'];
  $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();
  }

  // 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.
  $range = date_range_years($element['#date_year_range'], $date);
  $year_range = date_range_string($range);

  $settings = array(
    'prevText' => '«', 
    'nextText' => '»', 
    'currentText' => date_t('Today', '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, 2), 
    '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_format, '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' => (!empty($element['#value']['date']) || !empty($edit['date'])) && is_object($date) ? date_format_date($date, 'custom', $date_format) : '', 
    '#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_format)));
  return $sub_element;
}