src/Form/SearchAdsType.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Form;
  3. use Symfony\Component\Form\AbstractType;
  4. use Symfony\Component\Form\FormBuilderInterface;
  5. use Symfony\Component\OptionsResolver\OptionsResolver;
  6. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  7. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  8. use Symfony\Component\Form\Extension\Core\Type\HiddenType;
  9. use Symfony\Component\Form\Extension\Core\Type\TextType;
  10. class SearchAdsType extends AbstractType
  11. {
  12.     public function buildForm(FormBuilderInterface $builder, array $options)
  13.     {
  14.         /*dd($options);*/
  15.         $builder
  16.             ->add('search_field'TextType::class, [
  17.                 'required' => false,
  18.                 'data' => $options['search_field']
  19.             ])
  20.             ->add('adtype'ChoiceType::class, [
  21.                 'choices' => [
  22.                     'Maison' => '0',
  23.                     'Appartement' => '1',
  24.                     'Investissement locatif' => '2',
  25.                 ],
  26.                 'expanded' => true,
  27.                 'multiple' => true,
  28.                 'data' => explode(","$options['adtype']),
  29.             ])
  30.             ->add('nb_rooms'ChoiceType::class, [
  31.                 'choices' => [
  32.                     'Studio' => '0',
  33.                     '2' => '2',
  34.                     '3' => '3',
  35.                     '4 et plus' => '4',
  36.                 ],
  37.                 'expanded' => true,
  38.                 'multiple' => true,
  39.                 'data' => explode(","$options['nb_rooms']),
  40.             ])
  41.             ->add('nb_bedrooms'ChoiceType::class, [
  42.                 'choices' => [
  43.                     'Studio' => '0',
  44.                     '1' => '1',
  45.                     '2' => '2',
  46.                     '3' => '3',
  47.                     '4 et plus' => '4',
  48.                 ],
  49.                 'expanded' => true,
  50.                 'multiple' => true,
  51.                 'data' => explode(","$options['nb_bedrooms']),
  52.             ])
  53.             ->add('min_surface'HiddenType::class)
  54.             ->add('projettype'HiddenType::class, [
  55.                 'data' => $options['projettype']
  56.             ])
  57.             ->add('min_price'HiddenType::class)
  58.             ->add('max_price'HiddenType::class)
  59.             ->add('save'SubmitType::class)
  60.         ;
  61.     }
  62.     public function configureOptions(OptionsResolver $resolver)
  63.     {
  64.         $resolver->setDefaults([
  65.             // Configure your form options here
  66.             'search_field' => null,
  67.             'nb_rooms' => null,
  68.             'type' => null,
  69.             'nb_bedrooms' => null,
  70.             'projettype' => 0,
  71.             'adtype' => null,
  72.         ]);
  73.     }
  74. }