Closed (fixed)
Project:
Drupal core
Version:
11.x-dev
Component:
views.module
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
18 Nov 2022 at 08:43 UTC
Updated:
28 Jan 2026 at 22:01 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
idebr commentedAttached patch provides a Views option for filtering boolean fields on 'Is empty (NULL)' and 'Is not empty (NOT NULL)'
Comment #3
idebr commentedAttached patch adds a visibility state for values similar to other filter plugins, so the values are only displayed for 'Is equal to' and 'Is not equal to'
Comment #4
idebr commentedAttached patch fixes phpstan validation.
Comment #6
lendudeThanks for splitting this off.
Crediting @akalata here for the work they did adding it in #2769407: Add Boolean field filter option 'Treat NULL values as FALSE' to expose the already existing code path for handling this
Comment #7
lendudeChecked the patch again, looks good, has nice test coverage.
This:
Feels a bit weak but that is how other handlers manage this too, so ¯\_(ツ)_/¯
Comment #8
alexpottThis change does not correct. Prior to this change this method would always return a string now it does not. I think this should be:
Comment #9
idebr commented#8 Thanks for picking that up, the code makes more sense now.
Attached patch adds the change suggested in #8
Comment #10
lendudeNice, feedback has been addressed, did some extra manual testing to check the admin label, and looks good
Comment #11
quietone commentedI tested this on Drupal 10.1.x, standard install. I added a boolean field to the Page content type and made three nodes. One with the boolean On, two where I did not touch the boolean field. I created a duplicate of the Content view, adding the boolean to the fields and the filters.
I guess the field value is either TRUE of FALSE. How does it become NULL? More importantly, will this confuse the user?
I then played with the filter. it worked, except when exposed.
If the filter is exposed and the operator is "is empty(NULL)' or "Is not empty (NULL)" and I go to my view, I get a Warning. I did not check the results.
Back to because of the warning.
Comment #12
lendudeThe error comes out of the same pile of
ifs as what we are looking at here #3259090: Exposed filter equality check works differently in PHP 8.0, that really needs some coverage :(To reproduce the NULL values you can do two thing:
* Create some content, then add a new boolean field to it. These values will now be NULL until you save the content again
* Other option, create a View with an optional relationship to something that has a boolean field. In the rows that don't have the relationship the values will be NULL
Comment #13
lind101 commentedAs Lendude mentions here this is a massive gap in the current boolean filter logic, take the following scenario:
I have a View that lists multiple bundles of the same entity type, one of those bundles has a boolean field. I want to be able to filter the view to only show records that don't have that field (all but one of the bundles), or have a false value for the field. This is currently unachievable.
To my mind this is the main use case we are solving here.
Comment #14
lind101 commented+1 for the patch in #9.
Managed to successfully use the patch to acheive the above use case. I used an OR filter group containing a = FALSE condition and a IS NULL condition. Worked perfectly, thanks!
Comment #15
tylired commented+1 for the patch in #9.
It worked perfectly to provide new operator options "Is empty (NULL)" and "Is not empty (NOT NULL)" inside of the Views Filter Criteria section.
Comment #17
callen321 commentedRe-rolled patch for Drupal 10.3
Comment #18
callen321 commentedDoh! Of course the patch failed to apply for 10.1.
Comment #23
sokru commentedI picked up this instead of #3098560: Add 'Is empty (NULL)' and 'Is not empty (NOT NULL)' to field Filter Operators Options since this has working tests. Otherwise the "Proposed resolution" section seems rather identical with these two issues, calling for closing either of these or refining the issue summary.
Comment #25
smustgrave commentedI marked #3098560: Add 'Is empty (NULL)' and 'Is not empty (NOT NULL)' to field Filter Operators Options as PNMI for someone to confirm this ticket fixes the same issue, if not that issue should specify what didn't make it.
For this ticket
Ran the test-only feature
Show the test coverage.
Checking the issue summary, it appears complete with a matching solution to the MR.
Looking at the code I applied some small typehints for the new functions and the test.
I left
dataSetandschemaDefinitionas those are inherited and probably could be a standalone ticket for applying throughout the repo.Rest appears to do as advertised.
Comment #27
longwaveNice to see these small features still getting attention, I've needed this before on a similar project and had to patch in support for it.
Committed b6c0243 and pushed to 11.x. Thanks!
Not eligible for backport as it's a new feature, anything building on this has to be targetted at 11.1 and above only.
Comment #29
darkodev commentedSorry for posting to a closed thread, but I just came across this need and wanted to suggest a solution for the use case in #13.
You can configure two groups of AND filters and OR them. You just need to duplicate the conditions that apply to all bundles in both groups.
Group 1:
Bundle = X
AND
Condition 1
AND
Condition 2
OR
Group 2:
Bundle = Y
AND
Condition 1
AND
Condition 2
AND
Condition 3 (that only applies to Bundle Y)