The description of "Date year range" includes "Set the allowable minimum and maximum year range for this argument...", and if I set the range as 2000:2005, then try to deep link the argument in the URL as 2006, I'm told that "An illegal choice has been detected. Please contact the site administrator." This is as I'd expect, although not a 404 error, as the "Date year range" indicates it will be (but that's nit-picky :)

The issue is that if you select the default label of "-Year", you see ALL data, even that outside the date range. And there doesn't seem to be a way to remove this "-Year" option. The "Optional" setting in the Date filter would be ideal candidate to remove this "-Year" option, but it appears to be non-functional.

It seems the culprit might be the date_parts_form function in date_api_filter_handler.inc:

function date_parts_form($form_state, $prefix, $source, $which, $operator_values) {
    require_once('./'. drupal_get_path('module', 'date_api') .'/date_api_elements.inc');
    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);
    }
    $form[$prefix] = array(
      '#type' => $type,
      '#title' => $name,
      '#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'],
    );
    if ($which == 'all') {
      $dependency = array(
        '#process' => array($type .'_process', 'views_process_dependency'),
        '#dependency' => array($source => $operator_values),
      );
      $form[$prefix] += $dependency;
    }
    return $form;
  }

It seems to set '#date_label_position' => 'within' no matter what, whereas with date CCK fields, there's the option of placement of the label. So no matter what, "-Year" will show up within, and seems to act as an all/any choice. I think the filter's "Optional" setting is set up in views_filter_handler_numeric.inc or views_filter_handler.inc, and it hasn't been configured to work with date_api_filter_handler yet. Not sure though...

I'm new to this, so this is sort of guesswork. I'll try looking into it later, but any input would be appreciated! Cheers all

Keywords: restrict date parts optional -year year label

Comments

FreddieK’s picture

I'm currently having the same problem. Has anyone found a solution to this?

patcon’s picture

No sorry, never went any further with it, since it was a deal-breaker for me. I think part of the lack of response was that my explanation wasn't clear enough. If you wanted to distill it, you might get more of a response :)

Good luck!

DamienMcKenna’s picture

Status: Active » Closed (won't fix)

Unfortunately the Drupal 6 version of the Date module is no longer supported. That said, we appreciate that you took time to work on this issue. Should this request still be relevant for Drupal 7 please feel free to reopen it. Thank you.