src/Form/RegistrationTeacherType.php line 23

  1. <?php
  2. namespace App\Form;
  3. use App\Entity\Categorie;
  4. use App\Entity\User;
  5. use App\Validator\InvitationCode;
  6. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  7. use Symfony\Component\Form\AbstractType;
  8. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  9. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  10. use Symfony\Component\Form\Extension\Core\Type\PasswordType;
  11. use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
  12. use Symfony\Component\Form\Extension\Core\Type\TextType;
  13. use Symfony\Component\Form\FormBuilderInterface;
  14. use Symfony\Component\OptionsResolver\OptionsResolver;
  15. use Symfony\Component\Validator\Constraints\Callback;
  16. use Symfony\Component\Validator\Constraints\IsTrue;
  17. use Symfony\Component\Validator\Constraints\Length;
  18. use Symfony\Component\Validator\Constraints\NotBlank;
  19. use Symfony\Component\Validator\Constraints\Regex;
  20. class RegistrationTeacherType extends AbstractType
  21. {
  22.     public function buildForm(FormBuilderInterface $builder, array $options): void
  23.     {
  24.         $builder
  25.             ->add('email'EmailType::class, [
  26.                 'attr' => [
  27.                     'class' => 'border-0 bg-light rounded-end ps-1'
  28.                     'id' => 'last_name'
  29.                 ], 
  30.                 'label' => 'Email adress'
  31.             ])
  32.             ->add('parentCode'TextType::class, [
  33.                 'label' => "Invitation Code",
  34.                 'required' => false,
  35.                 'constraints' => [
  36.                     new InvitationCode()
  37.                 ],
  38.                 'attr' => [
  39.                     'class' => 'border-0 bg-light rounded-end ps-1',
  40.                     'placeholder' => "Insérer le code d'invitation ici si vous en avez un"
  41.                 ], 
  42.             ])
  43.             ->add('agreeTerms'CheckboxType::class, [
  44.                 'mapped' => false,
  45.                 'constraints' => [
  46.                     new IsTrue([
  47.                         'message' => 'You should agree to our terms.',
  48.                     ]),
  49.                 ],
  50.                 'label_html' => true,
  51.                 'label' => "By signing up, you agree to the <a href=''>terms</a>"
  52.             ])
  53.             ->add('username'TextType::class, [
  54.                 'mapped' => true,
  55.                 'required' => true,
  56.                 'constraints' => [
  57.                     new NotBlank([
  58.                         'message' => 'REQUIRED_FIELD_KEY'
  59.                     ]),
  60.                     new Length([
  61.                         'min' => 5,
  62.                         'max' => 8,
  63.                         'minMessage' => 'USERNAME_TOO_SHORT_KEY',
  64.                         'maxMessage' => 'USERNAME_TOO_LONG_KEY'
  65.                     ]),
  66.                     new Regex([
  67.                         'pattern' => '/^[a-zA-Z0-9_]+$/',
  68.                         'message' => 'INVALID_USERNAME_KEY'
  69.                     ]),
  70.                     new Callback([$this'validateUniqueUsername'])
  71.                 ]
  72.             ])
  73.             ->add('plainPassword'RepeatedType::class, [
  74.                 // instead of being set onto the object directly,
  75.                 // this is read and encoded in the controller
  76.                 'mapped' => false,
  77.                 'type' => PasswordType::class,
  78.                 'invalid_message' => 'The password fields must match.',
  79.                 'options' => ['attr' => ['class' => 'border-0 bg-light rounded-end ps-1''autocomplete' => 'new-password']],
  80.                 'required' => true,
  81.                 'first_options'  => ['label' => 'Password'],
  82.                 'second_options' => ['label' => 'Repeat Password'],
  83.                 
  84.             ])
  85.             ->add("personne"PersonneType::class)
  86.             ->add('enseignant'EnseignantType::class)
  87.         ;
  88.     }
  89.     public function configureOptions(OptionsResolver $resolver): void
  90.     {
  91.         $resolver->setDefaults([
  92.             'data_class' => User::class,
  93.         ]);
  94.     }
  95. }