Problem/Motivation

When searching on e.g. a node path or the frontpage (/), query parameters and fragments are stripped from the URL in the suggested paths.

Proposed resolution

When the user is entering an URL with query parameters or fragments, add them to the suggested path.

Steps to reproduce

  1. Enter a path to a node with query parameter or a fragment e.g. /node/1?test=1
  2. Linkit will show the entered node as a suggestion.
  3. Click on the suggestion. The query parameters are now removed from the field.

Issue fork linkit-3223919

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

JeroenT created an issue. See original summary.

jeroent’s picture

Status: Active » Needs review
StatusFileSize
new4.39 KB
new7.3 KB
jeroent’s picture

Issue summary: View changes
jeroent’s picture

Status: Needs review » Needs work

The last submitted patch, 2: 3223919-2.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

jeroent’s picture

Status: Needs work » Needs review
jeroent’s picture

StatusFileSize
new7.15 KB
new868 bytes

Removed 2 unused use statements.

Status: Needs review » Needs work

The last submitted patch, 7: 3223919-7.patch, failed testing. View results

jeroent’s picture

Status: Needs work » Needs review
idebr’s picture

Wasn't this fixed in #2895153: Linkit filter should honour the URL query and fragment?

The issue title mentions query parameters are stripped from the input URL, but the issue summary mentions the query parameters are stripped from the suggestion paths. What exactly is being fixed here?

jeroent’s picture

Updated the IS. I hope it makes more sense now.

The problem is that when you enter a path with a query parameter e.g. /node/1?test=1, the EntityMatcher will recognise this path as a node path and a suggestion is shown:

When you click on the suggestion the entered query parameters and fragments are removed:

The patch in #7 makes sure that the query parameters and fragment are preserved, when clicking on the suggestion.

This issue was a follow-up of #2712951: Linkit for Link field but it seems the same behaviour occurs when using the dialog in a CKEditor field.

stefan.atanasov’s picture

Hey,

I can confirm that preserving query parameters was reported as expected behaviour from a client and applying this patch solves it.

Details:

  • Drupal: 9.2.6
  • Linkit: 6.0.0-beta3
  • php: 7.4.19
  • MariaDB: 10.5.10

Please do let me know if you need more details regarding the case and I'll try to comeback to you asap.

Cheers!
Stefan

rajeshreeputra’s picture

StatusFileSize
new42.75 KB
new43.05 KB

I can confirm linkit is not removing the query parameter from the field even after clicking on the suggestion.

Details:

  1. Drupal: 9.3.3
  2. Linkit: 6.0.0-beta3
  3. php: 7.4.27
jeroent’s picture

Status: Needs review » Reviewed & tested by the community

Moving to rtbc, since 2 separate people mentioned the patch is working.

bogdan.dinu’s picture

StatusFileSize
new6.02 KB

I don't think the proposed solution is ok because it is saving the query and fragment in the uri. That is not compatible with the core link schema or other modules that use the core link schema.
I propose saving the query and fragment in the options base field of the link field as described in the core link schema.
My solution only works with the patch from this issue on linkit_field https://www.drupal.org/project/linkit_field/issues/3349013
because the linkit widget from linkit doesn't use the node path/alias.

bogdan.dinu’s picture

StatusFileSize
new8.71 KB

The previous patch is incomplete. I appologize!
I uploaded a new one (it is based on the patch from #7).

mark_fullmer’s picture

My solution only works with the patch from this issue on linkit_field

Just a note that recently #2712951: Linkit for Link field was merged into the 6.0.x branch, so a patch that addresses this for the link field context can build on that foundation.

mark_fullmer’s picture

Note that the equivalent issue reported on the 6.x branches for this module has been fixed in #3359375: Query fragments or anchors on internal URLs in link fields get lost on re-editing.

As is practicable, sites should update to 6.x rather than continuing to use 8.x-5.x

mark_fullmer’s picture

Version: 8.x-5.x-dev » 7.x-dev

Update: upon revisiting this now, my analysis in #18 is incorrect. *This* issue describes a different request than was dealt with in #3359375: Query fragments or anchors on internal URLs in link fields get lost on re-editing. Setting this to track the current development branch for Linkit.

mark_fullmer’s picture

Status: Reviewed & tested by the community » Needs review

I've added an MR that is based on the patch from #16 that applies to the 7.x branch. Setting back to needs review based on the change between #14 and #16.

mark_fullmer’s picture

Status: Needs review » Needs work

This introduces test failures, per https://git.drupalcode.org/project/linkit/-/jobs/5001403 . Setting back to "Needs work."

rhezios made their first commit to this issue’s fork.

rhezios’s picture

Status: Needs work » Needs review
StatusFileSize
new14.88 KB

Snapshot of latest state of MR for usage with composer patches

mark_fullmer’s picture

Status: Needs review » Needs work

timohuisman made their first commit to this issue’s fork.

timohuisman’s picture

Status: Needs work » Needs review
StatusFileSize
new13.21 KB

I've updated the MR with the latest changes from 7.x. The test failures from #22 are resolved. Attached is a snapshot of the current state of the MR, so it can be safely used with composer-patches.

I've used Claude Code to debug the CI failures.

idebr’s picture

Status: Needs review » Needs work

\Drupal\linkit\Plugin\Linkit\Matcher\FrontPageMatcher::getQueryAndFragment can be replaced with \Drupal\linkit\Utility\LinkitHelper::getQueryAndFragment now that #2712951: Linkit for Link field is committed

timohuisman’s picture

Status: Needs work » Needs review

#28 is addressed in the MR, thanks.

idebr’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me! I'll mark this RTBC so @mark_fullmer has the chance to take a second look before commit

mark_fullmer’s picture

Assigned: Unassigned » mark_fullmer
mark_fullmer’s picture

Status: Reviewed & tested by the community » Fixed

This all looks good to me. Thanks everyone for the work, and especially @timohuisman for updating the MR and @idebr for the review!

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.