src/Form/Types/ReCaptchaType.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Form\Types;
  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 $reCaptcha;
  16. /**
  17. * ReCaptchaType constructor.
  18. *
  19. * @param ReCaptcha $reCaptcha
  20. */
  21. public function __construct(ReCaptcha $reCaptcha)
  22. {
  23. $this->reCaptcha = $reCaptcha;
  24. }
  25. /**
  26. * @inheritDoc
  27. */
  28. public function buildForm(FormBuilderInterface $builder, array $options)
  29. {
  30. $builder->addEventSubscriber(new ReCaptchaValidationListener($this->reCaptcha));
  31. }
  32. /**
  33. * @inheritDoc
  34. */
  35. public function buildView(FormView $view, FormInterface $form, array $options)
  36. {
  37. $view->vars['type'] = $options['type'];
  38. } /**
  39. * @inheritDoc
  40. */
  41. public function configureOptions(OptionsResolver $resolver)
  42. {
  43. $resolver
  44. ->setDefault('type', 'invisible')
  45. ->setAllowedValues('type', ['checkbox', 'invisible']);
  46. }
  47. }