You are here

function date_views_filter_handler::date_parts_form in Date 7

A form element to select date part values.

Parameters

string $prefix: A prefix for the date values, 'value', 'min', or 'max' .

string $source: The operator for this element.

string $which: Which element to provide, 'all', 'value', or 'minmax' .

array $operator_values: An array of the allowed operators for this element.

array $limit: An array of date parts to limit this element to.

Return value

The form date part element for this instance.

1 call to date_views_filter_handler::date_parts_form()
date_views_filter_handler::value_form in date_views/includes/date_views_filter_handler.inc
Add the selectors to the value form using the date handler.

File

date_views/includes/date_views_filter_handler.inc, line 263
A flexible, configurable date filter.

Class

date_views_filter_handler
This filter allows you to select a granularity of date parts to filter on, such as year, month, day, etc.

Code

function date_parts_form($form_state, $prefix, $source, $which, $operator_values, $identifier) {
  module_load_include('inc', 'date_api', 'date_api_elements');
  switch ($prefix) {
    case 'min':
      $name = t('From date');
      break;
    case 'max':
      $name = t('To date');
      break;
    default:
      $name = '';
      break;
  }
  $type = $this->options['form_type'];
  if ($type == 'date_popup' && !module_exists('date_popup')) {
    $type = 'date_text';
  }
  $format = $this->date_handler
    ->views_formats($this->options['granularity'], 'sql');
  $granularity = array_keys($this->date_handler
    ->date_parts($this->options['granularity']));

  // Don't set a default date in the UI, only in the exposed form.
  $default_date = '';
  if (!empty($form_state['exposed'])) {
    $default_date = $this
      ->default_value($prefix);
  }
  $id = !empty($form_state['exposed']) ? 'edit-date-filter-' . $prefix : 'edit-options-value-' . $prefix;
  $form[$prefix] = array(
    '#title' => $name,
    '#type' => $type,
    '#size' => 20,
    '#default_value' => !empty($this->value[$prefix]) ? $this->value[$prefix] : $default_date,
    '#date_format' => date_limit_format($format, $granularity),
    '#date_label_position' => 'within',
    '#date_year_range' => $this->options['year_range'],
    '#process' => array(
      $type . '_element_process',
    ),
    '#prefix' => '<div id="' . $id . '-wrapper"><div id="' . $id . '">',
    '#suffix' => '</div></div>',
  );
  if ($which == 'all') {
    $form[$prefix]['#process'] = array(
      'ctools_dependent_process',
      $type . '_element_process',
    );
    $form[$prefix]['#dependency'] = array(
      $source => $operator_values,
    );
  }
  if (!empty($form_state['exposed']) && !isset($form_state['input'][$identifier][$prefix])) {
    $form_state['input'][$identifier][$prefix] = $this->value[$prefix];
  }
  return $form;
}