src/Form/RegistrationFormType.php line 26

  1. <?php
  2. namespace App\Form;
  3. use App\Entity\User;
  4. use Symfony\Component\Form\AbstractType;
  5. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  6. use Symfony\Component\Form\Extension\Core\Type\PasswordType;
  7. use Symfony\Component\Form\FormBuilderInterface;
  8. use Symfony\Component\OptionsResolver\OptionsResolver;
  9. use Symfony\Component\Validator\Constraints\IsTrue;
  10. use Symfony\Component\Validator\Constraints\Length;
  11. use Symfony\Component\Validator\Constraints\NotBlank;
  12. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  13. use Symfony\Component\Form\Extension\Core\Type\CollectionType;
  14. use Symfony\Component\Form\Extension\Core\Type\HiddenType;
  15. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  16. use App\Entity\Organization;
  17. use Doctrine\ORM\EntityRepository;
  18. use App\Entity\Province;
  19. use Symfony\Component\Form\ChoiceList\ChoiceList;
  20. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  21. use Symfony\Component\Form\Extension\Core\Type\TextType;
  22. use App\Entity\Specialty;
  23. class RegistrationFormType extends AbstractType
  24. {
  25.     public function buildForm(FormBuilderInterface $builder, array $options): void
  26.     {
  27.         $builder
  28.             ->add('email', EmailType::class, [
  29.                 'label' => 'Correo electrónico',  
  30.                 'attr' => ['autocomplete' => 'email'],
  31.             ])
  32.             ->add('name', TextType::class, [
  33.                 'label' => 'Nombre',
  34.                 'attr' => ['autocomplete' => 'given-name'],
  35.             ])
  36.             ->add('lastname', TextType::class, [
  37.                 'label' => 'Apellidos',
  38.                 'attr' => ['autocomplete' => 'family-name'],
  39.             ])
  40.             ->add('collegiateNumber', TextType::class, [
  41.                 'label' => 'Número colegiado',
  42.             ])
  43.             ->add('specialty', TextType::class, [
  44.                 'label' => 'Especialidad',
  45.             ])
  46.             ->add('province', EntityType::class, [
  47.                 'class' => Province::class,
  48.                 'label' => 'Provincia',
  49.                 'mapped' => false,
  50. //                 'attr' => [
  51. //                     'disabled' => true,
  52. //                 ],
  53.             ])
  54.             ->add('organization', EntityType::class, [
  55.                 'class' => Organization::class,
  56.                 'label' => 'Hospital',
  57.                 'attr' => [
  58.                     'placeholder' => 'Primero elige una provincia',
  59.                     'disabled' => true,
  60.                 ],
  61.                 'required' => true,
  62. //                 'choice_attr' => ChoiceList::attr($this, function (?Organization $organization) {
  63. //                     return ['data-province-id' => $organization->getProvince()->getId()];
  64. //                  }),
  65. //                  'choice_label' => function(?Organization $organization) {
  66. //                     return $organization->getProvince() ? $organization->getTitle().' ('.$organization->getProvince()->getName().')' : $organization->getTitle();
  67. //                  },
  68.             ])
  69.             ->add('agreeTerms', CheckboxType::class, [
  70. //                 'label' => 'He leído y acepto la política de privacidad',
  71.                 'mapped' => false,
  72.                 'constraints' => [
  73.                     new IsTrue([
  74.                         'message' => 'Tiene que aceptar la política de privacidad',
  75.                     ]),
  76.                 ],
  77.             ])
  78.             ->add('isAccepted1', CheckboxType::class, [
  79.                 'label' => 'Acepto recibir comunicaciones comerciales.',
  80.                 'required' => false,
  81.             ])
  82. //             ->add('isAccepted2', CheckboxType::class, [
  83. //                 'label' => 'Acepto recibir comunicaciones comerciales.',
  84. //                 'required' => false,
  85. //             ])
  86. //             ->add('isAccepted3', CheckboxType::class, [
  87. //                 'label' => 'Llevar a cabo procedimientos de elaboración de perfiles o segmentación profesional para comprender mejor mis intereses, preferencias y mi opinión como profesional sanitario.',
  88. //                 'required' => false,
  89. //             ])
  90.             ->add('plainPassword', PasswordType::class, [
  91.                 // instead of being set onto the object directly,
  92.                 // this is read and encoded in the controller
  93.                 'mapped' => false,
  94.                 'attr' => ['autocomplete' => 'new-password'],
  95.                 'constraints' => [
  96.                     new NotBlank([
  97.                         'message' => 'Please enter a password',
  98.                     ]),
  99.                     new Length([
  100.                         'min' => 6,
  101.                         'minMessage' => 'La contraseña debe tenel al menos {{ limit }} simbolos',
  102.                         // max length allowed by Symfony for security reasons
  103.                         'max' => 4096,
  104.                     ]),
  105.                 ],
  106.                 'label' => 'Contraseña',
  107.             ])
  108.         ;
  109.     }
  110.     public function configureOptions(OptionsResolver $resolver): void
  111.     {
  112.         $resolver->setDefaults([
  113.             'data_class' => User::class,
  114.         ]);
  115.     }
  116. }