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

  1. 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
  2. Configure the filter to provide a default value, select query parameter. Use multi level key, e.g. foo[bar]
  3. 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
  4. 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
  5. Only as a confirmation, open the page with query param /test?foo[bar]=page. Observe it only displays content of type page
  6. Only as a confirmation, open the page with query param /test?foo[bar]=all. Observe it displays all content regardless of their type
  7. 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

Command icon 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:

Comments

huzooka created an issue. See original summary.

huzooka’s picture

Assigned: Unassigned » huzooka

huzooka’s picture

Assigned: huzooka » Unassigned
Status: Active » Needs review
smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs steps to reproduce

Can we add actual steps to reproduce please.

huzooka’s picture

Issue summary: View changes
Status: Needs work » Needs review
Issue tags: -Needs steps to reproduce
alorenc’s picture

Assigned: Unassigned » alorenc
alorenc’s picture

Assigned: alorenc » Unassigned

It uses NestedArray::getValue's third $key_exists reference parameter, which correctly reports whether the full nested path exists

alorenc’s picture

Status: Needs review » Reviewed & tested by the community

  • godotislate committed ecf6584e on main
    fix: #3593838 Views QueryParameter argument_default plugin doesn't apply...

  • godotislate committed de90f3f1 on 11.x
    fix: #3593838 Views QueryParameter argument_default plugin doesn't apply...
godotislate’s picture

Version: main » 11.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)

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

  • godotislate committed 99258a8a on 11.4.x
    fix: #3593838 Views QueryParameter argument_default plugin doesn't apply...
godotislate’s picture

Version: 11.x-dev » 11.4.x-dev
Status: Patch (to be ported) » Fixed

@longwave agreed with 11.4 backport. Thanks, everyone!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.