src/Form/RegistrationFormType.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Form;
  3. use App\Entity\User;
  4. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  5. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  6. use Symfony\Component\Form\Extension\Core\Type\IntegerType;
  7. use Symfony\Component\Form\Extension\Core\Type\PasswordType;
  8. use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
  9. use Symfony\Component\Form\Extension\Core\Type\TextType;
  10. use Symfony\Component\Form\FormBuilderInterface;
  11. use Symfony\Component\OptionsResolver\OptionsResolver;
  12. use Symfony\Component\Validator\Constraints\IsTrue;
  13. use Symfony\Component\Validator\Constraints\Length;
  14. use Symfony\Component\Validator\Constraints\NotBlank;
  15. class RegistrationFormType extends UserBasicFormType
  16. {
  17.     private const LIST_MANUFACTURER = ['Charlatte Réservoirs''Réservoir Massal''Réservoirs X Pauchard'];
  18.     public const FIELD_EQUIPMENT_NAMES = ['manufacturer''serialNumber''manufactureDate''companyName'];
  19.     public function buildForm(FormBuilderInterface $builder, array $options): void
  20.     {
  21.         parent::buildForm($builder$options);
  22.         $builder
  23.             ->add('manufacturer'ChoiceType::class, [
  24.                 'choices' => array_combine(self::LIST_MANUFACTURERself::LIST_MANUFACTURER),
  25.                 'mapped' => false,
  26.                 'required' => true,
  27.                 'label' => 'Registration.Form.Manufacturer',
  28.             ])
  29.             ->add('serialNumber'null, [
  30.                 'mapped' => false,
  31.                 'required' => true,
  32.                 'label' => 'Registration.Form.SerialNumber',
  33.             ])
  34.             ->add('manufactureDate'IntegerType::class, [
  35.                 'mapped' => false,
  36.                 'required' => true,
  37.                 'label' => 'Registration.Form.ManufactureDate',
  38.             ])
  39.             ->add('companyName'TextType::class, [
  40.                 'required' => true,
  41.                 'label' => 'Registration.Form.companyName',
  42.                 'mapped' => false,
  43.             ])
  44.             ->add('agreeTerms'CheckboxType::class, [
  45.                 'mapped' => false,
  46.                 'constraints' => [
  47.                     new IsTrue([
  48.                         'message' => 'Form.AgreeTerms',
  49.                     ]),
  50.                 ],
  51.                 'label' => 'Registration.Form.AgreeTerms',
  52.                 'required' => true,
  53.             ])
  54.             ->add('plainPassword'RepeatedType::class, [
  55.                 'type' => PasswordType::class,
  56.                 'first_options' => [
  57.                     'attr' => ['autocomplete' => 'new-password'],
  58.                     'constraints' => [
  59.                         new NotBlank([
  60.                             'message' => 'ResetPassword.Form.EnterPassword',
  61.                         ]),
  62.                         new Length([
  63.                             'min' => 6,
  64.                             'minMessage' => 'Form.ValidatorPassword',
  65.                             // max length allowed by Symfony for security reasons
  66.                             'max' => 4096,
  67.                         ]),
  68.                     ],
  69.                     'label' => 'Registration.Form.Password',
  70.                     'required' => true,
  71.                 ],
  72.                 'second_options' => [
  73.                     'attr' => ['autocomplete' => 'new-password'],
  74.                     'label' => 'Registration.Form.ConfirmePassword',
  75.                     'required' => true,
  76.                 ],
  77.                 'invalid_message' => 'Form.MatchPassword',
  78.                 // instead of being set onto the object directly,
  79.                 // this is read and encoded in the controller
  80.                 'mapped' => false,
  81.             ]);
  82.     }
  83.     public function configureOptions(OptionsResolver $resolver): void
  84.     {
  85.         $resolver->setDefaults([
  86.             'data_class' => User::class,
  87.             'translation_domain' => 'app',
  88.         ]);
  89.     }
  90. }