The accept_exposed_input function checks for the presence of either 1 and 2 operands, but the 'Is empty / Is not empty' filters have 0 operands - which makes the check always fail, so the filter does not have any effect when it's exposed.

Attached patch fixes this by bringing the code in line with views_handler_filter_date::validate_valid_time().

Original report:

In the accept_exposed_input function it checks for 1 and 2 operands, but filtering for NULL and not NULL is a 0 operand filter.

This might help (views_handler_filter_date.inc, line 149)

      } elseif ($operators[$operator]['values'] != 0) {
            if ($this->value['min'] == '' || $this->value['max'] == '') {
                return FALSE;
            }
        } else {
            $this->value['type'] = $type;
            return true;
        }

Members fund testing for the Drupal project. Drupal Association Learn more

Comments

andrewbelcher’s picture

Version: 7.x-3.5 » 7.x-3.x-dev
Issue summary: View changes
Status: Active » Needs review
FileSize
509 bytes
PASSED: [[SimpleTest]]: [MySQL] 1,664 pass(es). View

I think really it should be checking explicitly for a need for 2 values like it does in views_handler_filter_date::validate_valid_time():

    if ($operators[$operator]['values'] == 1) {
      $convert = strtotime($value['value']);
      if (!empty($form['value']) && ($convert == -1 || $convert === FALSE)) {
        form_error($form['value'], t('Invalid date format.'));
      }
    }
    elseif ($operators[$operator]['values'] == 2) {
      $min = strtotime($value['min']);
      if ($min == -1 || $min === FALSE) {
        form_error($form['min'], t('Invalid date format.'));
      }
      $max = strtotime($value['max']);
      if ($max == -1 || $max === FALSE) {
        form_error($form['max'], t('Invalid date format.'));
      }
    }

Attached is a patch that fixes it.

roderik’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community
Related issues: +#477984: CCK field is empty/not empty filter doesn't work when exposed

Good catch on spotting views_handler_filter_date::validate_valid_time(). (I tried to fix this bug myself and wasn't sure how to construct the 'if block' exactly.) That means it doesn't really need any comments, IMHO.

(As for the related issue: its description says the same as what this patch fixes -except in D6 language-, but the patch under discussion seems to do a lot more than that. I think this patch should just be committed first, because it fixes the immediate bug.)

roderik’s picture

Issue summary: View changes
colan’s picture

We've recently switched our testing from the old qa.drupal.org to DrupalCI. Because of a bug in the new system, #2623840: Views (D7) patches not being tested, older patches must be re-uploaded. On re-uploading the patch, please set the status to "Needs Review" so that the test bot will add it to its queue.

If all tests pass, change the Status back to "Reviewed & tested by the community". We'll most likely commit the patch immediately without having to go through another round of peer review.

We apologize for the trouble, and appreciate your patience.

andrewbelcher’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
509 bytes

Have re-uploaded the patch.

vitalie’s picture

Status: Needs review » Reviewed & tested by the community

Thanks, patch #5 works for me.

DuneBL’s picture

I have tried to group all the patches/issues about this problem into one issue: https://www.drupal.org/node/2704699

deetergp’s picture

Patch #5 also worked for me. I have included it in my distro build. Thanks!

ikeigenwijs’s picture

Patch #5 also worked for me.

Aurangzeb_Alamgir’s picture

#5 works for me as well.

colan’s picture

Status: Reviewed & tested by the community » Postponed (maintainer needs more info)

Is this also a problem in D8? If so, we'd need to create another issue.

Aurangzeb_Alamgir’s picture

Yes, I just confirmed this to be a problem in the latest 8.4.x branch. Fixing this is just as easy, but I really don't know yet how to open issues and submit patches properly. Maybe somebody can guide me or do it with this patch for d8:

diff --git a/core/modules/views/src/Plugin/views/filter/Date.php b/core/modules/views/src/Plugin/views/filter/Date.php
index dbb573f..f349419 100644
--- a/core/modules/views/src/Plugin/views/filter/Date.php
+++ b/core/modules/views/src/Plugin/views/filter/Date.php
@@ -152,7 +152,7 @@ public function acceptExposedInput($input) {
         return FALSE;
       }
     }
-    else {
+    elseif ($operators[$operator]['values'] == 2) {
       if ($this->value['min'] == '' || $this->value['max'] == '') {
         return FALSE;
       }
colan’s picture

Aurangseb: Thanks for looking into this! First, create an issue in the "Drupal core" (short name: "drupal") project. We need to use Drupal core for this because Views is in core in Drupal 8.

Then, these two guides should help you:

Please cross-reference the D7 and D8 issues by linking back and forth. Once done, we can move forward with each.

Aurangzeb_Alamgir’s picture

Created the D8 bug report and added a relation to this issue.

colan’s picture

Status: Postponed (maintainer needs more info) » Reviewed & tested by the community

Thanks!

presleyd’s picture

This works for me to. Could we get this into next release?