src/Form/ReCaptchaType.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Form;
  3. use App\Form\EventListener\ReCaptchaValidationListener;
  4. use ReCaptcha\ReCaptcha;
  5. use Symfony\Component\Form\AbstractType;
  6. use Symfony\Component\Form\FormBuilderInterface;
  7. use Symfony\Component\Form\FormInterface;
  8. use Symfony\Component\Form\FormView;
  9. use Symfony\Component\OptionsResolver\OptionsResolver;
  10. class ReCaptchaType extends AbstractType
  11. {
  12. /**
  13. * @var ReCaptcha
  14. */
  15. private $reCaptcha;
  16. /**
  17. * ReCaptchaType constructor.
  18. */
  19. public function __construct(ReCaptcha $reCaptcha)
  20. {
  21. $this->reCaptcha = $reCaptcha;
  22. }
  23. /**
  24. * {@inheritDoc}
  25. */
  26. public function buildForm(FormBuilderInterface $builder, array $options)
  27. {
  28. $builder->addEventSubscriber(new ReCaptchaValidationListener($this->reCaptcha));
  29. }
  30. /**
  31. * {@inheritDoc}
  32. */
  33. public function buildView(FormView $view, FormInterface $form, array $options)
  34. {
  35. $view->vars['type'] = $options['type'];
  36. }
  37. public function configureOptions(OptionsResolver $resolver)
  38. {
  39. $resolver
  40. ->setDefault('type', 'invisible')
  41. ->setAllowedValues('type', ['checkbox', 'invisible']);
  42. }
  43. }