src/Form/RegistrationFormType.php line 15

  1. <?php
  2. namespace App\Form;
  3. use App\Entity\User;
  4. use App\Services\TranslationsWorkerService;
  5. use Symfony\Component\Form\AbstractType;
  6. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  7. use Symfony\Component\Form\Extension\Core\Type\PasswordType;
  8. use Symfony\Component\Form\FormBuilderInterface;
  9. use Symfony\Component\OptionsResolver\OptionsResolver;
  10. use Symfony\Component\Validator\Constraints\IsTrue;
  11. use Symfony\Component\Validator\Constraints\Length;
  12. use Symfony\Component\Validator\Constraints\NotBlank;
  13. class RegistrationFormType extends AbstractType
  14. {
  15.     public function buildForm(FormBuilderInterface $builder, array $options)
  16.     {
  17.         $builder
  18.             ->add('firstName')
  19.             ->add('lastName')
  20.             ->add('mobile')
  21.             ->add('email')
  22.             ->add('plainPassword'PasswordType::class, [
  23.                 // instead of being set onto the object directly,
  24.                 // this is read and encoded in the controller
  25.                 'mapped' => false,
  26.                 'attr' => ['autocomplete' => 'new-password'],
  27.                 'constraints' => [
  28.                     new NotBlank([
  29.                         'message' => 'Please enter a password',
  30.                     ]),
  31.                     new Length([
  32.                         'min' => 6,
  33.                         'minMessage' => 'Your password should be at least {{ limit }} characters',
  34.                         // max length allowed by Symfony for security reasons
  35.                         'max' => 4096,
  36.                     ]),
  37.                 ],
  38.             ])
  39.         ;
  40.     }
  41.     public function configureOptions(OptionsResolver $resolver)
  42.     {
  43.         $resolver->setDefaults([
  44.             'data_class' => User::class,
  45.         ]);
  46.     }
  47.     public function __construct(TranslationsWorkerService $translationsWorker)
  48.     {
  49.         $this->translationsWorker $translationsWorker;
  50.     }
  51. }