- 🇫🇷France louis-cuny
#55 works for me if I disable reference validation :
$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 pack to needs work because of the broken reference validation
- 🇧🇪Belgium brentg Ghent
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 pagesHowever, 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. - First commit to issue fork.
- 🇨ðŸ‡Switzerland tcrawford
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'.
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.
- 🇨ðŸ‡Switzerland tcrawford
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);
- 🇫🇷France alxgl
Hello and thanks for the work on this issue !
The latest patch #67 📌 Allow multiple target entity types in the 'entity_autocomplete' Form API element Needs work 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.
- First commit to issue fork.
- 🇮🇹Italy robertom
@alxgl I attach the patch that also shows the entity label when you return to edit the form
- 🇨🇦Canada phjou Vancouver 🇨🇦 🇪🇺
The patch doesn't seem to handle media. Only taxonomy terms and nodes.
- 🇫🇷France alxgl
@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.