Similar to #411376: Add "OR IS NULL" as an option to views_handler_filter_numeric, I have a use case where I'd like an "OR IS NULL" option, only mine is for contextual filters.

Basically, the use case I have is a multivalued field along the lines of "Intended for users of type X", attached to a node. I want to pass in the user's type as a contextual filter, and have the view return nodes that are intended for that type of user. However, if the content editors did not choose anything for the "Intended for users of type X" field on a particular node, that means it's intended for all types of users on the site, so I want the view to show that node too.

Unless I'm missing something, there is no way to do this currently, so I'm writing a patch.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

David_Rothstein’s picture

Status: Active » Needs review
FileSize
2.29 KB

Here is the patch. For now I did this only for views_handler_argument_string since that's where I needed it, but it would probably make sense for others (e.g. views_handler_argument_numeric) also.

ruloweb’s picture

This is just what I need.

I extended it to views_handler_argument_numeric.

It's usefull when you are working with Aggregations too, some fields after grouping are NULL, but I need those fields to be show.

Thanks!

Status: Needs review » Needs work

The last submitted patch, 2: views-contextual-filters-or-is-null-2411811-2.patch, failed testing.

ruloweb’s picture

Status: Needs work » Needs review

drupalci error, resend to test

Chris Matthews’s picture

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

The 3 year old patch in #2 to views_handler_argument_numeric.inc and views_handler_argument_string.inc does not apply to the latest views 7.x-3.x-dev and if still relevant needs to be rerolled.

Checking patch handlers/views_handler_argument_numeric.inc...
Hunk #1 succeeded at 34 (offset 5 lines).
error: while searching for:
      '#default_value' => !empty($this->options['not']),
      '#fieldset' => 'more',
    );
  }

  function title() {

error: patch failed: handlers/views_handler_argument_numeric.inc:52
error: handlers/views_handler_argument_numeric.inc: patch does not apply
Checking patch handlers/views_handler_argument_string.inc...
Hunk #1 succeeded at 38 (offset 6 lines).
Hunk #2 succeeded at 133 (offset 9 lines).
Hunk #3 succeeded at 243 (offset 9 lines).
Andrew Answer’s picture

KarlShea’s picture

Status: Needs review » Reviewed & tested by the community

Works for me!

DamienMcKenna’s picture

A minor coding standards adjustment to make an array definition line not go past 80 characters.

DamienMcKenna’s picture

Could someone please open a D8 core issue for this and cross-link it, so that we can track new features to make sure they're being considered for D8 too? Thank you.

DamienMcKenna’s picture

Status: Reviewed & tested by the community » Needs review
Issue tags: +Needs tests

Let's add some test coverage so we don't run into more problems later.

jrsouth’s picture

@DamienMcKenna I couldn't find a D8/D9 version of this issue so have created https://www.drupal.org/project/drupal/issues/3209940 with a basic adaptation of the patch in #8