<?php declare(strict_types=1);
namespace App\Form\Type;
use App\Entity\User;
use App\Validator\Constraints\RecaptchaIsTrue;
use EWZ\Bundle\RecaptchaBundle\Form\Type\EWZRecaptchaType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class RegistrationType extends AbstractType
{
/**
* @param mixed[] $options
*/
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder->add('email', EmailType::class, ['label' => 'form.email'])
->add('agreedNewsletter', CheckboxType::class, ['required' => true, 'label' => false])
->add('password', RepeatedType::class, [
'first_name' => 'password',
'second_name' => 'confirm_password',
'type' => EncodedPasswordType::class,
'mapped' => false,
'first_options' => [
'label' => 'form.password',
'event_dispatcher' => $builder->getEventDispatcher(),
'password_validation_groups' => ['Default'],
'mapped' => true,
],
'second_options' => [
'label' => 'form.password_confirm',
'event_dispatcher' => null,
'mapped' => true,
],
])
->add('recaptcha', EWZRecaptchaType::class, [
'mapped' => false,
'attr' => [
'options' => [
'theme' => 'light',
'type' => 'image',
'size' => 'normal',
],
],
'constraints' => [
new RecaptchaIsTrue(['message' => 'recaptcha.error']),
],
])
;
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => User::class,
'translation_domain' => 'registration',
'validation_groups' => ['registration', 'Default'],
]);
}
public function getBlockPrefix(): string
{
return 'registration';
}
}