namespace App\Form; use App\Entity\Category; use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\ChoiceList\View\ChoiceView; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormInterface; use Symfony\Component\Form\FormView; use Symfony\Component\OptionsResolver\OptionsResolver; class MonFormulaireType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add('categorie', EntityType::class, [ 'label' => 'Catégorie', 'class' => Category::class, 'choice_label' => 'display_string' ) // ... ; } public function finishView(FormView $view, FormInterface $form, array $options) { // Trier les options du champ 'categorie' selon leur 'label' usort( $view->children['categorie']->vars['choices'], function(ChoiceView $a, ChoiceView $b) { return strcasecmp( $a->label, $b->label ); } ); } public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults([ 'data_class' => Category::class, ]); } }