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.
Comments
Comment #1
David_Rothstein CreditAttribution: David_Rothstein commentedHere 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.
Comment #2
ruloweb CreditAttribution: ruloweb commentedThis 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!
Comment #4
ruloweb CreditAttribution: ruloweb commenteddrupalci error, resend to test
Comment #5
Chris Matthews CreditAttribution: Chris Matthews as a volunteer commentedThe 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.
Comment #6
Andrew Answer CreditAttribution: Andrew Answer as a volunteer commentedPatch rerolled.
Comment #7
KarlSheaWorks for me!
Comment #8
DamienMcKennaA minor coding standards adjustment to make an array definition line not go past 80 characters.
Comment #9
DamienMcKennaCould 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.
Comment #10
DamienMcKennaLet's add some test coverage so we don't run into more problems later.
Comment #11
jrsouth CreditAttribution: jrsouth as a volunteer commented@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