src/App/Form/Type/RegistrationType.php line 15

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace App\Form\Type;
  3. use App\Entity\User;
  4. use App\Validator\Constraints\RecaptchaIsTrue;
  5. use EWZ\Bundle\RecaptchaBundle\Form\Type\EWZRecaptchaType;
  6. use Symfony\Component\Form\AbstractType;
  7. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  8. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  9. use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
  10. use Symfony\Component\Form\FormBuilderInterface;
  11. use Symfony\Component\OptionsResolver\OptionsResolver;
  12. class RegistrationType extends AbstractType
  13. {
  14.     /**
  15.      * @param mixed[] $options
  16.      */
  17.     public function buildForm(FormBuilderInterface $builder, array $options): void
  18.     {
  19.         $builder->add('email'EmailType::class, ['label' => 'form.email'])
  20.             ->add('agreedNewsletter'CheckboxType::class, ['required' => true'label' => false])
  21.             ->add('password'RepeatedType::class, [
  22.                 'first_name' => 'password',
  23.                 'second_name' => 'confirm_password',
  24.                 'type' => EncodedPasswordType::class,
  25.                 'mapped' => false,
  26.                 'first_options' => [
  27.                     'label' => 'form.password',
  28.                     'event_dispatcher' => $builder->getEventDispatcher(),
  29.                     'password_validation_groups' => ['Default'],
  30.                     'mapped' => true,
  31.                 ],
  32.                 'second_options' => [
  33.                     'label' => 'form.password_confirm',
  34.                     'event_dispatcher' => null,
  35.                     'mapped' => true,
  36.                 ],
  37.             ])
  38.             ->add('recaptcha'EWZRecaptchaType::class, [
  39.                 'mapped' => false,
  40.                 'attr' => [
  41.                     'options' => [
  42.                         'theme' => 'light',
  43.                         'type' => 'image',
  44.                         'size' => 'normal',
  45.                     ],
  46.                 ],
  47.                 'constraints' => [
  48.                     new RecaptchaIsTrue(['message' => 'recaptcha.error']),
  49.                 ],
  50.             ])
  51.         ;
  52.     }
  53.     public function configureOptions(OptionsResolver $resolver): void
  54.     {
  55.         $resolver->setDefaults([
  56.             'data_class' => User::class,
  57.             'translation_domain' => 'registration',
  58.             'validation_groups' => ['registration''Default'],
  59.         ]);
  60.     }
  61.     public function getBlockPrefix(): string
  62.     {
  63.         return 'registration';
  64.     }
  65. }