<?php
namespace App\Form;
use App\Entity\Area;
use App\Entity\Role;
use App\Entity\Unidad;
use App\Entity\Usuario;
use Doctrine\ORM\EntityRepository;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints\NotBlank;
class RegistrationFormType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('nombre', null, [
'label' => '* Nombre(s)',
'attr' => ['class' => 'form-control'],
'constraints' => [
new NotBlank([
'message' => 'Ingrese su(s) nombre(s) por favor',
])
],
'required' => true,
])
->add('papellido', null, [
'label' => '* Primer apellido (Paterno)',
'attr' => ['class' => 'form-control'],
'constraints' => [
new NotBlank(['message' => 'El campo sebe llenarse.']),
],
'required' => true,
])
->add('sapellido', null, [
'label' => 'Segundo apellido (Materno)',
'attr' => ['class' => 'form-control']
])
->add('correo', RepeatedType::class, [
'type' => TextType::class,
'first_options' => [
'label' => '* Correo',
'attr' => ['class' => 'form-control'],
'constraints' => [
new NotBlank([
'message' => 'Ingrese su correo por favor',
])
],
],
'second_options' => [
'label' => '* Repetir correo',
'attr' => ['class' => 'form-control', 'autocomplete' => 'off']
],
'invalid_message' => 'Los correos deben coincidir.',
// Instead of being set onto the object directly,
// this is read and encoded in the controller
'mapped' => true,
])
->add('contrasena', null, [
'label' => "* Contraseña",
'attr' => ['class' => 'form-control'],
'constraints' => [
new NotBlank([
'message' => 'Este campo no debe estar vacío',
]),
],
'required' => true
])
->add('unidad', EntityType::class, [
'label' => '* Unidad administrativa / Plantel',
'class' => Unidad::class,
'required' => true,
'attr' => [
'class' => 'form-control'
],
'query_builder' => function (EntityRepository $er) {
return $er->createQueryBuilder('u')
->orderBy('u.nombre', 'ASC');
}
])
->add('rol', null, [
'label' => '* Rol',
'class' => Role::class,
'required' => true,
'attr' => ['class' => 'form-control']
])
->add('estatus', ChoiceType::class, [
'choices' => [
'Pendiente' => 'Pendiente',
'Rechazado' => 'Rechazado',
'Aceptado' => 'Aceptado',
'Activo' => 'Activo',
'Suspendido' => 'Suspendido'
],
'attr' => ['class' => 'form-control']
])
/*
->add('agreeTerms', CheckboxType::class, [
'mapped' => false,
'constraints' => [
new IsTrue([
'message' => 'You should agree to our terms.',
]),
],
])
->add('plainPassword', PasswordType::class, [
// instead of being set onto the object directly,
// this is read and encoded in the controller
'mapped' => false,
'attr' => ['autocomplete' => 'new-password'],
'constraints' => [
new NotBlank([
'message' => 'Please enter a password',
]),
new Length([
'min' => 6,
'minMessage' => 'Your password should be at least {{ limit }} characters',
// max length allowed by Symfony for security reasons
'max' => 4096,
]),
],
])
*/
;
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => Usuario::class,
]);
}
}