You are here

function date_views_filter_handler_simple::value_validate in Date 8

Same name and namespace in other branches
  1. 7.3 date_views/includes/date_views_filter_handler_simple.inc \date_views_filter_handler_simple::value_validate()
  2. 7.2 date_views/includes/date_views_filter_handler_simple.inc \date_views_filter_handler_simple::value_validate()

Value validation.

TODO add in more validation.

We are setting an extra option using a value form because it makes more sense to set it there. That's not the normal method, so we have to manually transfer the selected value back to the option.

File

date_views/includes/date_views_filter_handler_simple.inc, line 407
A standard Views filter for a single date field, using Date API form selectors and sql handling.

Class

date_views_filter_handler_simple

Code

function value_validate($form, &$form_state) {
  $options =& $form_state['values']['options'];
  if ($options['operator'] == 'between' || $options['operator'] == 'not between') {
    if ($options['value']['min_group']['min_choose_input_type'] == 'relative') {
      if (empty($options['value']['min_group']['default_date'])) {
        form_set_error('options][value][min_group][default_date', t('Relative start date not specified.'));
      }
      else {
        $this->options['default_date'] = $options['value']['min_group']['default_date'];

        // NULL out the value field, user wanted the relative value to take hold.
        $options['value']['min_group']['min'] = NULL;
      }
    }
    else {
      $this->options['default_date'] = '';
    }
    if ($options['value']['max_group']['max_choose_input_type'] == 'relative') {
      if (empty($options['value']['max_group']['default_to_date'])) {
        form_set_error('options][value][max_group][default_to_date', t('Relative end date not specified.'));
      }
      else {
        $this->options['default_to_date'] = $options['value']['max_group']['default_to_date'];

        // NULL out the value field, user wanted the relative value to take hold.
        $options['value']['max_group']['max'] = NULL;
      }
    }
    else {
      $this->options['default_to_date'] = '';
    }
  }
  elseif (in_array($options['operator'], array(
    '<',
    '<=',
    '=',
    '!=',
    '>=',
    '>',
  ))) {
    if ($options['value']['value_group']['value_choose_input_type'] == 'relative') {
      if (empty($options['value']['value_group']['default_date'])) {
        form_set_error('options][value][value_group][default_date', t('Relative date not specified.'));
      }
      else {
        $this->options['default_date'] = $options['value']['value_group']['default_date'];

        // NULL out the value field, user wanted the relative value to take hold.
        $options['value']['value_group']['value'] = NULL;
      }
    }
    else {
      $this->options['default_date'] = '';
    }
  }

  // Flatten the form structure for views, so the values can be saved.
  foreach (array(
    'value',
    'min',
    'max',
  ) as $key) {
    $options['value'][$key] = $options['value'][$key . '_group'][$key];
  }
}