src/Form/SearchFormType.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Form;
  3. use App\Entity\SearchData;
  4. use App\Entity\TypeGroupe;
  5. use Doctrine\ORM\EntityRepository;
  6. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  7. use Symfony\Component\Form\AbstractType;
  8. use Symfony\Component\Form\Extension\Core\Type\DateType;
  9. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  10. use Symfony\Component\Form\Extension\Core\Type\TextType;
  11. use Symfony\Component\Form\FormBuilderInterface;
  12. use Symfony\Component\OptionsResolver\OptionsResolver;
  13. class SearchFormType extends AbstractType
  14. {
  15.     public function buildForm(FormBuilderInterface $builder, array $options): void
  16.     {
  17.         $builder
  18.             ->add('depart'TextType::class, [
  19.                 'required' => false,
  20.                 'label' => 'Départ :',
  21.                 'attr'=> [
  22.                     'placeholder' => 'Cholet'
  23.                 ],
  24.             ])
  25.             ->add('retour'TextType::class, [
  26.                 'required' => false,
  27.                 'label' => 'Destination :',
  28.                 'attr'=> [
  29.                     'placeholder' => 'Nice'
  30.                 ],
  31.             ])
  32.             // ---------------------- DATES ----------------------------//
  33.             ->add('dateD'DateType::class, [
  34.                 'format' => 'dd/MM/yyyy',
  35.                 'html5' => false,
  36.                 'label' => 'Date départ :',
  37.                 'widget' => 'single_text',
  38.                 'attr' => [
  39.                     'class' => 'datetimepicker',
  40.                     'data-provider' => 'flatpickr',
  41.                     'data-date-format' => 'd/m/Y',
  42.                     'placeholder'=>'27/03/2023'
  43.                 ],
  44.             ])
  45.             ->add('dateR'DateType::class, [
  46.                 'format' => 'dd/MM/yyyy',
  47.                 'html5' => false,
  48.                 'label' => 'Date retour :',
  49.                 'widget' => 'single_text',
  50.                 'attr' => [
  51.                     'class' => 'datetimepicker',
  52.                     'data-provider' => 'flatpickr',
  53.                     'data-date-format' => 'd/m/Y',
  54.                     'placeholder'=>'19/05/2023'
  55.                 ],
  56.             ])
  57.             // ---------------------- Type Groupe ----------------------------//
  58.             ->add('typeGroupe'EntityType::class, [
  59.                 'trim' => true,
  60.                 'label' => 'Type de groupe : ',
  61.                 //pour avoir un champ vide si non choisi
  62.                 'required' => false,
  63.                 'class' => TypeGroupe::class,
  64.                 'query_builder' => function (EntityRepository $er) {
  65.                     return $er->createQueryBuilder('typeGroupe')
  66.                         ->orderBy('typeGroupe.intitule''ASC');
  67.                 },
  68.                 'choice_label' => 'intitule',
  69.             ])
  70.             ->add('rechercher'SubmitType::class, [
  71.                 'attr' => [
  72.                     'class' => 'btn btn-lg btn-primary',
  73.                     'type'=> 'submit']
  74.             ]);
  75.     }
  76.     public function configureOptions(OptionsResolver $resolver): void
  77.     {
  78.         $resolver->setDefaults([
  79.             'data_class' => SearchData::class,
  80.         ]);
  81.     }
  82. }