Skip to content

Commit 22df3f4

Browse files
1edweaverryan
authored andcommitted
Autocomplete docs tweak and fix
1 parent e27d318 commit 22df3f4

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

src/Autocomplete/doc/index.rst

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
336341
Then, update your field configuration to use your new controller (it will be used
337342
in 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
371377
This only works for Doctrine entities: see `Manually using the Stimulus Controller`_
372378
if 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-
434431
Thanks to this, your can now autocomplete your ``Food`` entity via
435432
the ``ux_entity_autocomplete`` route and ``alias`` route wildcard:
436433

src/Autocomplete/tests/Fixtures/Kernel.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ protected function configureContainer(ContainerConfigurator $c): void
123123
],
124124
]);
125125

126+
$c->extension('zenstruck_foundry', [
127+
'auto_refresh_proxies' => false,
128+
]);
129+
126130
$services = $c->services();
127131
$services
128132
->defaults()

src/LiveComponent/tests/Fixtures/Kernel.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public function registerBundles(): iterable
5454
yield new ZenstruckFoundryBundle();
5555
yield new TwigComponentBundle();
5656
yield new LiveComponentBundle();
57+
yield new ZenstruckFoundryBundle();
5758
}
5859

5960
protected function configureContainer(ContainerConfigurator $c): void
@@ -99,6 +100,10 @@ protected function configureContainer(ContainerConfigurator $c): void
99100
],
100101
]);
101102

103+
$c->extension('zenstruck_foundry', [
104+
'auto_refresh_proxies' => false,
105+
]);
106+
102107
$c->services()
103108
->defaults()
104109
->autowire()

0 commit comments

Comments
 (0)