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.

CommentFileSizeAuthor
#63 interdiff-2427803-62-63.txt1.25 KBprudloff
#63 drupal-2427803-63.patch14.28 KBprudloff
#62 interdiff-2427803-60-62.txt598 bytesprudloff
#62 drupal-2427803-62.patch14.43 KBprudloff
#60 interdiff-59-60.txt869 bytesprudloff
#60 drupal-2427803-60.patch14.5 KBprudloff
#59 interdiff-57-58.txt3.48 KBprudloff
#59 drupal-2427803-58.patch14.5 KBprudloff
#58 2427803-nr-bot.txt1.79 KBneeds-review-queue-bot
#57 interdiff-56-57.txt1018 bytesprudloff
#57 drupal-2427803-57.patch12.33 KBprudloff
#56 2427803-56.patch12.22 KB_utsavsharma
#56 interdiff_54-56.txt3.77 KB_utsavsharma
#55 2427803-nr-bot.txt4.09 KBneeds-review-queue-bot
#54 interdiff-53-54.txt4.51 KBprudloff
#54 drupal-2427803-54.patch12.61 KBprudloff
#53 drupal-2427803-53.patch12.7 KBprudloff
#51 2427803-nr-bot.txt144 bytesneeds-review-queue-bot
#49 2427803-49.patch9.96 KBranjith_kumar_k_u
#45 drupal-2427803-45.patch10.55 KBkishor_kolekar
#43 drupal-2427803-44.patch9.95 KBkishor_kolekar
#42 drupal-2427803-38.patch9.82 KBprudloff
#37 expose_target_type-2427803-33.patch10.09 KBJustin Langley
#32 expose_target_type-2427803-32.patch10.09 KBryan.gibson
#25 2423093-convert-menu-system-to-DEA-16.patch4.28 KBSam152
#25 Screen Shot 2017-05-24 at 5.19.21 PM-1.png84.32 KBSam152
#15 interdiff.txt812 bytesandyceo
#15 expose_target_type-2427803-14.patch10.43 KBandyceo
#13 expose_target_type-2427803-13.patch10.42 KBjibran
#11 expose_target_type-2427803-11.patch10.42 KBjibran
#11 interdiff.txt3.38 KBjibran
#7 expose_target_type-2427803-7.patch9.04 KBjibran
#7 interdiff.txt934 bytesjibran
#6 screenshot-d8.dev 2015-02-18 00-39-15.png26.29 KBjibran
#6 expose_target_type-2427803-5.patch8.87 KBjibran
#6 interdiff.txt6.73 KBjibran
#1 Screenshot from 2015-02-17 16:43:59.png6.83 KBjibran
#1 screenshot-d8.dev 2015-02-17 16-42-43.png17.38 KBjibran
#1 expose_target_type-2427803-1.patch3.04 KBjibran
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jibran’s picture

How about something like that?
Link Field setting forms.

Link Field widget.

amateescu’s picture

Yes, that's a start. Now we need the selection handler and its settings.

Status: Needs review » Needs work

The last submitted patch, 1: expose_target_type-2427803-1.patch, failed testing.

jibran’s picture

Now we need the selection handler and its settings.

Where in the link field settings form? We have to use ajax for that.

amateescu’s picture

Where in the link field settings form?

Below the target type selector?

We have to use ajax for that.

Of course :)

jibran’s picture

Issue summary: View changes
Status: Needs work » Needs review
FileSize
6.73 KB
8.87 KB
26.29 KB

I haven't tested it after saving the field but selection handler is now loaded using ajax.

jibran’s picture

FileSize
934 bytes
9.04 KB

Updated Link field widget as well.

jibran’s picture

+++ b/core/modules/link/src/Plugin/Field/FieldType/LinkItem.php
@@ -104,6 +108,100 @@ public function fieldSettingsForm(array $form, FormStateInterface $form_state) {
+        '#required' => TRUE,

We 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.

Status: Needs review » Needs work

The last submitted patch, 7: expose_target_type-2427803-7.patch, failed testing.

The last submitted patch, 6: expose_target_type-2427803-5.patch, failed testing.

jibran’s picture

Status: Needs work » Needs review
FileSize
3.38 KB
10.42 KB

Here is a workaround for #8.

Status: Needs review » Needs work

The last submitted patch, 11: expose_target_type-2427803-11.patch, failed testing.

jibran’s picture

Status: Needs work » Needs review
FileSize
10.42 KB

Just simple re-roll.

Status: Needs review » Needs work

The last submitted patch, 13: expose_target_type-2427803-13.patch, failed testing.

andyceo’s picture

Replace Utility/String with Utility/SafeMarkup

andyceo’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 15: expose_target_type-2427803-14.patch, failed testing.

NormySan’s picture

Is 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.

Wim Leers’s picture

Version: 8.0.x-dev » 8.1.x-dev

I think this would have to happen in 8.1 since it changes the UI.

jibran’s picture

Issue tags: +Needs tests

Needs Tests as well.

NormySan’s picture

I'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.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.0-beta1 was released on March 2, 2016, which means new developments and disruptive changes should now be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Sam152’s picture

Just 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.

Rob230’s picture

I 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.

Sam152’s picture

The selection handler settings allow you limit by bundle.

Rob230’s picture

Are you saying that's currently in core?

Sam152’s picture

Nope, sorry. Only that it's currently supported by both patches in this issue.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

ryan.gibson’s picture

Status: Needs work » Needs review
FileSize
10.09 KB

Re-rolling patch from #15.

Status: Needs review » Needs work

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

ryan.gibson’s picture

I'm not sure how the patch ever worked, since

$uri = 'entity:'. self::getFieldSetting('target_type') .'/' . $entity_id;

is using a static call to getFieldSetting, which isn't a static function.

olafkarsten’s picture

@ryanissamson
You can call self::methodName() to call the current classes implementation of a method. [php.net]

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Justin Langley’s picture

Was 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()

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

prudloff’s picture

#37 causes crashes for existing fields because the parameter is not yet set:

Missing required #target_type parameter.

This new patch adds a fallback on node.

kishor_kolekar’s picture

Status: Needs work » Needs review
FileSize
9.95 KB

patch #42 Failed to apply re-roll the patch

kishor_kolekar’s picture

Assigned: Unassigned » kishor_kolekar
kishor_kolekar’s picture

Assigned: kishor_kolekar » Unassigned
FileSize
10.55 KB

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

ranjith_kumar_k_u’s picture

Rerolled #45

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
FileSize
144 bytes

The 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.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

prudloff’s picture

Status: Needs work » Needs review
FileSize
12.7 KB

I 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.)

prudloff’s picture

#53 was causing errors with existing fields, it should be better now.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
FileSize
4.09 KB

The 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.

_utsavsharma’s picture

Tried to fix failures in #54.

prudloff’s picture

Status: Needs work » Needs review
FileSize
12.33 KB
1018 bytes

Just noticed it triggers an exception in the widget when the target_type setting is empty.
I updated the patch to fix that.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
FileSize
1.79 KB

The 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.

prudloff’s picture

Status: Needs work » Needs review
FileSize
14.5 KB
3.48 KB

LinkWidget tries to call getFieldSetting statically and it can't work.

prudloff’s picture

Fixed a notice when handler_settings is NULL.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs upgrade path

Was 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.

prudloff’s picture

#60 was using the new node handler by default instead of keeping the old behavior.
The new handler should be opt-in.

prudloff’s picture

FileSize
14.28 KB
1.25 KB

Reroll for Drupal 10.2.5.