vendor/excelwebzone/recaptcha-bundle/src/Form/Type/EWZRecaptchaV3Type.php line 10

Open in your IDE?
  1. <?php
  2. namespace EWZ\Bundle\RecaptchaBundle\Form\Type;
  3. use Symfony\Component\Form\Extension\Core\Type\HiddenType;
  4. use Symfony\Component\Form\FormInterface;
  5. use Symfony\Component\Form\FormView;
  6. use Symfony\Component\OptionsResolver\OptionsResolver;
  7. class EWZRecaptchaV3Type extends AbstractEWZRecaptchaType
  8. {
  9. public const DEFAULT_ACTION_NAME = 'form';
  10. /** @var bool */
  11. private $hideBadge;
  12. /**
  13. * EWZRecaptchaV3Type constructor.
  14. *
  15. * @param string $publicKey
  16. * @param bool $enabled
  17. * @param bool $hideBadge
  18. * @param string $apiHost
  19. */
  20. public function __construct(string $publicKey, bool $enabled, bool $hideBadge, string $apiHost = 'www.google.com')
  21. {
  22. parent::__construct($publicKey, $enabled, $apiHost);
  23. $this->hideBadge = $hideBadge;
  24. }
  25. /**
  26. * {@inheritdoc}
  27. */
  28. public function configureOptions(OptionsResolver $resolver): void
  29. {
  30. $resolver->setDefaults([
  31. 'label' => false,
  32. 'mapped' => false,
  33. 'validation_groups' => ['Default'],
  34. 'script_nonce_csp' => '',
  35. 'action_name' => 'form',
  36. ]);
  37. $resolver->setAllowedTypes('script_nonce_csp', 'string');
  38. $resolver->setAllowedTypes('action_name', 'string');
  39. }
  40. /**
  41. * {@inheritdoc}
  42. */
  43. public function getParent(): string
  44. {
  45. return HiddenType::class;
  46. }
  47. /**
  48. * {@inheritdoc}
  49. */
  50. protected function addCustomVars(FormView $view, FormInterface $form, array $options): void
  51. {
  52. $view->vars = array_replace($view->vars, [
  53. 'ewz_recaptcha_hide_badge' => $this->hideBadge,
  54. 'script_nonce_csp' => $options['script_nonce_csp'] ?? '',
  55. 'action_name' => $options['action_name'] ?? '',
  56. ]);
  57. }
  58. }