Problem/Motivation
I have Linkit selected as widget for Link field and it always works correctly when the suggestion is clicked and used to select the wanted link target. However sometimes the content editors just want to paste in the target path or external URL and not to click on the suggestion. When this is done, the value seems to be saved at first but when returning to the edit view, the old value is back in the field.
Steps to reproduce
1) Configure a node link field to use Linkit widget
2) Create a node with an internal route on the link field
3) Open the node edit form. Type into the URL field an external route, such as "https://google.com" or some local path
4) Do not click on the dropdown suggestions. Instead click "Save" to save the node directly.
5) Check that field value seems to have changed first in the node view and then go back to node edit to see the old value back
Proposed resolution
I found that marcoscano already found this issue in the issue https://www.drupal.org/project/linkit/issues/2712951#comment-12605809 for adding Linkit support for fields. He first added a fix for it but then reverted it since he found some issues with it. I wasn't able to replicate his issues in the current module version.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | linkit-field-value-save-3389847-2.patch | 1.43 KB | thatguy |
Issue fork linkit-3389847
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
thatguy commentedHere is a patch with marcoscanos fix from https://www.drupal.org/project/linkit/issues/2712951#comment-12605809
Comment #3
thatguy commentedComment #4
mark_fullmerSetting this issue priority to "Major," since I consider this to be a significant user experience problem. Will review this soon.
Comment #7
hawkeye.twolfMR !28 adds support for maintaining fragments and query strings (the issue that @marcoscano noted in the LinkIt for Fields issue).
Comment #8
thatguy commentedMR !28 seems to fix the issue
Comment #9
mark_fullmerI'm unable to reproduce an issue specific to query parameters or anchor links that seems to necessitate the more substantial change proposed in MR !28.
The less substantial change proposed in #2 seems to resolve all scenarios that I have tested. If there is a scenario that requires the more involved change proposed in the MR, can someone provide steps to reproduce?
Here are the steps that I used to test #2 that demonstrate that the patch resolves the original problem:
Scenario 1: Basic URL; Patch #2 passes
1) Configure a node link field to use Linkit widget
2) Create a node and set the link field to an internal route on the link field. After save, the link to the internal route will display correctly.
3) Open the node edit form. Type into the URL field "https://google.com"
4) Do not click on the dropdown suggestions. Instead click "Save" to save the node directly.
5) Check that field value seems to have changed first in the node view and then go back to node edit to see the old value back.
6) Go back to node edit and verify the value "https://google.com#test" is preserved.
Scenario 2: URL with query parameter; Patch #2 passes
1) Configure a node link field to use Linkit widget
2) Create a node and set the link field to an internal route on the link field. After save, the link to the internal route will display correctly.
3) Open the node edit form. Type into the URL field "https://google.com?test=1"
4) Do not click on the dropdown suggestions. Instead click "Save" to save the node directly.
5) Check that field value seems to have changed first in the node view and then go back to node edit to see the old value back.
6) Go back to node edit and verify the value "https://google.com" is preserved.
Scenario 3: URL with anchor link: Patch #2 passes
1) Configure a node link field to use Linkit widget
2) Create a node and set the link field to an internal route on the link field. After save, the link to the internal route will display correctly.
3) Open the node edit form. Type into the URL field "https://google.com#test"
4) Do not click on the dropdown suggestions. Instead click "Save" to save the node directly.
5) Check that field value seems to have changed first in the node view and then go back to node edit to see the old value back.
6) Go back to node edit and verify the value "https://google.com#test" is preserved.
Scenario 4: URLs with differing queries: Patch #2 passes
This scenario specifically tries to test the comment in MR 28:
1) Configure a node link field to use Linkit widget
2) Create a node and set the link field to an internal route on the link field. Append
#footo the internal route in the edit form. After save, the link to the internal route will display correctly, with the#fooanchor3) Open the node edit form. Type into the URL field "https://google.com#test"
4) Do not click on the dropdown suggestions. Instead click "Save" to save the node directly.
5) Check that field value seems to have changed first in the node view.
6) Go back to node edit and verify the value "https://google.com#test" is preserved.
Comment #10
hawkeye.twolfThank you for the review and thorough testing scenarios @mark_fullmer! 🙏🏻🙏🏻
I think the bug @marcoscano referred to was with the clearing of match metadata stored in the link field's "options" array. I didn't actually test his patch until now, and found out it breaks a little worse than I thought. I expected:
But it actually works like:* **
*Tested in Firefox on linux
**EDIT: I realized this is partially due to the placement of the listener. But even when I attached it to
$uriinstead of$autocomplete, it still had some bugs, where it would clear the previous item's metadata as soon as you edit a different item in the multivalue link field.Specifically, the options data we lose with the first patch are:
The approach in MR 28 attempts to be less aggressive in clearing the match metadata. Specifically when any portion of the link changes, besides query string and fragment.
Comment #13
mark_fullmerThanks for clarifying, hawkeye.twolf! I understand how the patch in #2 is too aggressive. (The way I'd put it is: the hidden form inputs should not be cleared until a user either explicitly accepts the autocomplete suggestion or saves the form. Testing the MR with this in mind, it makes good sense to me.
Merged into the 6.0.x and 6.1.x branches.
Comment #14
hawkeye.twolfGreat :D I see new releases already cut—thanks so much @mark_fullmer!