Problem/Motivation

#1959806: Provide a generic 'entity_autocomplete' Form API element introduced a generic 'entity_autocomplete' Form API element. But it hardcodes a single entity type. While linking, users should (optionally) be able to select which entity type they want to link to.

Proposed resolution

Introduce the equivalent of DER (Dynamic Entity Reference), sans the storage/formatter/widget, only the Form API element.

Remaining tasks

TBD

User interface changes

TBD

API changes

TBD

Issue fork drupal-2423093

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

dawehner’s picture

As first step we could just make the configuration on the widget settings level.

dave reid’s picture

I would also like to select a bundle as well, so I could filter down to only Article nodes, instead of all nodes. Often I've encountered projects that have nodes with the same titles, so this would help with those instances.

webchick’s picture

Agreed that filtering by bundle types is actually probably more important for a lot of use cases than different entity types.

jibran’s picture

jibran’s picture

How about adding a new DER form element to the core which will use ER form element and it'll show a select list with entity type ids? I am doing something similar in above issue with DER widget. We can use dynamic_entity_autocomplete form element instead of entity_autocomplete in link widget.
For #2 we can implement hierarchical select type widget for DER form element in a follow up issue to select bundles.

jibran’s picture

There is a @todo in EntityReferenceAutocompleteWidget::getAutocreateBundle()

        // @todo Expose a proper UI for choosing the bundle for autocreated
        // entities in https://www.drupal.org/node/2412569.

which is kind of similar to #2 but it is only for taxonomies #2412569: Allow setting the auto-create bundle on entity reference fields with multiple target bundles.

amateescu’s picture

Title: Allow an entity type to be selected in the generic 'entity_autocomplete' Form API element » Allow multiple target entity types in the 'entity_autocomplete' Form API element

Opened #2427803: [PP-1] Expose target type, selection handler and selection settings in LinkWidget for #1. I think that was the original intention for this issue but we need two of them anyway, so this can stay open and focused on the 'entity_autocomplete' form element.

wim leers’s picture

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

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.

jibran’s picture

amateescu’s picture

Why not in this issue and by adding support to the current form element?

Edit: oh, I see, that issue is in the DER project, not in core :)

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.

spheresh’s picture

StatusFileSize
new1.36 KB

This still does not work as intended:

Steps to reproduce:
1. Create/update link with a "entity:group/{group_id}" value.
2. If you go after this on the edit form again. You can see that the value of the input field is now "Title of your group (277)"
3. After that I re-save the link. And I go to the editing form again.
4. The value of the field is again changed to "entity:node/{group_id}"

Since the entity type was changed from group to node The link for the end user was broken

This small patch will fix this problem while we are waiting for the solution to the issue with the whole

berdir’s picture

@spheresh: There's an RTBC (as of today) issue that fixes that problem: #2804391: Resaving menu links that points to a non-node entity changes the type to node and breaks the link

sam152’s picture

I would have expected adding features to entity_autocomplete would be one issue and updating the menu system to use those features to be another. While they are one issue, here is an approach to making the menu UI reference multiple entity types. It's blocked behind proper multi-entity autocomplete support, but in the meantime I'm shimming that support in with a sandbox: https://www.drupal.org/sandbox/sam/2881047.

Applying this patch and installing the sandbox gives you this feature, albeit not in a form that is ready for core.

sam152’s picture

Needed the same patch for 8.3.x.

amateescu’s picture

@Sam152,

I would have expected adding features to entity_autocomplete would be one issue and updating the menu system to use those features to be another.

I don't know why @spheresh posted that patch here, but we do actually have separate issues. This one is for enhancing the core 'entity_autocomplete' element with multiple target type support and then there is #2427803: [PP-1] Expose target type, selection handler and selection settings in LinkWidget for improving the link field (used by the menu system).

sam152’s picture

Exactly what I was looking for! Thanks @amateescu.

sam152’s picture

Rerolled for latest 8.3.x.

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.

aaronbauman’s picture

This patch now proposes adding dynamic_entity_reference to core.
Am i reading this right?

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

Rerolling the patch from 20 against latest 3.x.

ryan.ryan’s picture

The same patch with cleaned up whitespace issues.

idflood’s picture

Reroll of patch in #25 against 8.6.x.

Note that it may be useful for this issue https://www.drupal.org/project/linkit/issues/2712951 (use link field to reference files or other entities)

borisson_’s picture

Status: Active » Needs review

Setting to needs review to have the testbot take a look at the patches.

The last submitted patch, 24: 2423093-convert-menu-system-to-DEA-32.patch, failed testing. View results

The last submitted patch, 25: 2423093-convert-menu-system-to-DEA-33.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 26: 2423093-convert-menu-system-to-DEA-26.patch, failed testing. View results

yogeshmpawar’s picture

Assigned: Unassigned » yogeshmpawar
yogeshmpawar’s picture

Assigned: yogeshmpawar » Unassigned
Status: Needs work » Needs review
StatusFileSize
new4.25 KB

Re-rolled the #26 patch against 8.6x branch.

Status: Needs review » Needs work

The last submitted patch, 33: 2423093-33.patch, failed testing. View results

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.

k_a_l’s picture

While I'm interested in seeing this feature in core, I decided to just extend the core link field in order to add a bundle filter for node entities for the time being. If anyone is interested, you can check out the project here: https://www.drupal.org/project/filterable_link

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.

lpeabody’s picture

Re-roll of 16 for latest 8.6.x.

lpeabody’s picture

StatusFileSize
new4.18 KB

Re-roll without the erroneous Drupal.php version constant change.

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.

nadavoid’s picture

Issue tags: -JavaScript +JavaScript

Until this core issue is resolved, there is an alternative method available, using the linkit module. The patch from #2712951-191: Linkit for Link field enables using linkit on link fields, and linkit can be used to autocomplete any combination of entity types. I'm using it to list node and media entities in a single list.

techlead’s picture

@nadavoid

there is an alternative method available, using the linkit module. The patch from #2712951-191: Linkit for Link field field enables using linkit on link fields, and linkit can be used to autocomplete any combination of entity types.

Thanks for bringing this to our attention. This works for me.

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.

norman.lol’s picture

Linkit's #2712951: Linkit for Link field is truly a helper. By using it I found out that there's a least a pattern to be entered in the link field that works for spitting out the correct link to other entities in the end. Like querying a certain webform is entity:webform/my_form_id. Querying a certain terms is entity:taxonomy_term/TID (although this one doesn't link to the alias).

ravi.shankar’s picture

StatusFileSize
new4.22 KB

Added reroll of patch #39 on Drupal 9.4.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.

kdborg@gmail.com’s picture

Patch #48 isn't working on Drupal 9.4.7. The URL of the Link field disappears.

The error in the logs:

Error: Class "Drupal\dynamic_entity_autocomplete\Element\DynamicEntityAutocomplete" not found in Drupal\link\Plugin\Field\FieldWidget\LinkWidget::getUserEnteredStringAsUri() (line 111 of /var/www/docroot/core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php)
#0 /var/www/docroot/core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php(144): Drupal\link\Plugin\Field\FieldWidget\LinkWidget::getUserEnteredStringAsUri(NULL)
#1 [internal function]: Drupal\link\Plugin\Field\FieldWidget\LinkWidget::validateUriElement(Array, Object(Drupal\Core\Form\FormState), Array)
#2 /var/www/docroot/core/lib/Drupal/Core/Form/FormValidator.php(282): call_user_func_array(Array, Array)
#3 /var/www/docroot/core/lib/Drupal/Core/Form/FormValidator.php(238): Drupal\Core\Form\FormValidator->doValidateForm(Array, Object(Drupal\Core\Form\FormState))
#4 /var/www/docroot/core/lib/Drupal/Core/Form/FormValidator.php(238): Drupal\Core\Form\FormValidator->doValidateForm(Array, Object(Drupal\Core\Form\FormState))
#5 /var/www/docroot/core/lib/Drupal/Core/Form/FormValidator.php(238): Drupal\Core\Form\FormValidator->doValidateForm(Array, Object(Drupal\Core\Form\FormState))
#6 /var/www/docroot/core/lib/Drupal/Core/Form/FormValidator.php(238): Drupal\Core\Form\FormValidator->doValidateForm(Array, Object(Drupal\Core\Form\FormState))
#7 /var/www/docroot/core/lib/Drupal/Core/Form/FormValidator.php(238): Drupal\Core\Form\FormValidator->doValidateForm(Array, Object(Drupal\Core\Form\FormState))
#8 /var/www/docroot/core/lib/Drupal/Core/Form/FormValidator.php(238): Drupal\Core\Form\FormValidator->doValidateForm(Array, Object(Drupal\Core\Form\FormState))
#9 /var/www/docroot/core/lib/Drupal/Core/Form/FormValidator.php(238): Drupal\Core\Form\FormValidator->doValidateForm(Array, Object(Drupal\Core\Form\FormState))
#10 /var/www/docroot/core/lib/Drupal/Core/Form/FormValidator.php(238): Drupal\Core\Form\FormValidator->doValidateForm(Array, Object(Drupal\Core\Form\FormState))
#11 /var/www/docroot/core/lib/Drupal/Core/Form/FormValidator.php(238): Drupal\Core\Form\FormValidator->doValidateForm(Array, Object(Drupal\Core\Form\FormState))
#12 /var/www/docroot/core/lib/Drupal/Core/Form/FormValidator.php(238): Drupal\Core\Form\FormValidator->doValidateForm(Array, Object(Drupal\Core\Form\FormState))
#13 /var/www/docroot/core/lib/Drupal/Core/Form/FormValidator.php(238): Drupal\Core\Form\FormValidator->doValidateForm(Array, Object(Drupal\Core\Form\FormState))
#14 /var/www/docroot/core/lib/Drupal/Core/Form/FormValidator.php(238): Drupal\Core\Form\FormValidator->doValidateForm(Array, Object(Drupal\Core\Form\FormState))
#15 /var/www/docroot/core/lib/Drupal/Core/Form/FormValidator.php(118): Drupal\Core\Form\FormValidator->doValidateForm(Array, Object(Drupal\Core\Form\FormState), 'node_basic_page...')
#16 /var/www/docroot/core/lib/Drupal/Core/Form/FormBuilder.php(588): Drupal\Core\Form\FormValidator->validateForm('node_basic_page...', Array, Object(Drupal\Core\Form\FormState))
#17 /var/www/docroot/core/lib/Drupal/Core/Form/FormBuilder.php(320): Drupal\Core\Form\FormBuilder->processForm('node_basic_page...', Array, Object(Drupal\Core\Form\FormState))
#18 /var/www/docroot/core/lib/Drupal/Core/Controller/FormController.php(73): Drupal\Core\Form\FormBuilder->buildForm(Object(Drupal\node\NodeForm), Object(Drupal\Core\Form\FormState))
#19 /var/www/docroot/core/modules/layout_builder/src/Controller/LayoutBuilderHtmlEntityFormController.php(39): Drupal\Core\Controller\FormController->getContentResult(Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Routing\RouteMatch))
#20 [internal function]: Drupal\layout_builder\Controller\LayoutBuilderHtmlEntityFormController->getContentResult(Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Routing\RouteMatch))
#21 /var/www/docroot/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array)
#22 /var/www/docroot/core/lib/Drupal/Core/Render/Renderer.php(564): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#23 /var/www/docroot/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))
#24 /var/www/docroot/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array)
#25 /var/www/vendor/symfony/http-kernel/HttpKernel.php(159): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#26 /var/www/vendor/symfony/http-kernel/HttpKernel.php(81): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)
#27 /var/www/docroot/core/lib/Drupal/Core/StackMiddleware/Session.php(58): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#28 /var/www/docroot/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#29 /var/www/docroot/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#30 /var/www/docroot/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#31 /var/www/docroot/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#32 /var/www/docroot/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#33 /var/www/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#34 /var/www/docroot/core/lib/Drupal/Core/DrupalKernel.php(709): Stack\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#35 /var/www/docroot/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))
#36 {main}
.
dpi’s picture

The patch doesnt work as-is. See #16

rastepanyan’s picture

StatusFileSize
new4.35 KB
new4.35 KB

I have used a code from custom patch made by Valery Lourie (valthebald) and re-roll it to make it compatible with Drupal 9.3.x core. It seems that it fixed the issue reported in #51 - the missing CTA-link-uri field.

_utsavsharma’s picture

Status: Needs work » Needs review
_utsavsharma’s picture

StatusFileSize
new2.33 KB
new4.61 KB

Fixed CCF for #53.

louis-cuny’s picture

Status: Needs review » Needs work

#55 doesn't work for me, if I disable reference validation neither :

    $form['contact'] = [
      '#type' => 'entity_autocomplete',
      '#tags' => TRUE,
      '#target_type' => 'node,user',
      '#validate_reference' => FALSE,
      ....
];

Patches that are suggesting using dynamic_entity_reference does not feel right

I put it back to needs work because of the broken reference validation

EDIT
I could avoid the broken validation by using my own :

      '#element_validate' => [
        [$this, 'contactValidate'],
      ],
    ];

    return $form;
  }

  public static function contactValidate(array &$element, FormStateInterface $form_state, array &$complete_form) {
    if (is_array($element['#value'])) {
      $value = $element['#value'];
    }
    else {
      $input_values = $element['#tags'] ? Tags::explode($element['#value']) : [$element['#value']];
      $value = [];
      foreach ($input_values as $input) {
        $match = EntityAutocomplete::extractEntityIdFromAutocompleteInput($input);

        if ($match !== NULL) {
          $value[] = [
            'target_id' => $match,
          ];
        }
      }
    }
    $form_state->setValueForElement($element, $value);
  }

But it's mismatching entity types
My field (custom entity Base field), doesn't store the entity type. I guess this issue cannot be fixed so easily

brentg’s picture

StatusFileSize
new4.62 KB
new792 bytes

I encountered some issues with #55 where when saving a taxonomy term link, it was giving an unexpected error, because $node was null, so added a small extra patch that fixes this issue.

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.

brentg’s picture

StatusFileSize
new1.22 KB
new4.81 KB

Had some issues when using a link field inside layout builder on a translated page.
Issue was that the langcode was not passed along, so added a fallback for the langcode on layout builder pages

However, I have the feeling this patch is atm not the way to go as the str_pos is way too risky.
It's probably better to extend on one of the existing modules (e.g. linkit or link_field_autocomplete_filter) so that they support linking towards multiple entity types at the same time.

siegrist’s picture

StatusFileSize
new4.8 KB

Re-role for 10.2.3

sakthi_dev made their first commit to this issue’s fork.

sakthi_dev’s picture

Created an MR against 11.x.

anybody’s picture

Issue tags: +Needs tests

Looks like the suggestion from #47 by @leymannx have not been incorporated into the MR yet?

Furthermore, this will need tests.

tcrawford’s picture

StatusFileSize
new639.04 KB

I am seeing a type error in SelectionPluginManager as getSelectionGroups does not return an entry for the concatenated entity entity type ID of 'node,taxonomy_term'.

TypeError

The website encountered an unexpected error. Try again later.

TypeError: uasort(): Argument #1 ($array) must be of type array, null given in uasort() (line 65 of core/lib/Drupal/Core/Entity/EntityReferenceSelection/SelectionPluginManager.php).

Drupal\Core\Entity\EntityReferenceSelection\SelectionPluginManager->getPluginId('node,taxonomy_term', 'default') (Line: 41)
Drupal\Core\Entity\EntityReferenceSelection\SelectionPluginManager->getInstance(Array) (Line: 41)
Drupal\Core\Entity\EntityAutocompleteMatcher->getMatches('node,taxonomy_term', 'default', Array, 're') (Line: 118)
Drupal\system\Controller\EntityAutocompleteController->handleAutocomplete(Object, 'node,taxonomy_term', 'default', '3kwQYPisvvlkGtu1zMaBQotUMioVXxI_qWM7KjOEK2w') (Line: 25)
Drupal\realname\Controller\RealnameAutocompleteController->handleAutocomplete(Object, 'node,taxonomy_term', 'default', '3kwQYPisvvlkGtu1zMaBQotUMioVXxI_qWM7KjOEK2w')
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 627)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 181)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 28)
Drupal\Core\StackMiddleware\ContentLength->handle(Object, 1, 1) (Line: 32)
Drupal\big_pipe\StackMiddleware\ContentLength->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 53)
Asm89\Stack\Cors->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 36)
Drupal\Core\StackMiddleware\AjaxPageState->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 704)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

This is on Drupal 10.2.5 (PHP 8.1) with patch #60 applied. This error occurs when editing the link on a menu item.

tcrawford’s picture

The above issue with the TypeError is coming as the second diff in patch #60 did not apply properly on one of our projects (and weirdly failed silently both locally and in the pipeline). Applying the second diff manually works. There appears to be an issue with patch #60 in that case and it would be good if someone else can verify. I have never seen a patch partially apply and fail silently and therefore suspect there is an issue on our side.

diff --git a/core/modules/system/src/Controller/EntityAutocompleteController.php b/core/modules/system/src/Controller/EntityAutocompleteController.php
index a49da37340..fd597a3947 100644
--- a/core/modules/system/src/Controller/EntityAutocompleteController.php
+++ b/core/modules/system/src/Controller/EntityAutocompleteController.php
@@ -77,6 +77,7 @@ public static function create(ContainerInterface $container) {
    */
   public function handleAutocomplete(Request $request, $target_type, $selection_handler, $selection_settings_key) {
     $matches = [];
+    $target_types = explode(',', $target_type);

     // Get the typed string from the URL, if it exists.
     if ($input = $request->query->get('q')) {
       $tag_list = Tags::explode($input);
@@ -109,8 +110,12 @@ public function handleAutocomplete(Request $request, $target_type, $selection_ha
           }
         }
       }
-
-      $matches = $this->matcher->getMatches($target_type, $selection_handler, $selection_settings, $typed_string);
+      foreach ($target_types as $t_type) {
+        $target_matches = $this->matcher->getMatches($t_type, $selection_handler, $selection_settings, $typed_string);
+        if ($target_matches) {
+          $matches = array_merge($matches, $target_matches);
+        }
+      }
     }

     return new JsonResponse($matches);
tcrawford’s picture

I have rerolled #60 as #66 (against 10.2.x) and this applies for me properly. I hope that helps if someone else was having an issue with #60. I am sorry that I have not yet been able to otherwise move this issue forward.

alxgl’s picture

Hello and thanks for the work on this issue !

The latest patch #67 works well for me on a Drupal 10.4.6. The autocomplete is working for taxonomy terms and displays the proper label for the user once selected.

However, if I come back to the edition form, the field displays the raw storage value entity:taxonomy_term/tid instead of the clean entity label.

It's still functional and editable, but not very user friendly.

If someone have an idea to fix it, it will be a good improvement.

robertom made their first commit to this issue’s fork.

robertom’s picture

StatusFileSize
new5.33 KB
new5.34 KB

@alxgl I attach the patch that also shows the entity label when you return to edit the form

phjou’s picture

The patch doesn't seem to handle media. Only taxonomy terms and nodes.

alxgl’s picture

@robertom Thanks a lot for improving this patch.

It's now working perfectly for my needs and my request, which was taxonomy only. I didn't try another bundle indeed.

aherczeg’s picture

Hello, the patch from #70 works for our use case with taxonomy terms on Drupal 10.4.7

omar_emailat’s picture

StatusFileSize
new6.23 KB

I've rerolled the patch to work with Drupal 11.3.2.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

s3b0un3t’s picture

@omar_emailat I tested your patch, Composer applies it, but when you look at the changes, not all of them are applied to Drupal 11.3.2.

I'm proposing a new patch that works for me on Drupal 11.3.2 and also enables media autocompletion.