Problem/Motivation
As link widget for internal links allows to have entity reference autocomplete, it would be nice to have opportunity to select the reference method the same way as it is possible for entity reference field. This way it would be possible to easily find content that is needed using, for example, views entity reference handler.
We can also add the same settings available to the default entity reference widget that allow for customization of how matches are queried and the number of matches returned.
Steps to reproduce
Standard Drupal installation, article content type, add link field allowing both internal and external links or only internal.
Proposed resolution
Add handler and handler_settings field settings to the LinkItem field type.
Add match_operator and match_limit settings to the LinkWidget.
Remaining tasks
Usability review
User interface changes
Field settings for link field type would have "Reference method" setting, the same as entity reference field.
Before:

After:

Link widget settings will allow setting the "Autocomplete matching" and "Number of Results".
Before:

After:

API changes
None
Data model changes
None
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #40 | 3373258-MR5993-v6.patch | 33.62 KB | inaw |
| #34 | 3373258-MR5993-v5.patch | 34.42 KB | ilianoz |
| #32 | 3373258-MR5993-v4.patch | 35.38 KB | taran2l |
| #4 | 3373258-link-field-handler-settings-4.patch | 20.29 KB | a.dmitriiev |
| #2 | 3373258-link-field-handler-settings-2.patch | 19.54 KB | a.dmitriiev |
Issue fork drupal-3373258
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
a.dmitriiev commentedAttaching the first patch. It is mostly the copy from EntityReferenceItem class
Comment #3
a.dmitriiev commentedComment #4
a.dmitriiev commentedForgot config schema changes.
Comment #5
a.dmitriiev commentedUploading the patch that combines also match_limit and match_operator settings from related issue.
Comment #7
a.dmitriiev commentedUpdating
trigger_errorformatComment #8
a.dmitriiev commentedI have a question how now to change content of this file
core/modules/system/tests/fixtures/update/drupal-9.4.0.filled.standard.php.gz, because now the trigger_error makes the tests failComment #9
a.dmitriiev commentedTrying to fix tests and the logic of the update. Add update test.
Comment #10
a.dmitriiev commentedComment #13
a.dmitriiev commentedFixing tests.
Comment #15
a.dmitriiev commentedFixing core/modules/link/tests/src/Functional/LinkFieldUITest.php test
Comment #16
smustgrave commentedCould a CR be written for this new change and setting please.
Comment #17
a.dmitriiev commentedI have created a change record https://www.drupal.org/node/3375174 . This is my first change record, so please take it into account. Is it ok to have screenshots in the change record? Or it should be more "textish"?
Comment #18
a.dmitriiev commentedI have rephrased the change record, so it is easier to read.
Comment #19
smustgrave commentedOn a standard install
Applied patch
Create a basic page and article page
Verified the post_update hooks run without issue.
Added a link field to the Article content type and only allowed link reference to Basic pages
Created another Article page and searching for article page from before didn't show up but basic page did.
Comment #20
quietone commentedI am doing triage on the core RTBC queue.
The patch needs an update, setting to needs work.
The issue summary is straight forward with a proposed resolution. This is making changes to the UI so I am adding the Usability tag. There are no unanswered items in the comments. The patch has been manually tested, including the post_update hook. But all changes need a code review as well.
@a.dmitriiev, thank you for your first change record! It has all the sections that it should. Nice job!
Looking at the screenshots in the CR, the first one has 'Browse available tokens' which is not a string in core. The screenshots are nearly always made from a 'standard' install. Can someone update that? I also think it would be easier for the reader if the 'Field Settings' screenshots were a smaller. If needed, they could just include the 'Allowed link type' and the 'Allow link text' section. Oh, and the text would benefit from some improvements for grammar and readability.
Comment #21
a.dmitriiev commentedI have changed the images in change record.
Comment #23
quietone commentedI changed the status of #3341689: Port entity reference widget autocomplete settings to link field widget to duplicate, and now moving credit.
Comment #24
quietone commentedOh, I meant to remove a tag. And I think it was supposed to be 'needs change record updates'.
Comment #25
a.dmitriiev commentedAnyone knows how to move forward here? What changes should be done to change record? Are there any instructions on how to proceed?
Comment #26
smustgrave commentedI believe @quietone meant in #20 the tag should of been "needs change record updates" which appears you addressed in #21
But relooking at the patch it appears to be failing drupalCi, recommend turning into an MR for easier reviews.
Too many to list but all new functions should have a typehint return even if it's :void.
Deprecation can probably be bumped from 10.2 to 10.3
Comment #28
a.dmitriiev commentedI have converted patch to MR. All jobs in the pipeline for MR were successful.
Comment #29
smustgrave commentedComment #30
a.dmitriiev commentedAll new functions and their parameters now have typehints. Please review MR once again.
Comment #31
smustgrave commentedFeedback has been addressed.
Comment #32
taran2lAttaching a static patch from the latest changes in the MR (for composer patching purposes)
Comment #33
quietone commentedI'm triaging RTBC issues. I read the IS and the comments. I didn't find any unanswered questions.
I see that the issue summary has remaining tasks that I think are completed. But as I think about this some more it needs more input from UI folds. I am tagging for a UX review..
Comment #34
ilianoz commentedComment #36
dcam commentedThe MR needed a rebase badly. I took care of it.
I also updated the issue summary. There was no mention of the changes to the
LinkWidgetsettings. I'm not 100% convinced they belong in this same issue, but since this was already RTBC twice I won't stop it.Since this hasn't undergone a usability review I'm setting the status to Needs Review.
Comment #37
a.dmitriiev commented@dcam, thank you for rebasing the code. Regarding LinkWidget: the changes are described in the issue description with screenshots of Before and After
Comment #38
rkollerafter checking out MR5993, i run
ddev drush cri get the following error:... on 11.x i dont get that error. i am on php 8.3 with ddev.
Update: the error happened also after i'Ve dropped the db and reinstalled the site. per @benjifisher recommendation i should have tried
git merge 11.xorgit rebase 11.x. i first tried the rebase but that had conflicts. I'Ve aborted the rebase and tried the merge and that went through. after the merge of the latest 11.x i was able to rundrush crwithout any errors. so i suppose the MR needs a rebase as well?Comment #39
benjifisherUsability review
We discussed this issue at #3555446: Drupal Usability Meeting 2025-11-14. That issue has a link to a recording of the meeting. I am giving issue credit here to the attendees at the usability meeting: @benjifisher, @rkoller, and @simohell.
There are a few usability issues we noticed while testing the current MR:
<details>element "Reference type" applies to internal links.<details>element separates the existing options. Experienced site builders are used to having those options next to each other.<select>element triggers an AJAX reload, which scrolls to the top of the modal window.The last point is out of scope for this issue, since it is an existing problem (for reference fields). But please check for an existing issue, and add a new one if you cannot find one. I am adding the issue tag for a followup issue.
The usability team suggests the following steps to fix the other issues:
<details>element to "Reference method for internal links".<details>element collapsed by default.We think that the new feature is something that most sites will not use, so we want to add it in a way that interrupts the existing workflow as little as possible. After (2), a site builder can submit the form, accepting defaults. As a result, there is no problem with (3).
If you want more feedback from the usability team, a good way to reach out is in the #ux channel in Slack.
Comment #40
inaw commented