Allow filtering the link autocomplete by content type. This patch adds a checklist of content types to the link field settings and filters the autocomplete in the widget to only return nodes of one of the content types selected in the settings.

CommentFileSizeAuthor
#62 2887376-62.patch12.39 KBglenndw
#54 reroll_diff_50-54.txt7.73 KBjhandsta
#54 2887376-54.patch11.22 KBjhandsta
#50 interdiff_47-50.txt1.46 KBatul4drupal
#50 2887376-50.patch11.35 KBatul4drupal
#47 interdiff_45-47.txt1.67 KBsuresh prabhu parkala
#47 2887376-47.patch10.74 KBsuresh prabhu parkala
#45 link-autocomplete-ct-filter-2887376-45-9.2.x.patch11.88 KBrahulrasgon
#43 link-autocomplete-ct-filter-2887376-43-8.9.x.patch12.64 KBrahulrasgon
link-autocomplete-ct-filter-2887376-37-8.7.x.patch11.1 KBmoshe weitzman
link-autocomplete-ct-filter-2887376-37-8.7.x.patch11.23 KBmoshe weitzman
#39 link-autocomplete-ct-filter-2887376-39-8.7.x.patch13.08 KBnavneet0693
#36 interdiff_35-36.txt4.46 KBmichael_wojcik
#36 link-autocomplete-ct-filter-2887376-36-8.5.x.patch11.28 KBmichael_wojcik
#36 link-autocomplete-ct-filter-2887376-36-8.6.x.patch11.23 KBmichael_wojcik
#35 interdiff_34-35.txt1.6 KBmichael_wojcik
#35 link-autocomplete-ct-filter-2887376-35-8.5.x.patch10.45 KBmichael_wojcik
#35 link-autocomplete-ct-filter-2887376-35-8.6.x.patch10.4 KBmichael_wojcik
#34 interdiff_33-34.txt7.41 KBmichael_wojcik
#34 link-autocomplete-ct-filter-2887376-34-8.5.x.patch10.19 KBmichael_wojcik
#34 link-autocomplete-ct-filter-2887376-34-8.6.x.patch10.13 KBmichael_wojcik
#33 interdiff_26-33.txt4.14 KBmichael_wojcik
#33 link-autocomplete-ct-filter-2887376-33-8.5.x.patch10.05 KBmichael_wojcik
#33 link-autocomplete-ct-filter-2887376-33-8.6.x.patch10 KBmichael_wojcik
#31 patch_interdiff_26-31.txt777 bytesmichael_wojcik
#31 link-autocomplete-ct-filter-2887376-31.patch10.13 KBmichael_wojcik
#26 interdiff_24-26.txt4.23 KBmichael_wojcik
#26 link-autocomplete-ct-filter-2887376-26.patch10.08 KBmichael_wojcik
#25 interdiff_24-25.txt5.42 KBmichael_wojcik
#25 link-autocomplete-ct-filter-2887376-25.patch8.89 KBmichael_wojcik
#24 interdiff_11-24.txt10.43 KBmichael_wojcik
#24 link-autocomplete-ct-filter-2887376-24.patch12.26 KBmichael_wojcik
#23 interdiff_11-23.txt10.62 KBmichael_wojcik
#23 link-autocomplete-ct-filter-2887376-23.patch12.45 KBmichael_wojcik
#21 interdiff_18-20.txt2.12 KBmichael_wojcik
#20 interdiff_18-20.patch2.12 KBmichael_wojcik
#20 link-autocomplete-ct-filter-2887376-20.patch11.75 KBmichael_wojcik
#18 interdiff_16-18.txt3.05 KBmichael_wojcik
#18 link-autocomplete-ct-filter-2887376-18.patch9.91 KBmichael_wojcik
#16 interdiff_14-16.txt548 bytesmichael_wojcik
#16 link-autocomplete-ct-filter-2887376-16.patch7.7 KBmichael_wojcik
#14 interdiff_11-14.txt4.49 KBmichael_wojcik
#14 link-autocomplete-ct-filter-2887376-14.patch7.16 KBmichael_wojcik
#11 link-autocomplete-ct-filter-2887376-11.patch3.09 KBrob230
#10 interdiff-2887376-5-10.txt649 bytesrob230
#10 link-autocomplete-ct-filter-2887376-10.patch3.09 KBrob230
#5 link-autocomplete-ct-filter-2887376-5-8.4.x.patch3.08 KBrobpowell
link-autocomplete-ct-filter.patch3.13 KBkbentham

Issue fork drupal-2887376

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

kbentham created an issue. See original summary.

cilefen’s picture

Version: 8.2.8 » 8.4.x-dev
cilefen’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, link-autocomplete-ct-filter.patch, failed testing. View results

robpowell’s picture

let's try this reroll against 8.4.x

robpowell’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 5: link-autocomplete-ct-filter-2887376-5-8.4.x.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

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.

rob230’s picture

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

Your patch worked for me, however it has an error: invalid argument supplied for foreach() when you haven't chosen any of the checkboxes yet.

I'll submit a patch that fixes that.

It would be great to get this in core. I have a lot of content types and most of them I don't want to show up as potential links.

rob230’s picture

rob230’s picture

Version: 8.4.x-dev » 8.5.x-dev
StatusFileSize
new3.09 KB

Rerolling for 8.5.x.

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.ryan’s picture

The patch applies cleanly and works as expected. Does this need test coverage to make it into core?

michael_wojcik’s picture

Title: Link Autocomplete content type filter. » Link Autocomplete content type filter
Status: Needs work » Needs review
StatusFileSize
new7.16 KB
new4.49 KB

Re-rolled patch for 8.6.x and added validation of optional content type within LinkWidget::validateUriElement.

Original patch did not include validation step for fields that make use of this new content type restriction option.

Status: Needs review » Needs work

The last submitted patch, 14: link-autocomplete-ct-filter-2887376-14.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

michael_wojcik’s picture

Status: Needs work » Needs review
StatusFileSize
new7.7 KB
new548 bytes

Patch re-rolled to update schema after test failure.

Status: Needs review » Needs work

The last submitted patch, 16: link-autocomplete-ct-filter-2887376-16.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

michael_wojcik’s picture

Status: Needs work » Needs review
StatusFileSize
new9.91 KB
new3.05 KB

Re-rolled for core unit test coverage.

Status: Needs review » Needs work

The last submitted patch, 18: link-autocomplete-ct-filter-2887376-18.patch, failed testing. View results

michael_wojcik’s picture

Status: Needs work » Needs review
StatusFileSize
new11.75 KB
new2.12 KB

Updates after further failed tests.

michael_wojcik’s picture

StatusFileSize
new2.12 KB

Mislabeled interdiff.

Status: Needs review » Needs work

The last submitted patch, 20: interdiff_18-20.patch, failed testing. View results

michael_wojcik’s picture

StatusFileSize
new12.45 KB
new10.62 KB
michael_wojcik’s picture

StatusFileSize
new12.26 KB
new10.43 KB
michael_wojcik’s picture

michael_wojcik’s picture

StatusFileSize
new10.08 KB
new4.23 KB
michael_wojcik’s picture

Status: Needs work » Needs review

The last submitted patch, 10: link-autocomplete-ct-filter-2887376-10.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

The last submitted patch, 11: link-autocomplete-ct-filter-2887376-11.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

The last submitted patch, 25: link-autocomplete-ct-filter-2887376-25.patch, failed testing. View results

michael_wojcik’s picture

#31 is simply a Drupal-8.5.x backport (for anyone who needs it) of #26, which is compatible with Drupal-8.6.x.

#26 should be the patch to be committed or updated going forward.

rbayliss’s picture

Status: Needs review » Needs work
  1. +++ b/core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php
    @@ -142,6 +169,36 @@ public static function validateUriElement($element, FormStateInterface $form_sta
    +        foreach ($content_types as $key => $type) {
    

    I think this can be expressed as:

    $content_types = array_filter($content_types);

    That should filter out all of the non-selected content types.

  2. +++ b/core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php
    @@ -142,6 +169,36 @@ public static function validateUriElement($element, FormStateInterface $form_sta
    +        $entity_type = key($params);
    

    Content types = node. We always know we're going to have a node here, so we should just check for the existence of $params['node'], then explicitly use node storage.

  3. +++ b/core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php
    @@ -142,6 +169,36 @@ public static function validateUriElement($element, FormStateInterface $form_sta
    +          $form_state->setError($element, t('Allowed content types for internal links: @content_types', [
    

    I think this message could be clearer. What about something like "You have referenced content of a type that is not allowed here. Allowed types: @content_types."

  4. +++ b/core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php
    @@ -196,6 +253,31 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen
    +        foreach ($content_types as $key => $type) {
    

    You can use array_filter() here too.

michael_wojcik’s picture

Status: Needs work » Needs review
StatusFileSize
new10 KB
new10.05 KB
new4.14 KB

Re-rolled patch for 8.6.x and 8.5.x based on comments in #32. Thanks @rbayliss!

Regarding the second proposed change in #32: Because of the ongoing work in https://www.drupal.org/node/2423093 to allow for multiple entity types within entity_autocomplete fields, I think we should try to keep our new code as generalized as possible, to allow for additional entity types in the future. I've adjusted the patch accordingly.

michael_wojcik’s picture

Updated patch to use more accurate entity_bundles name instead of content_types names for new field setting, to support future work being done in https://www.drupal.org/node/2423093.

michael_wojcik’s picture

  • Updated patch with a @todo to add other entity support for internal link entity types: currently just allows for nodes.
  • Added #states functionality to Link field settings forms for entity bundles.
michael_wojcik’s picture

Changed entity bundle field setting widget to use a select input instead of a checkbox.
Added human-readable entity bundle labels for error messages.

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.

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.

navneet0693’s picture

Re-rolled for 8.7.x

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.

rahulrasgon’s picture

Re-rolled for 8.9.x

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.

rahulrasgon’s picture

Re-rolled for 9.2.x

chetanbharambe’s picture

Status: Needs review » Needs work

Hi @rahulrasgon,

Above test cases, #45 is getting failed.
Can you please check it once again and attached some before and after screenshots.

Needs to be re-rolled for 9.3.x
Can be a move to Needs work

suresh prabhu parkala’s picture

Status: Needs work » Needs review
StatusFileSize
new10.74 KB
new1.67 KB

Updated patch for 9.3.x. Please review.

Status: Needs review » Needs work

The last submitted patch, 47: 2887376-47.patch, failed testing. View results

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.

atul4drupal’s picture

StatusFileSize
new11.35 KB
new1.46 KB

Adding patch for 9.3.x

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.

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.

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.

jhandsta’s picture

Status: Needs work » Needs review
StatusFileSize
new11.22 KB
new7.73 KB

Re-rolled for 10.2.x

needs-review-queue-bot’s picture

Status: Needs review » Needs work

The Needs Review Queue Bot tested this issue.

While you are making the above changes, we recommend that you convert this patch to a merge request. Merge requests are preferred over patches. Be sure to hide the old patch files as well. (Converting an issue to a merge request without other contributions to the issue will not receive credit.)

rahulrasgon changed the visibility of the branch 2887376-link-autocomplete-content to hidden.

rahulrasgon changed the visibility of the branch 2887376-link-autocomplete-content to active.

rahulrasgon’s picture

Status: Needs work » Needs review
rahulrasgon’s picture

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs issue summary update

Have not reviewed but issue summary doesn't follow correct template

glenndw’s picture

StatusFileSize
new12.39 KB

Re-rolled for 10.3.9

dcam’s picture

Status: Needs work » Closed (duplicate)
Issue tags: +stale-issue-cleanup

I'm closing this in favor of #3373258: Allow to select reference method in link field type for internal links. Because it implements the entity reference selection plugin it inherently includes the ability to select bundles. Also, the MR in the other issue has a few advantages. It's a more complete patch. It's consistent with the way that the EntityReferenceItem class works instead of being a unique implementation. And it has tests.

Credit has been granted to everyone who worked on the patch in this issue. Thank you for your contributions!

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.