Problem/Motivation
When a contextual filter value is not present, one can use the QueryParameter argument_default plugin to fetch the missing value from the specified query parameter. This plugin can be configured to fetch the value not just from a first-level param like foo, but also to look at nested values, like foo[bar].
(In my project, we want to use it to send the current OG group ID to the media library to display only the media which belongs to the current group, or only display media without group if the group context is missing.)
My problem is that QueryParameter was written to only check the presence of the first level parameter key. If it is present, but any of the keys at deeper levels are missing, the plugin returns NULL value, without applying a fallback value (if something is configured).
Steps to reproduce
- Create a views page (path:
test) display using a contextual filter. List e.g. all nodes on the page, then the filter can be the type of the nodes - Configure the filter to provide a default value, select query parameter. Use multi level key, e.g.
foo[bar] - Configure the filter to use a fallback value (and ignore the filter value in case of the fallback value is active) - let's say it is
all. Also configure this at the "Exceptions" section - Configure the filter to use a fallback value (and ignore the filter value in case of the fallback value is active) - let's say it is
all - Only as a confirmation, open the page with query param
/test?foo[bar]=page. Observe it only displays content of type page - Only as a confirmation, open the page with query param
/test?foo[bar]=all. Observe it displays all content regardless of their type - Open the page with query param
/test?foo[something]=else.
Expected: page displays all items (because the plugin applied the fallback value.
Actual: Page displays no results.
Proposed resolution
Use the third parameter of NestedArray::getValue() to determine if all keys exist and apply fallback value if any of them is missing.
Remaining tasks
Patch and test. Maybe test updates?
User interface changes
Nothing.
Introduced terminology
Nothing.
API changes
QueryParameter plugin applies fallback value if any of the configured query parameter keys are missing.
Data model changes
Nothing.
Release notes snippet
Issue fork drupal-3593838
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 3593838-queryparam-fallback
changes, plain diff MR !15996
Comments
Comment #2
huzookaComment #4
huzookaComment #5
smustgrave commentedCan we add actual steps to reproduce please.
Comment #6
huzookaComment #7
alorencComment #8
alorencIt uses NestedArray::getValue's third $key_exists reference parameter, which correctly reports whether the full nested path exists
Comment #9
alorencComment #13
godotislateCommitted and pushed ecf6584 to main and de90f3f to 11.x.
Consulting with other RMs about whether this is OK to backport to 11.4.x, so moving to Patch to be ported for now.
Comment #15
godotislate@longwave agreed with 11.4 backport. Thanks, everyone!