Add 'Is empty (NULL)' and 'Is not empty (NOT NULL)' operators to boolean field filtering

Created on 18 November 2022, about 2 years ago
Updated 21 August 2024, 4 months ago

Problem/Motivation

Issue split from Views UI should offer a 'Treat NULL values as FALSE' on boolean field filtering to expose the already existing code path for handling this Needs work for a clearer issue scope.

Proposed resolution

Views provides an option for filtering boolean fields on 'Is empty (NULL)' and 'Is not empty (NOT NULL)'

Remaining tasks

  1. Write a patch
  2. Review
  3. Commit

User interface changes

Views now offers 'Is empty (NULL)' and 'Is not empty (NOT NULL)' operators to boolean field filtering

API changes

None.

Data model changes

None.

Release notes snippet

Views now offers 'Is empty (NULL)' and 'Is not empty (NOT NULL)' operators to boolean field filtering

📌 Task
Status

Fixed

Version

11.0 🔥

Component
Views 

Last updated about 11 hours ago

Created by

🇳🇱Netherlands idebr

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇬🇧United Kingdom lind101

    * 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

    As 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.

  • 🇬🇧United Kingdom lind101

    +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!

  • 🇺🇸United States tylired

    +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.

  • 🇺🇸United States callen321

    Re-rolled patch for Drupal 10.3

  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update 6 months ago
    Patch Failed to Apply
  • 🇺🇸United States callen321

    Doh! Of course the patch failed to apply for 10.1.

  • First commit to issue fork.
  • Merge request !8551Convert patch to merge request → (Open) created by sokru
  • 🇫🇮Finland sokru

    sokru changed the visibility of the branch 11.x to hidden.

  • 🇫🇮Finland sokru

    sokru changed the visibility of the branch 10.1.x to hidden.

  • Pipeline finished with Failed
    6 months ago
    Total: 167s
    #208968
  • Pipeline finished with Success
    6 months ago
    Total: 574s
    #208972
  • Status changed to Needs review 6 months ago
  • 🇫🇮Finland sokru

    I picked up this instead of Add 'Is empty (NULL)' and 'Is not empty (NOT NULL)' to field filter operators Needs work 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.

  • First commit to issue fork.
  • Status changed to RTBC 5 months ago
  • 🇺🇸United States smustgrave

    I marked Add 'Is empty (NULL)' and 'Is not empty (NOT NULL)' to field filter operators Needs work 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

    1) Drupal\Tests\views\Kernel\Handler\FilterBooleanOperatorTest::testEmptyFilterBooleanOperator
    Failed asserting that actual size 6 matches expected size 1.
    /builds/issue/drupal-3322402/core/modules/views/tests/src/Kernel/Handler/FilterBooleanOperatorTest.php:161
    FAILURES!
    Tests: 3, Assertions: 13, Failures: 1.
    

    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 dataSet and schemaDefinition as those are inherited and probably could be a standalone ticket for applying throughout the repo.

    Rest appears to do as advertised.

    • longwave committed b6c02433 on 11.x
      Issue #3322402 by idebr, smustgrave, Lendude, lind101, akalata, quietone...
  • Status changed to Fixed 5 months ago
  • 🇬🇧United Kingdom longwave UK

    Nice 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.

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024