src/Form/RegistrationFormType.php line 85

Open in your IDE?
  1. <?php
  2. namespace App\Form;
  3. use App\Entity\Area;
  4. use App\Entity\Role;
  5. use App\Entity\Unidad;
  6. use App\Entity\Usuario;
  7. use Doctrine\ORM\EntityRepository;
  8. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  9. use Symfony\Component\Form\AbstractType;
  10. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  11. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  12. use Symfony\Component\Form\Extension\Core\Type\PasswordType;
  13. use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
  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\NotBlank;
  18. class RegistrationFormType extends AbstractType
  19. {
  20.     public function buildForm(FormBuilderInterface $builder, array $options): void
  21.     {
  22.         $builder
  23.             ->add('nombre'null, [
  24.                 'label' => '* Nombre(s)',
  25.                 'attr' => ['class' => 'form-control'],
  26.                 'constraints' => [
  27.                     new NotBlank([
  28.                         'message' => 'Ingrese su(s) nombre(s) por favor',
  29.                     ])
  30.                 ],
  31.                 'required' => true,
  32.             ])
  33.             ->add('papellido'null, [
  34.                 'label' => '* Primer apellido (Paterno)',
  35.                 'attr' => ['class' => 'form-control'],
  36.                 'constraints' => [
  37.                     new NotBlank(['message' => 'El campo sebe llenarse.']),
  38.                 ],
  39.                 'required' => true,
  40.             ])
  41.             ->add('sapellido'null, [
  42.                 'label' => 'Segundo apellido (Materno)',
  43.                 'attr' => ['class' => 'form-control']
  44.             ])
  45.             ->add('correo'RepeatedType::class, [
  46.                 'type' => TextType::class,
  47.                 'first_options' => [
  48.                     'label' => '* Correo',
  49.                     'attr' => ['class' => 'form-control'],
  50.                     'constraints' => [
  51.                         new NotBlank([
  52.                             'message' => 'Ingrese su correo por favor',
  53.                         ])
  54.                     ],
  55.                 ],
  56.                 'second_options' => [
  57.                     'label' => '* Repetir correo',
  58.                     'attr' => ['class' => 'form-control''autocomplete' => 'off']
  59.                 ],
  60.                 'invalid_message' => 'Los correos deben coincidir.',
  61.                 // Instead of being set onto the object directly,
  62.                 // this is read and encoded in the controller
  63.                 'mapped' => true,
  64.             ])
  65.             ->add('contrasena'null, [
  66.                 'label' => "* Contraseña",
  67.                 'attr' => ['class' => 'form-control'],
  68.                 'constraints' => [
  69.                     new NotBlank([
  70.                         'message' => 'Este campo no debe estar vacío',
  71.                     ]),
  72.                 ],
  73.                 'required' => true
  74.             ])
  75.             ->add('unidad'EntityType::class, [
  76.                 'label' => '* Unidad administrativa / Plantel',
  77.                 'class' => Unidad::class,
  78.                 'required' => true,
  79.                 'attr' => [
  80.                     'class' => 'form-control'
  81.                 ],
  82.                 'query_builder' => function (EntityRepository $er) {
  83.                     return $er->createQueryBuilder('u')
  84.                         ->orderBy('u.nombre''ASC');
  85.                 }
  86.             ])
  87.             ->add('rol'null, [
  88.                 'label' => '* Rol',
  89.                 'class' => Role::class,
  90.                 'required' => true,
  91.                 'attr' => ['class' => 'form-control']
  92.             ])
  93.             ->add('estatus'ChoiceType::class, [
  94.                 'choices'  => [
  95.                     'Pendiente' => 'Pendiente',
  96.                     'Rechazado' => 'Rechazado',
  97.                     'Aceptado' => 'Aceptado',
  98.                     'Activo' => 'Activo',
  99.                     'Suspendido' => 'Suspendido'
  100.                 ],
  101.                 'attr' => ['class' => 'form-control']
  102.             ])
  103.             /*
  104.              ->add('agreeTerms', CheckboxType::class, [
  105.                 'mapped' => false,
  106.                 'constraints' => [
  107.                     new IsTrue([
  108.                         'message' => 'You should agree to our terms.',
  109.                     ]),
  110.                 ],
  111.             ])
  112.             ->add('plainPassword', PasswordType::class, [
  113.                 // instead of being set onto the object directly,
  114.                 // this is read and encoded in the controller
  115.                 'mapped' => false,
  116.                 'attr' => ['autocomplete' => 'new-password'],
  117.                 'constraints' => [
  118.                     new NotBlank([
  119.                         'message' => 'Please enter a password',
  120.                     ]),
  121.                     new Length([
  122.                         'min' => 6,
  123.                         'minMessage' => 'Your password should be at least {{ limit }} characters',
  124.                         // max length allowed by Symfony for security reasons
  125.                         'max' => 4096,
  126.                     ]),
  127.                 ],
  128.             ])
  129.             */
  130.         ;
  131.     }
  132.     public function configureOptions(OptionsResolver $resolver): void
  133.     {
  134.         $resolver->setDefaults([
  135.             'data_class' => Usuario::class,
  136.         ]);
  137.     }
  138. }