@@ -333,6 +333,11 @@ events that the core Stimulus controller dispatches:
333333 }
334334 }
335335
336+ .. note ::
337+
338+ The extending controller should be loaded eagerly (remove ``/* stimulusFetch: 'lazy' */ ``), so
339+ it can listen to events dispatched by the original controller.
340+
336341Then, update your field configuration to use your new controller (it will be used
337342in addition to the core Autocomplete controller):
338343
@@ -341,6 +346,7 @@ in addition to the core Autocomplete controller):
341346 $builder
342347 ->add('food', EntityType::class, [
343348 'class' => Food::class,
349+ 'autocomplete' => true,
344350 + 'attr' => [
345351 + 'data-controller' => 'custom-autocomplete',
346352 + ],
@@ -371,16 +377,19 @@ endpoint and then :ref:`initialize the Stimulus controller manually <manual-stim
371377This only works for Doctrine entities: see `Manually using the Stimulus Controller `_
372378if you're autocompleting something other than an entity.
373379
374- To expose the endpoint, create a class that implements ``Symfony\UX\Autocomplete\EntityAutocompleterInterface ``::
380+ To expose the endpoint, create a class that implements ``Symfony\UX\Autocomplete\EntityAutocompleterInterface ``
381+ and tag this service with ``ux.entity_autocompleter `` and include an ``alias ``::
375382
376383 namespace App\Autocompleter;
377384
378385 use App\Entity\Food;
379386 use Doctrine\ORM\EntityRepository;
380387 use Doctrine\ORM\QueryBuilder;
388+ use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag;
381389 use Symfony\Component\Security\Core\Security;
382390 use Symfony\UX\Autocomplete\EntityAutocompleterInterface;
383391
392+ #[AutoconfigureTag('ux.entity_autocompleter', ['alias' => 'food'])]
384393 class FoodAutocompleter implements EntityAutocompleterInterface
385394 {
386395 public function getEntityClass(): string
@@ -419,18 +428,6 @@ To expose the endpoint, create a class that implements ``Symfony\UX\Autocomplete
419428 }
420429 }
421430
422- Next, tag this service with ``ux.entity_autocompleter `` and include an ``alias ``:
423-
424- .. code-block :: yaml
425-
426- # config/services.yaml
427- services :
428- # ...
429-
430- App\Autocompleter\FoodAutocompleter :
431- tags :
432- - { name: ux.entity_autocompleter, alias: 'food' }
433-
434431Thanks to this, your can now autocomplete your ``Food `` entity via
435432the ``ux_entity_autocomplete `` route and ``alias `` route wildcard:
436433
0 commit comments