<?php
namespace App\Form;
use App\Entity\SearchData;
use App\Entity\TypeGroupe;
use Doctrine\ORM\EntityRepository;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class SearchFormType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('depart', TextType::class, [
'required' => false,
'label' => 'Départ :',
'attr'=> [
'placeholder' => 'Cholet'
],
])
->add('retour', TextType::class, [
'required' => false,
'label' => 'Destination :',
'attr'=> [
'placeholder' => 'Nice'
],
])
// ---------------------- DATES ----------------------------//
->add('dateD', DateType::class, [
'format' => 'dd/MM/yyyy',
'html5' => false,
'label' => 'Date départ :',
'widget' => 'single_text',
'attr' => [
'class' => 'datetimepicker',
'data-provider' => 'flatpickr',
'data-date-format' => 'd/m/Y',
'placeholder'=>'27/03/2023'
],
])
->add('dateR', DateType::class, [
'format' => 'dd/MM/yyyy',
'html5' => false,
'label' => 'Date retour :',
'widget' => 'single_text',
'attr' => [
'class' => 'datetimepicker',
'data-provider' => 'flatpickr',
'data-date-format' => 'd/m/Y',
'placeholder'=>'19/05/2023'
],
])
// ---------------------- Type Groupe ----------------------------//
->add('typeGroupe', EntityType::class, [
'trim' => true,
'label' => 'Type de groupe : ',
//pour avoir un champ vide si non choisi
'required' => false,
'class' => TypeGroupe::class,
'query_builder' => function (EntityRepository $er) {
return $er->createQueryBuilder('typeGroupe')
->orderBy('typeGroupe.intitule', 'ASC');
},
'choice_label' => 'intitule',
])
->add('rechercher', SubmitType::class, [
'attr' => [
'class' => 'btn btn-lg btn-primary',
'type'=> 'submit']
]);
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => SearchData::class,
]);
}
}