src/Form/Type/Frontend/VehicleFreeSearchType.php line 76

Open in your IDE?
  1. <?php
  2. namespace App\Form\Type\Frontend;
  3. use App\Repository\SaleRepository;
  4. use Symfony\Component\Form\AbstractType;
  5. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  6. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  7. use Symfony\Component\Form\Extension\Core\Type\TextType;
  8. use Symfony\Component\Form\FormBuilderInterface;
  9. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  10. use Symfony\Component\OptionsResolver\OptionsResolver;
  11. class VehicleFreeSearchType extends AbstractType
  12. {
  13.     public function __construct(private readonly SaleRepository $saleRepository, private readonly SessionInterface $session)
  14.     {
  15.     }
  16.     public function buildForm(FormBuilderInterface $builder, array $options): void
  17.     {
  18.         $builder
  19.             ->add('freeSearch'TextType::class, [
  20.                 'required' => false,
  21.                 'mapped' => false,
  22.                 'attr' => [
  23.                     'class' => 'input-texte',
  24.                 ],
  25.             ])
  26.             ->add('maxKm'TextType::class, [
  27.                 'required' => false,
  28.                 'mapped' => false,
  29.                 'attr' => [
  30.                     'class' => 'input-texte',
  31.                     'placeholder' => 'frontend.search.form.kilometersSearch.max',
  32.                 ],
  33.             ])
  34.             ->add('maxPrice'TextType::class, [
  35.                 'required' => false,
  36.                 'mapped' => false,
  37.                 'attr' => [
  38.                     'class' => 'input-texte',
  39.                     'placeholder' => 'frontend.form.price-search.label.max',
  40.                 ],
  41.             ])
  42.             ->add('sale'ChoiceType::class, [
  43.                 'required' => false,
  44.                 'choices' => array_flip($this->getActiveSales($options['user'])),
  45.                 'placeholder' => 'frontend.home_top.form.sale.placeholder',
  46.                 'multiple' => false,
  47.                 'expanded' => false,
  48.             ])
  49.             ->add('search'SubmitType::class, [
  50.                 'label' => 'frontend.home_top.form.submit.label',
  51.                 'attr' => [
  52.                 ],
  53.             ])
  54.         ;
  55.     }
  56.     public function configureOptions(OptionsResolver $resolver): void
  57.     {
  58.         $resolver->setDefaults([
  59.             'csrf_protection' => false,
  60.             'user' => null,
  61.         ]);
  62.     }
  63.     public function getBlockPrefix()
  64.     {
  65.         return 'vp_auto_vehicle_free_search';
  66.     }
  67.     protected function getActiveSales($user)
  68.     {
  69.         return $this->saleRepository->getUserActiveChoices($user$this->session->get('dimension''private'));
  70.     }
  71. }