bundle/w3des/AdminBundle/src/Form/Type/RecaptchaV3Ttype.php line 11

Open in your IDE?
  1. <?php
  2. namespace w3des\AdminBundle\Form\Type;
  3. use Symfony\Component\Form\AbstractType;
  4. use w3des\AdminBundle\Service\Settings;
  5. use w3des\AdminBundle\Validator\IsTrueV3;
  6. use w3des\AdminBundle\Validator\IsTrueValidatorV3;
  7. use Symfony\Component\Form\Extension\Core\Type\HiddenType;
  8. use ReCaptcha\ReCaptcha;
  9. class RecaptchaV3Ttype extends AbstractType
  10. {
  11. const API = 'https://www.google.com/recaptcha/api.js';
  12. private Settings $settings;
  13. public function __construct(Settings $settings)
  14. {
  15. $this->settings = $settings;
  16. }
  17. /**
  18. * {@inheritDoc}
  19. */
  20. public function getBlockPrefix()
  21. {
  22. return 'recaptcha';
  23. }
  24. /**
  25. * {@inheritDoc}
  26. */
  27. public function buildForm(\Symfony\Component\Form\FormBuilderInterface $builder, array $options)
  28. {}
  29. /**
  30. * {@inheritDoc}
  31. */
  32. public function buildView(\Symfony\Component\Form\FormView $view, \Symfony\Component\Form\FormInterface $form, array $options)
  33. {
  34. $view->vars['action_name'] = $options['action_name'];
  35. $view->vars['public_key'] = $this->settings->get(IsTrueValidatorV3::SETTINGS_PUBLIC);
  36. $view->vars['enabled'] = $this->settings->get(IsTrueValidatorV3::SETTINGS_ENABLED);
  37. $view->vars['vue'] = $_ENV['VUE'] ?? true;
  38. $view->vars['api_uri'] = 'https://www.google.com/recaptcha/api.js';
  39. }
  40. /**
  41. * {@inheritDoc}
  42. */
  43. public function configureOptions(\Symfony\Component\OptionsResolver\OptionsResolver $resolver)
  44. {
  45. $resolver->setDefault('contstraints', [
  46. new IsTrueV3()
  47. ]);
  48. $resolver->setDefault('action_name', 'form');
  49. $resolver->setRequired('action_name');
  50. }
  51. /**
  52. * {@inheritdoc}
  53. */
  54. public function getParent(): string
  55. {
  56. return HiddenType::class;
  57. }
  58. }