You are here

function date_popup_process in Date 5.2

Same name and namespace in other branches
  1. 6.2 date_popup/date_popup.module \date_popup_process()
  2. 6 date_popup/date_popup.module \date_popup_process()

Javascript popup element processing. Add popup attributes to $element.

In regular FAPI processing $element['#value'] will contain a string value before the form is submitted, and an array during submission.

In regular FAPI processing $edit is empty until the form is submitted when it will contain an array.

When used as a Views widget, $edit is always empty, and the validation step is bypassed. $element['#value'] is the only available value, but it is a string before submission and an array afterward.

File

date_popup/date_popup.module, line 149
A module to enable jquery calendar and time entry popups. Requires the Date API.

Code

function date_popup_process($element, $edit = NULL) {
  date_popup_load();
  $granularity = date_format_order($element['#date_format']);
  require_once './' . drupal_get_path('module', 'date_api') . '/date_api_elements.inc';
  if (empty($edit)) {
    $edit = date_views_filter_value($element);
  }
  $date = NULL;
  if (!empty($edit) || is_array($element['#value'])) {
    if (empty($edit)) {
      $edit = $element['#value'];
    }
    $input = $edit['date'] . (!empty($edit['time']) ? ' ' . $edit['time'] : '');
    $datetime = date_convert_from_custom($input, $element['#date_format']);
    $date = date_make_date($datetime, $element['#date_timezone'], DATE_DATETIME, $granularity);
  }
  elseif (!empty($element['#value'])) {
    $date = date_make_date($element['#value'], $element['#date_timezone'], DATE_DATETIME, $granularity);
  }
  date_increment_round($date, $element['#date_increment']);
  $granularity = date_format_order($element['#date_format']);
  $element['#tree'] = TRUE;
  $element['#granularity'] = $granularity;
  $element['date'] = date_popup_process_date($element, $edit, $date);
  $element['time'] = date_popup_process_time($element, $edit, $date);

  // Add #date_float to allow date parts to float together on the same line.
  $class = 'container-inline-date';
  if (empty($element['#date_float'])) {
    $class .= ' date-clear-block';
  }
  if (isset($element['#attributes']) || isset($element['#attributes']['class'])) {
    $element['#attributes']['class'] .= ' ' . $class;
  }
  else {
    $element['#attributes'] = array(
      'class' => $class,
    );
  }
  if (isset($element['#validate'])) {
    array_push($element['#validate'], array(
      'date_popup_validate' => array(),
    ));
  }
  else {
    $element['#validate'] = array(
      'date_popup_validate' => array(),
    );
  }
  return $element;
}