src/Form/Backend/AutocompleteField/FirmField.php line 12

Open in your IDE?
  1. <?php
  2. namespace App\Form\Backend\AutocompleteField;
  3. use App\Entity\Entreprise;
  4. use Symfony\Component\Form\AbstractType;
  5. use Symfony\Component\OptionsResolver\OptionsResolver;
  6. use Symfony\UX\Autocomplete\Form\AsEntityAutocompleteField;
  7. use Symfony\UX\Autocomplete\Form\ParentEntityAutocompleteType;
  8. #[AsEntityAutocompleteField]
  9. class FirmField extends AbstractType
  10. {
  11.     public function configureOptions(OptionsResolver $resolver)
  12.     {
  13.         $resolver->setDefaults([
  14.             'class' => Entreprise::class,
  15.             'searchable_fields' => ['raisonSocial'],
  16.             'choice_label' => function(Entreprise $entreprise) {
  17.                 return $entreprise->getRaisonSocial().' ('.$entreprise->getId().')';
  18.             }
  19.         ]);
  20.     }
  21.     public function getParent(): string
  22.     {
  23.         return ParentEntityAutocompleteType::class;
  24.     }
  25. }