Problem/Motivation

The query parameter (query_parameter) plugin provides a Views default argument with a value taken from a query parameter from the current request. For instance, if the request has a query string such as ?foo=bar&baz=qux, by configuring the plugin to get the argument default value from the foo param, will return bar.

However, the request query string might look like ?foo[bar][baz]=qux. With the current code, setting the the param to foo[bar][baz] will return NULL instead of qux. The reason is that QueryParameter::getArgument() only checks for the 1st tier of query string parameters and is not able to process array structured values.

Steps to reproduce

See the tests.

Proposed resolution

  • Convert the param name into an array: the foo[bar][baz] will become ['foo', 'bar', 'baz'].
  • Use NestedArray::getValue() to vertically traverse the array and find the nested value.

Remaining tasks

None.

User interface changes

None.

API changes

None.

Data model changes

Site builders are able to store query param names having an array structure.

Release notes snippet

N/A

Original report

By providing a query parameter as contextual filter argument, we can already limit the referenceable entitities in an entity reference view, with #1699378: Allow tokens in entity reference views selection arguments being only an alternative approach.

In many cases we can use a simple ?key=value query parameter.

When creating a new entity in a dependent dropdown setting with two fields (the entity reference field_city depending on another field_country), we however might want to use the Prepopulate module to prepopulate both field_country and the (dependent) entity reference field_city. We could easily do so, setting both fields at the same time using a single query parameter for field_country that is also caught by the entity reference view and used to restrict the referenceable entities in field_city.

Prepopulate however expects all parameters in the ?edit[field_xyz] form in order to avoid name collisions, and our QueryParameter default argument doesn't support this kind of array structure. Or actually it does. The only problem is the

if ($current_request->query->has($this->options['query_param'])) {

clause, as the flattened edit[field_xyz] parameter is send to ParameterBag->has() which uses array_key_exists() to find the (string) needle in the (array) haystack. Which can't work.

I'm not sure if beyond Prepopulate module there is any use for this kind of array structure in query parameters, and clearly this could be solved by prepopulate module itself, by supplying an altered QueryParameter default argument plugin. On the other hand, why wouldn't we want to support this kind of array structure in Core views, plus the parse_str making this work isn't expensive at all.

Issue fork drupal-3027705

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

Pancho created an issue. See original summary.

pancho’s picture

Status: Active » Needs review
StatusFileSize
new1.01 KB
pancho’s picture

Issue tags: +Needs tests

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new197 bytes

The Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

claudiu.cristea made their first commit to this issue’s fork.

claudiu.cristea’s picture

Status: Needs work » Needs review
claudiu.cristea’s picture

Issue tags: -Needs tests

Added test coverage

claudiu.cristea’s picture

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs Review Queue Initiative, +Needs issue summary update

Could the issue summary be updated to include what the proposed solution was.

Ran the tests locally without the fix and of the 3 news one
first =failed
second = failed
third = passed

Can you confirm the third one should still pass?

Thanks!

claudiu.cristea’s picture

Issue summary: View changes
Status: Needs work » Needs review
Issue tags: -Needs issue summary update

Can you confirm the third one should still pass?

Yes, it's expected behaviour with the current code because the plugin is not able to handle query params such as foo[bar]

Updated the IS.

claudiu.cristea’s picture

Category: Feature request » Bug report

And for me this looks like a bug.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Thanks for clarifying!

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

  • catch committed 06485719 on 10.0.x
    Issue #3027705 by claudiu.cristea, Pancho, smustgrave: Allow ?edit[...

  • catch committed 3400fd6d on 10.1.x
    Issue #3027705 by claudiu.cristea, Pancho, smustgrave: Allow ?edit[...

  • catch committed 471c0afd on 11.x
    Issue #3027705 by claudiu.cristea, Pancho, smustgrave: Allow ?edit[...

  • catch committed ff589230 on 9.5.x
    Issue #3027705 by claudiu.cristea, Pancho, smustgrave: Allow ?edit[...
catch’s picture

Version: 11.x-dev » 9.5.x-dev
Status: Reviewed & tested by the community » Fixed

Committed/pushed to 11.x and cherry-picked back through to 9.5.x, thanks!

claudiu.cristea’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.