@@ -333,6 +333,11 @@ events that the core Stimulus controller dispatches:
333
333
}
334
334
}
335
335
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
+
336
341
Then, update your field configuration to use your new controller (it will be used
337
342
in addition to the core Autocomplete controller):
338
343
@@ -341,6 +346,7 @@ in addition to the core Autocomplete controller):
341
346
$builder
342
347
->add('food', EntityType::class, [
343
348
'class' => Food::class,
349
+ 'autocomplete' => true,
344
350
+ 'attr' => [
345
351
+ 'data-controller' => 'custom-autocomplete',
346
352
+ ],
@@ -371,16 +377,19 @@ endpoint and then :ref:`initialize the Stimulus controller manually <manual-stim
371
377
This only works for Doctrine entities: see `Manually using the Stimulus Controller `_
372
378
if you're autocompleting something other than an entity.
373
379
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 ``::
375
382
376
383
namespace App\Autocompleter;
377
384
378
385
use App\Entity\Food;
379
386
use Doctrine\ORM\EntityRepository;
380
387
use Doctrine\ORM\QueryBuilder;
388
+ use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag;
381
389
use Symfony\Component\Security\Core\Security;
382
390
use Symfony\UX\Autocomplete\EntityAutocompleterInterface;
383
391
392
+ #[AutoconfigureTag('ux.entity_autocompleter', ['alias' => 'food'])]
384
393
class FoodAutocompleter implements EntityAutocompleterInterface
385
394
{
386
395
public function getEntityClass(): string
@@ -419,18 +428,6 @@ To expose the endpoint, create a class that implements ``Symfony\UX\Autocomplete
419
428
}
420
429
}
421
430
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
-
434
431
Thanks to this, your can now autocomplete your ``Food `` entity via
435
432
the ``ux_entity_autocomplete `` route and ``alias `` route wildcard:
436
433
0 commit comments