src/Form/SearchFormType.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\SearchType;
  7. use Symfony\Component\Validator\Constraints as Assert;
  8. use Symfony\Contracts\Translation\TranslatorInterface;
  9. Class SearchFormType extends AbstractType
  10. {
  11.     public function __construct(TranslatorInterface $translator)
  12.     {
  13.         $this->translator $translator;
  14.     }
  15.     public function buildForm(FormBuilderInterface $builder, array $options)
  16.     {
  17.         $builder
  18.             ->setAction('/search/')
  19.             ->setMethod('GET')
  20.             ->add('q'SearchType::Class, [
  21.                 'label' => $this->translator->trans('Zoeken'),
  22.                 'constraints' => [
  23.                     new Assert\NotBlank(),
  24.                 ],
  25.                 'attr' => ['class' => 'searchinput']
  26.             ])
  27.         ;
  28.     }
  29.     public function configureOptions(OptionsResolver $resolver)
  30.     {
  31.         $resolver->setDefaults([
  32.         ]);
  33.     }
  34. }