<?php
namespace App\Form\Backend\AutocompleteField;
use App\Entity\Entreprise;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\UX\Autocomplete\Form\AsEntityAutocompleteField;
use Symfony\UX\Autocomplete\Form\ParentEntityAutocompleteType;
#[AsEntityAutocompleteField]
class FirmField extends AbstractType
{
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'class' => Entreprise::class,
'searchable_fields' => ['raisonSocial'],
'choice_label' => function(Entreprise $entreprise) {
return $entreprise->getRaisonSocial().' ('.$entreprise->getId().')';
}
]);
}
public function getParent(): string
{
return ParentEntityAutocompleteType::class;
}
}