<?php
namespace w3des\AdminBundle\Form\Type;
use Symfony\Component\Form\AbstractType;
use w3des\AdminBundle\Service\Settings;
use w3des\AdminBundle\Validator\IsTrueV3;
use w3des\AdminBundle\Validator\IsTrueValidatorV3;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use ReCaptcha\ReCaptcha;
class RecaptchaV3Ttype extends AbstractType
{
const API = 'https://www.google.com/recaptcha/api.js';
private Settings $settings;
public function __construct(Settings $settings)
{
$this->settings = $settings;
}
/**
* {@inheritDoc}
*/
public function getBlockPrefix()
{
return 'recaptcha';
}
/**
* {@inheritDoc}
*/
public function buildForm(\Symfony\Component\Form\FormBuilderInterface $builder, array $options)
{}
/**
* {@inheritDoc}
*/
public function buildView(\Symfony\Component\Form\FormView $view, \Symfony\Component\Form\FormInterface $form, array $options)
{
$view->vars['action_name'] = $options['action_name'];
$view->vars['public_key'] = $this->settings->get(IsTrueValidatorV3::SETTINGS_PUBLIC);
$view->vars['enabled'] = $this->settings->get(IsTrueValidatorV3::SETTINGS_ENABLED);
$view->vars['vue'] = $_ENV['VUE'] ?? true;
$view->vars['api_uri'] = 'https://www.google.com/recaptcha/api.js';
}
/**
* {@inheritDoc}
*/
public function configureOptions(\Symfony\Component\OptionsResolver\OptionsResolver $resolver)
{
$resolver->setDefault('contstraints', [
new IsTrueV3()
]);
$resolver->setDefault('action_name', 'form');
$resolver->setRequired('action_name');
}
/**
* {@inheritdoc}
*/
public function getParent(): string
{
return HiddenType::class;
}
}