Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
#2418017: Implement autocomplete UI for the link widget implemented the 'entity_autocomplete' form element in LinkWidget but hardcoded the target type to 'node'.
Proposed resolution
We should expose the target type, selection handler and selection settings as widget settings in LinkWidget.
Remaining tasks
Do it.
User interface changes
Three new elements will be exposed in Field UI for the default link widget.
API changes
Nope.
Comment | File | Size | Author |
---|---|---|---|
#63 | interdiff-2427803-62-63.txt | 1.25 KB | prudloff |
#63 | drupal-2427803-63.patch | 14.28 KB | prudloff |
#59 | drupal-2427803-58.patch | 14.5 KB | prudloff |
#58 | 2427803-nr-bot.txt | 1.79 KB | needs-review-queue-bot |
#56 | 2427803-56.patch | 12.22 KB | _utsavsharma |
Comments
Comment #1
jibranHow about something like that?
Link Field setting forms.
Link Field widget.
Comment #2
amateescu CreditAttribution: amateescu commentedYes, that's a start. Now we need the selection handler and its settings.
Comment #4
jibranWhere in the link field settings form? We have to use ajax for that.
Comment #5
amateescu CreditAttribution: amateescu commentedBelow the target type selector?
Of course :)
Comment #6
jibranI haven't tested it after saving the field but selection handler is now loaded using ajax.
Comment #7
jibranUpdated Link field widget as well.
Comment #8
jibranWe have to toggle this and
target_bundles
required to FALSE when$element['selection']
is hidden to submit the form in chrome. See https://code.google.com/p/chromium/issues/detail?id=45804 and http://stackoverflow.com/a/12486761.Comment #11
jibranHere is a workaround for #8.
Comment #13
jibranJust simple re-roll.
Comment #15
andyceo CreditAttribution: andyceo commentedReplace Utility/String with Utility/SafeMarkup
Comment #16
andyceo CreditAttribution: andyceo commentedComment #18
NormySan CreditAttribution: NormySan as a volunteer and at Odd Hill commentedIs there anything left to do on this issue? I was thinking about implementing a new link field with this functionality but would gladly help to get it into core as son as possible instead.
Comment #19
Wim LeersI think this would have to happen in 8.1 since it changes the UI.
Comment #20
jibranNeeds Tests as well.
Comment #21
NormySan CreditAttribution: NormySan as a volunteer and at Odd Hill commentedI'll look into this when i get the time. I'll probably create a separate module with a new field in the meantime for my own needs and then attempt to port this functionality back into core if no one else has done it already.
Comment #25
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedJust cross-posting a solution to this problem from 2423093 which isn't ready for core, but supports multiple entity types.
It relies on a patch, plus a sandbox for half-working mutli-entity autocomplete options: https://www.drupal.org/sandbox/sam/2881047.
Needs quite a bit of tidy-up, but a workable solution if anyone needs it.
Comment #26
Rob230 CreditAttribution: Rob230 commentedI have hundreds of generated nodes which clog up the suggestions, making the autocomplete useless (can't ever choose any internal link because the 10 shown are always one of the generated ones). Would be nice to have the option to limit on content type.
Comment #27
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedThe selection handler settings allow you limit by bundle.
Comment #28
Rob230 CreditAttribution: Rob230 commentedAre you saying that's currently in core?
Comment #29
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedNope, sorry. Only that it's currently supported by both patches in this issue.
Comment #32
ryan.gibson CreditAttribution: ryan.gibson at Mediacurrent commentedRe-rolling patch from #15.
Comment #34
ryan.gibson CreditAttribution: ryan.gibson at Mediacurrent commentedI'm not sure how the patch ever worked, since
is using a static call to getFieldSetting, which isn't a static function.
Comment #35
olafkarsten CreditAttribution: olafkarsten as a volunteer commented@ryanissamson
You can call self::methodName() to call the current classes implementation of a method. [php.net]
Comment #37
Justin Langley CreditAttribution: Justin Langley as a volunteer commentedWas unable to apply this against 8.6.2. There was a missing dangling comma inside `src/Plugin/Field/FieldType/LinkItem.php` around line 36.This patch applies cleanly to 8.6.2.I also fixed as issue where existing link fields would crash since there was no `handler` specified on the field settings. Looking through others it seems the string `default` was an acceptable value to default to if there was no handler specified.Seems the
self::getFieldSetting('target_type')
does actually throw an exception on PHP 7.2.Error: Using $this when not in object context in Drupal\Core\Field\WidgetBase::getFieldSetting()
Comment #42
prudloff CreditAttribution: prudloff at Insite commented#37 causes crashes for existing fields because the parameter is not yet set:
This new patch adds a fallback on
node
.Comment #43
kishor_kolekar CreditAttribution: kishor_kolekar as a volunteer and at QED42 for Drupal India Association commentedpatch #42 Failed to apply re-roll the patch
Comment #44
kishor_kolekar CreditAttribution: kishor_kolekar as a volunteer and at QED42 for Drupal India Association commentedComment #45
kishor_kolekar CreditAttribution: kishor_kolekar as a volunteer and at QED42 for Drupal India Association commentedComment #49
ranjith_kumar_k_u CreditAttribution: ranjith_kumar_k_u at Zyxware Technologies commentedRerolled #45
Comment #51
needs-review-queue-bot CreditAttribution: needs-review-queue-bot as a volunteer commentedThe 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.
Comment #53
prudloff CreditAttribution: prudloff at Insite for Muséum national d'Histoire naturelle commentedI tried to reroll the #49 patch for 9.5.9 but the field settings form was not working correctly: settings were not saved and AJAX requests did nothing.
I reworked the patch and now everything seems to work on my setup.
Unfortunately, I had to duplicate some methods from
EntityReferenceItem
.(I tried to generate an interdiff but it fails for some reason.)
Comment #54
prudloff CreditAttribution: prudloff at Insite for Muséum national d'Histoire naturelle commented#53 was causing errors with existing fields, it should be better now.
Comment #55
needs-review-queue-bot CreditAttribution: needs-review-queue-bot as a volunteer commentedThe Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
This does not mean that the patch needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #56
_utsavsharma CreditAttribution: _utsavsharma at OpenSense Labs for DrupalFit commentedTried to fix failures in #54.
Comment #57
prudloff CreditAttribution: prudloff at Insite for Muséum national d'Histoire naturelle commentedJust noticed it triggers an exception in the widget when the target_type setting is empty.
I updated the patch to fix that.
Comment #58
needs-review-queue-bot CreditAttribution: needs-review-queue-bot as a volunteer commentedThe Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
This does not mean that the patch needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #59
prudloff CreditAttribution: prudloff at Insite for Muséum national d'Histoire naturelle commentedLinkWidget
tries to callgetFieldSetting
statically and it can't work.Comment #60
prudloff CreditAttribution: prudloff at Insite for Muséum national d'Histoire naturelle commentedFixed a notice when handler_settings is NULL.
Comment #61
smustgrave CreditAttribution: smustgrave at Mobomo commentedWas previously tagged for tests which I believe are still needed.
And with the schema change an upgrade path may be needed.
But also there seemed to be some failures.
Comment #62
prudloff CreditAttribution: prudloff at Insite for Muséum national d'Histoire naturelle commented#60 was using the new node handler by default instead of keeping the old behavior.
The new handler should be opt-in.
Comment #63
prudloff CreditAttribution: prudloff at Insite for Muséum national d'Histoire naturelle commentedReroll for Drupal 10.2.5.