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

Created on 3 December 2019, about 5 years ago
Updated 22 July 2024, 5 months ago

Problem/Motivation

If a base field on an entity's base table is used as a filter criteria, there are no operator choices for "Is empty (NULL)" and "Is not empty (NOT NULL)".

I discovered this with a custom entity when I wanted to find null values. The only example I can find in core uses the file entity.

Steps to reproduce

  1. Create a view for files.
  2. Add a filter criteria. Select filename as the field.
  3. Note that "Is empty (NULL)" and "Is not empty (NOT NULL)" do not appear in the operator selection.

Proposed resolution

Make "Is empty (NULL)" and "Is not empty (NOT NULL)" options available on Views UI filters for all Not Required fields.

Remaining tasks

Code review

User interface changes

"Is empty (NULL)" and "Is not empty (NOT NULL)" options available on Views UI filters for all Not Required fields.
Before:

After MR Solution:

API changes

None

Data model changes

None

Original description

I'm not quite sure if this should be a bug or a feature request.

If a base field on an entity's base table is used as a filter criteria, there are no operator choices for "Is empty (NULL)" and "Is not empty (NOT NULL)".

I discovered this with a custom entity when I wanted to find null values. The only example I can find in core uses the file entity.

Steps to reproduce.

  1. Create a view for files.
  2. Add a filter criteria. Select filename as the field.
  3. Note that "Is empty (NULL)" and "Is not empty (NOT NULL)" do not appear in the operator selection.

I think it is a reasonable expectation to be able to search for null and not null. I know "allow empty" can be added per entity in a views_data handler or a hook_views_data or hook_views_data_alter but is there any reason this shouldn't be added automatically?

✨ Feature request
Status

Postponed: needs info

Version

11.0 🔥

Component
Views  →

Last updated about 15 hours ago

Created by

🇺🇸United States tetranz

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

Not all content is available!

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

Production build 0.71.5 2024