diff --git a/date_views/includes/date_views_filter_handler_simple.inc b/date_views/includes/date_views_filter_handler_simple.inc index ebddb27..969ef57 100644 --- a/date_views/includes/date_views_filter_handler_simple.inc +++ b/date_views/includes/date_views_filter_handler_simple.inc @@ -9,6 +9,7 @@ class date_views_filter_handler_simple extends views_handler_filter_date { var $date_handler = NULL; var $offset = NULL; + var $element_number = 1; function init(&$view, &$options) { parent::init($view, $options); @@ -62,7 +63,7 @@ class date_views_filter_handler_simple extends views_handler_filter_date { $default_date = ''; if (empty($options)) { if ($this->options['is_grouped']) { - if ($this->options['group_info']['default_group'] = 'All') { + if ($this->options['group_info']['default_group'] == 'All') { return ''; } $options = $this->options['group_info']['group_items'][$this->options['group_info']['default_group']]['value'][$prefix . '_group']; @@ -79,10 +80,10 @@ class date_views_filter_handler_simple extends views_handler_filter_date { } } - // This is a date that needs to be constructed from options like 'now' . + // This is a relative date that needs to be constructed from options like 'now'. $default_option = $prefix == 'max' ? $options['default_to_date'] : $options['default_date']; - if (!empty($default_option)) { - str_replace('now', 'today', $default_option); + if (isset($options[$prefix . '_choose_input_type']) && $options[$prefix . '_choose_input_type'] == 'relative' && !empty($default_option)) { + $default_option = str_replace('now', 'today', $default_option); $date = date_create($default_option, date_default_timezone_object()); $default_date = !empty($date) ? $date->format($this->format) : ''; @@ -115,7 +116,7 @@ class date_views_filter_handler_simple extends views_handler_filter_date { if (empty($this->options['exposed'])) { return str_replace(' ', 'T', $this->date_default_value($prefix)); } - elseif ($this->options['is_grouped'] && isset($this->view->exposed_raw_input[$this->options['group_info']['identifier']]['value'])) { + elseif ($this->options['is_grouped'] && isset($this->view->exposed_raw_input[$this->options['group_info']['identifier']])) { $identifier = $this->view->exposed_raw_input[$this->options['group_info']['identifier']]; $options = $this->options['group_info']['group_items'][$identifier]['value'][$prefix . '_group']; return str_replace(' ', 'T', $this->date_default_value($prefix, $options)); @@ -144,7 +145,6 @@ class date_views_filter_handler_simple extends views_handler_filter_date { $input[$this->options['expose']['identifier']] = $element_input; } return parent::accept_exposed_input($input); - } function op_between($field) { @@ -315,18 +315,16 @@ class date_views_filter_handler_simple extends views_handler_filter_date { } } - static $element_no = 1; - if ($which == 'all' || $which == 'value') { - $form['value'] += $this->date_parts_form($form_state, 'value', $source, $which, $this->operator_values(1), $identifier, 'default_date', $element_no); + $form['value'] += $this->date_parts_form($form_state, 'value', $source, $which, $this->operator_values(1), $identifier, 'default_date', $this->element_number); } if ($which == 'all' || $which == 'minmax') { - $form['value'] += $this->date_parts_form($form_state, 'min', $source, $which, $this->operator_values(2), $identifier, 'default_date', $element_no); - $form['value'] += $this->date_parts_form($form_state, 'max', $source, $which, $this->operator_values(2), $identifier, 'default_to_date', $element_no); + $form['value'] += $this->date_parts_form($form_state, 'min', $source, $which, $this->operator_values(2), $identifier, 'default_date', $this->element_number); + $form['value'] += $this->date_parts_form($form_state, 'max', $source, $which, $this->operator_values(2), $identifier, 'default_to_date', $this->element_number); } - $element_no++; + $this->element_number++; // Add some extra validation for the select widget to be sure that // the user inputs all parts of the date. @@ -411,8 +409,9 @@ class date_views_filter_handler_simple extends views_handler_filter_date { // UI when the date selector is on the views configuration screen. // Fix for grouped between filter. Input class has to be different - // for each group and efault value needs to be taken from group item. + // for each group and default value needs to be taken from group item. $relative_value_key = ($prefix == 'max' ? 'default_to_date' : 'default_date'); + $input_type_key = $prefix . '_choose_input_type'; if ($this->options['is_grouped']) { $input_class = "$prefix-$element_no-choose-input-type"; $default_select_date_value = !empty($this->options['group_info']['group_items'][$element_no]['value'][$prefix . '_group'][$prefix]) ? $this->options['group_info']['group_items'][$element_no]['value'][$prefix . '_group'][$prefix] : $default_date; @@ -423,18 +422,18 @@ class date_views_filter_handler_simple extends views_handler_filter_date { $relative_value = $this->options[$relative_value_key]; } - $default_date = ''; $id = 'edit-options-value-' . $prefix; $form[$prefix . '_group'] = array( '#type' => 'fieldset', '#attributes' => array('class' => array('date-views-filter-fieldset')), ); - $form[$prefix . '_group'][$prefix . '_choose_input_type'] = array( + $form[$prefix . '_group'][$input_type_key] = array( '#title' => check_plain($label), '#type' => 'select', '#options' => array('date' => t('Select a date'), 'relative' => ('Enter a relative date')), '#attributes' => array('class' => array($input_class)), - '#default_value' => !empty($relative_value) ? 'relative' : 'date', + '#default_value' => !empty($this->options['group_info']['group_items'][$element_no]['value'][$prefix . '_group'][$input_type_key]) + ? $this->options['group_info']['group_items'][$element_no]['value'][$prefix . '_group'][$input_type_key] : 'date', ); $form[$prefix . '_group'][$prefix] = array( '#title' => t('Select a date'),