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;
}
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | 2874767_fixed_exposed_date_filter_zero_values_operator.patch | 535 bytes | Aurangzeb_Alamgir |
Comments
Comment #2
Aurangzeb_Alamgir commentedComment #3
Aurangzeb_Alamgir commentedmoved this report to its proper place. Also read a guide on how to submit :)
Comment #4
Aurangzeb_Alamgir commentedComment #5
Aurangzeb_Alamgir commentedComment #6
lendude@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.
Comment #7
lendude#2637854: Grouped date filter results in undefined index notice has a test for a date filter using empty, seems related
Comment #8
Aurangzeb_Alamgir commentedHow 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.
Comment #9
lendudeIt 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.
Comment #11
Aurangzeb_Alamgir commentedNow 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...
Comment #13
klabautermann_ commentedThe 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.
Comment #21
golddragon007 commentedIn 9.2.x I see already this modification, therefore I close this issue.
Comment #22
lendudeYup, this got fixed in #2865344: Exposed date filters 'empty' and 'not empty' are broken, thanks for the triage @golddragon007!