Problem/Motivation
Using the link field with a link like this: /my-page?myparam[2021]=2021 when printed looks like this: /my-page?myparam[0]=2021&myparam[1]=2021
This is a problem when you try to add links to filtered views because even though the filters get applied, the boxes don't get checked.
Steps to reproduce
- Create a link field
- Point to an internal view page with filters in the url like: /my-page?myparam[2021]=2021
Expected behavior
- Link will be printed as entered
Current behavior
- Link gets printed like this: /my-page?myparam[0]=2021&myparam[1]=2021
Proposed resolution
Issue seems to be in line https://git.drupalcode.org/project/drupal/-/blob/9.2.x/core/lib/Drupal/C... that gets the options wicked up.
If we change that line to
$options = NestedArray::mergeDeepArray([$element['#url']->getOptions(), $element['#options']], TRUE);
it will work, but I'm unsure of the underlying effects of this.
Remaining tasks
- Analyze proposed solution
- Create patch and commit
User interface changes
None
API changes
None
Data model changes
None
Release notes snippet
Comment | File | Size | Author |
---|
Issue fork drupal-3191456
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
Comment #2
cilefen CreditAttribution: cilefen as a volunteer commentedIs this the same as #3079694: URL query string is broken on render?
Comment #3
kporras07 CreditAttribution: kporras07 as a volunteer commentedHmmm, not 100% sure but it looks related. I guess we could concentrate discussion only in one of the issues and then test the other one when fixed.
I'm not sure which issue is the best to keep the discussion.
Comment #4
kporras07 CreditAttribution: kporras07 as a volunteer and at Evolving Web commentedI'm using this patch in the site where I found this issue. Hopefully it will help to trigger the discussion
Comment #10
pcambraI've found this bug on a site today and patch in #4 works great.
Comment #11
needs-review-queue-bot CreditAttribution: needs-review-queue-bot as a volunteer commentedThe Needs Review Queue Bot tested this issue.
While you are making the above changes, we recommend that you convert this patch to a merge request. Merge requests are preferred over patches. Be sure to hide the old patch files as well. (Converting an issue to a merge request without other contributions to the issue will not receive credit.)
Comment #13
arisenThe patch in #4 resolves the issue. Created a MR.
mergeDeep
is internally usingmergeDeepArray
with preserve integer keys set to FALSE by default.In the patch we are passing it as TRUE to keep the keys as it is. Should be fine IMO.
This might need some tests.
Comment #14
pcambra@arisen seems you've created the branch but not the actual MR?
Comment #16
pcambraComment #17
arisenWhat would be the ideal place to add a Kernel Test for this?
Wondering if it can added as part of
core/modules/system/tests/src/Kernel/Common/UrlTest.php
orcore/tests/Drupal/KernelTests/Core/Render/Element/RenderElementTypesTest.php
Comment #18
smustgrave CreditAttribution: smustgrave at Mobomo commentedFor the tests.
Comment #19
arisenComment #20
smustgrave CreditAttribution: smustgrave at Mobomo commentedRan the test only feature and it seemed to pass without the fix https://git.drupalcode.org/issue/drupal-3191456/-/jobs/707698 so not testing what we think it is. While updating please add :void to any new test function.
Comment #21
arisen@smustgrave The issue is no longer reproducible on D11 but still existing on D10(checked on 10.2.2).
Seems like
NestedArray::mergeDeep
was not the root cause.Looks like there has been some changes to the link preprocessing logic.
$options = NestedArray::mergeDeep($element['#url']->getOptions(), $element['#options']);
On D11, $element['#options'] is an empty array so the issue is no longer occurring, whereas on D10 its having the params info same as $element['#url']->getOptions().
Comment #22
smustgrave CreditAttribution: smustgrave at Mobomo commentedThen think we need some research about what issue was committed to 11 that didn’t get backported to 10 that fixed this issue.
Comment #23
arisen@smustgrave found the issue https://www.drupal.org/project/drupal/issues/2885351
It's already been added to 10.2 also.
Comment #24
smustgrave CreditAttribution: smustgrave at Mobomo commentedThen this should be closed.
Comment #25
smustgrave CreditAttribution: smustgrave at Mobomo commentedNote the related issue was merged 2 days ago so not in a tagged release yet