src/Form/User/AccountCreationFormType.php line 21

Open in your IDE?
  1. <?php
  2. namespace App\Form\User;
  3. use App\Entity\Organization;
  4. use App\Entity\Statut;
  5. use App\Entity\University;
  6. use App\Entity\User;
  7. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  8. use Symfony\Component\Form\AbstractType;
  9. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  10. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  11. use Symfony\Component\Form\Extension\Core\Type\PasswordType;
  12. use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
  13. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  14. use Symfony\Component\Form\Extension\Core\Type\TextType;
  15. use Symfony\Component\Form\FormBuilderInterface;
  16. use Symfony\Component\OptionsResolver\OptionsResolver;
  17. use Symfony\Component\Validator\Constraints\Regex;
  18. class AccountCreationFormType extends AbstractType
  19. {
  20.     /**
  21.      * {@inheritdoc}
  22.      */
  23.     public function buildForm(FormBuilderInterface $builder, array $options)
  24.     {
  25.         $builder
  26.             ->add(
  27.                 'email',
  28.                 EmailType::class,
  29.                 [
  30.                     'label' => 'form.label.email',
  31.                     'required' => true,
  32.                 ]
  33.             )
  34.             ->add(
  35.                 'firstName',
  36.                 TextType::class,
  37.                 [
  38.                     'label' => 'form.label.first_name',
  39.                     'required' => true,
  40.                 ]
  41.             )
  42.             ->add(
  43.                 'lastName',
  44.                 TextType::class,
  45.                 [
  46.                     'label' => 'form.label.last_name',
  47.                     'required' => true,
  48.                 ]
  49.             )
  50.             ->add(
  51.                 'organization',
  52.                 EntityType::class,
  53.                 [
  54.                     'label' => 'form.label.organization',
  55.                     'class' => Organization::class,
  56.                     'choice_label' => 'name',
  57.                     'placeholder' => 'form.label.none',
  58.                     'required' => false,
  59.                 ]
  60.             )
  61.             ->add(
  62.                 'password',
  63.                 RepeatedType::class,
  64.                 [
  65.                     'type' => PasswordType::class,
  66.                     'invalid_message' => 'the password fields must match',
  67.                     'mapped' => false,
  68.                     'first_options' => [
  69.                         'label' => 'form.label.new_password',
  70.                         'required' => true,
  71.                     ],
  72.                     'second_options' => [
  73.                         'label' => 'form.label.confirmation_password',
  74.                         'required' => true,
  75.                     ],
  76.                     'constraints' => [
  77.                         new Regex('/(?=(.*[0-9]))(?=.*[a-z])(?=(.*[A-Z]))(?=(.*)).{8,}/''form.alert.password_rule'),
  78.                     ],
  79.                 ]
  80.             )
  81.             ->add(
  82.                 'statut',
  83.                 EntityType::class,
  84.                 [
  85.                     'label' => 'form.label.statut',
  86.                     'class' => Statut::class,
  87.                     'choice_label' => 'name',
  88.                     'required' => $options['statut_required'],
  89.                     'disabled' => $options['statut_disabled'],
  90.                     'placeholder' => 'form.label.none',
  91.                 ]
  92.             )
  93.             /* Uncomment when checkbox integration is done
  94.             ->add(
  95.                 'checkbox',
  96.                 CheckboxType::class,
  97.                 ['mapped' => false,
  98.                 'label' => 'form.action.accepted_cgu',
  99.                 'required' => true]
  100.             ) */
  101.             ->add('submit'SubmitType::class, [
  102.                 'label' => 'form.label.register',
  103.             ]);
  104.     }
  105.     /**
  106.      * {@inheritdoc}
  107.      */
  108.     public function configureOptions(OptionsResolver $resolver)
  109.     {
  110.         $resolver->setDefaults([
  111.             'data_class' => User::class,
  112.             'statut_disabled' => false,
  113.             'statut_required' => true,
  114.         ]);
  115.     }
  116. }