Repeatable: Always

How to recreate:
1) Create a content type with a nullable (not required) date field
2) Create some content with the new type, leaving the date null
3) Create a view with an exposed filter for that nullable date field
4) Set the operator to "Is empty" or "is not empty"
5) Verify the view output

Expected:
The content should be filtered according to the operator

Actual:
The content is not filtered. Both empty and non-empty results will show.

Analysis:
Function core/modules/views/src/Plugin/views/filter/Date.php acceptExposedInput does not properly distinguish between operators with two values and operators with zero values.
Due to this zero value operators get checked for min and max values which are never present in zero value operators. The result is always FALSE as return value for this function and the filter not working.

How to fix:
Make sure that the test for the presence of two values applies only for two values operators.

A fix for this problem is provided in the attached patch.

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;
       }

Comments

Aurangseb created an issue. See original summary.

Aurangzeb_Alamgir’s picture

Title: exposed date filter with zero value operator does not work » exposed date filter with zero values operator does not work
Aurangzeb_Alamgir’s picture

Project: Views (for Drupal 7) » Drupal core
Version: 8.x-3.x-dev » 8.4.x-dev
Component: exposed filters » views.module
Assigned: Unassigned » Aurangzeb_Alamgir
Issue summary: View changes
StatusFileSize
new535 bytes

moved this report to its proper place. Also read a guide on how to submit :)

Aurangzeb_Alamgir’s picture

Status: Active » Needs review
Aurangzeb_Alamgir’s picture

Assigned: Aurangzeb_Alamgir » Unassigned
lendude’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

@Aurangseb thanks for your report and patch.

This fix makes sense to me and the patch looks good. We will need some tests for this though.

lendude’s picture

Aurangzeb_Alamgir’s picture

How about having this patch tested and reviewed manually and submit it, then adding automated tests as a separate issue.

Things progress way too slow like this and fixed issues remain open for an undue long time.

After all this bug is fixed and having automated tests for it is sugar coating. On top of that I do believe that having tests for a small issue like this (one line of code) is quite the overkill.

lendude’s picture

After all this bug is fixed

It would be fixed now, but we need to make sure it stays fixed, and the only way to do so is with an automated test.

See https://api.drupal.org/api/drupal/core%21core.api.php/group/testing/8.3.x on a bit of the philosophy behind this.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Aurangzeb_Alamgir’s picture

Now this work has gone to waste. Certainly nobody will profit now and the issue remains unfixed in this AND followup versions. I am not going to write those tests...

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

klabautermann_’s picture

The Patch worked for me. Had some exposed filter and one was a date field, where i needed to filter on NULL to get all nodes not having this field set.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

golddragon007’s picture

Status: Needs work » Closed (won't fix)

In 9.2.x I see already this modification, therefore I close this issue.

lendude’s picture

Status: Closed (won't fix) » Closed (duplicate)

Yup, this got fixed in #2865344: Exposed date filters 'empty' and 'not empty' are broken, thanks for the triage @golddragon007!