<?php
namespace App\Form;
use App\Form\EventListener\ReCaptchaValidationListener;
use ReCaptcha\ReCaptcha;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\OptionsResolver\OptionsResolver;
class ReCaptchaType extends AbstractType
{
/**
* @var ReCaptcha
*/
private $reCaptcha;
/**
* ReCaptchaType constructor.
*/
public function __construct(ReCaptcha $reCaptcha)
{
$this->reCaptcha = $reCaptcha;
}
/**
* {@inheritDoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->addEventSubscriber(new ReCaptchaValidationListener($this->reCaptcha));
}
/**
* {@inheritDoc}
*/
public function buildView(FormView $view, FormInterface $form, array $options)
{
$view->vars['type'] = $options['type'];
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver
->setDefault('type', 'invisible')
->setAllowedValues('type', ['checkbox', 'invisible']);
}
}