You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
But this autocompleter is not used by EntityAutocompleteController and AutocompleterRegistry which always return Symfony\UX\Autocomplete\Form\WrappedEntityTypeAutocompleter.
symfony/ux-autocomplete: v2.23.0
DogAutocompleteType:
namespace App\Form\Autocomplete;
use App\Entity\Dog;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\UX\Autocomplete\Form\AsEntityAutocompleteField;
use Symfony\UX\Autocomplete\Form\BaseEntityAutocompleteType;
#[AsEntityAutocompleteField]
class DogAutocompleteType extends AbstractType
{
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'class' => Dog::class,
'choice_label' => fn (Dog $dog) => $dog->getId().' - '.$dog->getName(),
'searchable_fields' => ['id', 'name'],
]);
}
public function getParent(): string
{
return BaseEntityAutocompleteType::class;
}
}
DogAutocompleter:
namespace App\Autocompleter;
use App\Entity\Dog;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
use Symfony\Bundle\SecurityBundle\Security;
use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag;
use Symfony\UX\Autocomplete\OptionsAwareEntityAutocompleterInterface;
#[AutoconfigureTag('ux.entity_autocompleter', ['alias' => 'dog_autocomplete_type', 'priority' => 100])]
class DogAutocompleter implements OptionsAwareEntityAutocompleterInterface
{
public function __construct(
private readonly EntityManagerInterface $entityManager,
) {
}
/**
* @var array<string, mixed>
*/
private array $options = [];
public function createFilteredQueryBuilder(EntityRepository $repository, string $query): \Doctrine\ORM\QueryBuilder
{
...
return $qb;
}
public function getEntityClass(): string
{
return Dog::class;
}
public function getLabel(object $entity): string
{
return $entity->getId().' - '.$entity->getName();
}
public function getValue(object $entity): mixed
{
return $entity;
}
public function isGranted(Security $security): bool
{
return true;
}
public function setOptions(array $options): void
{
$this->options = $options;
}
}
As you can see my autocompleter should be in priority :
The text was updated successfully, but these errors were encountered:
I have created a custom autocompleter following this : https://symfony.com/bundles/ux-autocomplete/current/index.html#advanced-creating-an-autocompleter-with-no-form.
But this autocompleter is not used by
EntityAutocompleteController
andAutocompleterRegistry
which always returnSymfony\UX\Autocomplete\Form\WrappedEntityTypeAutocompleter
.symfony/ux-autocomplete: v2.23.0
DogAutocompleteType:
DogAutocompleter:
As you can see my autocompleter should be in priority :

The text was updated successfully, but these errors were encountered: