src/Form/RegistrationFormType.php line 156

Open in your IDE?
  1. <?php
  2. namespace App\Form;
  3. use App\Entity\Country;
  4. use App\Entity\Referee;
  5. use App\Repository\CountryRepository;
  6. use Symfony\Component\Form\AbstractType;
  7. use Symfony\Component\Form\FormBuilderInterface;
  8. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  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\OptionsResolver\OptionsResolver;
  13. use Symfony\Component\Form\Extension\Core\Type\TelType;
  14. use Symfony\Component\Form\Extension\Core\Type\FileType;
  15. use Symfony\Component\Form\Extension\Core\Type\TextType;
  16. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  17. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  18. use Symfony\Component\Form\Extension\Core\Type\BirthdayType;
  19. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  20. use Symfony\Component\Form\Extension\Core\Type\PasswordType;
  21. class RegistrationFormType extends AbstractType
  22. {
  23.     public function buildForm(FormBuilderInterface $builder, array $options): void
  24.     {
  25.         $builder
  26.         ->add('gender'ChoiceType::class, [
  27.             'choices'  => [
  28.                 'Mme' => 0,
  29.                 'Mr.' => 1,
  30.             ],
  31.             'row_attr' => ['class' => 'mb-3 col-lg-2 col-sm-5'],
  32.             'label' => 'Gender',
  33.             'label_attr' => ['class' => 'radio-inline'],
  34.             'multiple' => false,
  35.             'expanded' => true,
  36.         ])
  37.         ->add('firstname'TextType::class, [
  38.             'row_attr' => ['class' => 'mb-3 col-lg-5 col-sm-6'],
  39.             'label' => 'Fist Name (Second name)',
  40.         ])
  41.         ->add('lastname'TextType::class, [
  42.             'row_attr' => ['class' => 'mb-3 col-lg-5 col-sm-5'],
  43.             'label' => 'Last Name',
  44.         ])
  45.         ->add('email'TextType::class, [
  46.             'row_attr' => ['class' => 'mb-3 col-lg-6 col-sm-12'],
  47.             'label' => 'Email',
  48.         ])
  49.         ->add('birthday'BirthdayType::class, [
  50.             'row_attr' => ['class' => 'mb-3 col-lg-6 col-sm-12'],
  51.             'label' => 'Birthday',
  52.             'required'   => false,
  53.         ])
  54.         ->add('phone1'TelType::class, [
  55.             'row_attr' => ['class' => 'mb-3 col-lg-6 col-sm-12'],
  56.             'label' => 'Phone Number',
  57.         ])
  58.         ->add('phone2'TelType::class, [
  59.             'row_attr' => ['class' => 'mb-3 col-lg-6 col-sm-12'],
  60.             'label' => 'Phone Number 2',
  61.             'required'   => false,
  62.         ])
  63.         
  64.         ->add('kyorugiNumber'TextType::class, [
  65.             'row_attr' => ['class' => 'mb-3 col-lg-4 col-sm-8'],
  66.             'label' => 'KYORUGI IR Number',
  67.             'required'   => false,
  68.         ])
  69.         ->add('kyorugiClass'ChoiceType::class, [
  70.             'row_attr' => ['class' => 'mb-3 col-lg-2 col-sm-4'],
  71.             'label' => 'KYORUGI RANK',
  72.             'choices'  => [
  73.                 'P' => 'P',
  74.                 '3' => 3,
  75.                 '2' => 2,
  76.                 '1' => 1,
  77.                 'S' => 'S',
  78.             ],
  79.             'required'   => false,
  80.         ])
  81.         ->add('poomsaeNumber'TextType::class, [
  82.             'row_attr' => ['class' => 'mb-3 col-lg-4 col-sm-8'],
  83.             'label' => 'POOMSAE IR Number',
  84.             'required'   => false,
  85.         ])
  86.         ->add('poomsaeClass'ChoiceType::class, [
  87.             'row_attr' => ['class' => 'mb-3 col-lg-2 col-sm-4'],
  88.             'label' => 'POOMSAE RANK',
  89.             'choices'  => [
  90.                 'P' => 'P',
  91.                 '3' => 3,
  92.                 '2' => 2,
  93.                 '1' => 1,
  94.                 'S' => 'S',
  95.             ],
  96.             'required'   => false,
  97.         ])
  98.         ->add('avatar'FileType::class, [
  99.             'data_class' => null
  100.             'row_attr' => ['class' => 'mb-3 col-lg-4 col-sm-12''format' => 'img''dir' => 'profiles'],
  101.             'label' => 'Photo',
  102.             'required'   => false,
  103.         ])
  104.         ->add('kyorugiIRCard'FileType::class, [
  105.             'data_class' => null
  106.             'row_attr' => ['class' => 'mb-3 col-lg-4 col-sm-12''format' => 'img''dir' => 'badges'],
  107.             'label' => 'Kyorugi IR Card',
  108.             'required'   => false,
  109.         ])
  110.         ->add('poomsaeIRCard'FileType::class, [
  111.             'data_class' => null
  112.             'row_attr' => ['class' => 'mb-3 col-lg-4 col-sm-12''format' => 'img''dir' => 'badges'],
  113.             'label' => 'Poomsae IR Card',
  114.             'required'   => false,
  115.         ])
  116.         
  117.         ->add('country'EntityType::class, [
  118.             'row_attr' => ['class' => 'mb-3 col-lg-6 col-sm-12'],
  119.             'label' => 'Country',
  120.             'class' => Country::class,
  121.             'choice_label' => 'name',
  122.         ])
  123.         ->add('country'EntityType::class, [
  124.             'class' => Country::class,
  125.             'query_builder' => function (CountryRepository $er) {
  126.                 $qb $er->createQueryBuilder('country')
  127.                 ->innerJoin('country.continent''continent')
  128.                 ->orderBy('country.name''ASC');
  129.                 return $qb;
  130.             },
  131.             'group_by' => function (Country $country) {
  132.                 return $country->getContinent()->getName();
  133.             },
  134.             'row_attr' => ['class' => 'mb-3 col-lg-6 col-sm-12'],
  135.             'label' => 'Country',
  136.             'choice_label' => 'name',
  137.         ])
  138.         ->add('secondcountry'EntityType::class, [
  139.             'class' => Country::class,
  140.             'query_builder' => function (CountryRepository $er) {
  141.                 $qb $er->createQueryBuilder('country')
  142.                 ->innerJoin('country.continent''continent')
  143.                 ->orderBy('country.name''ASC');
  144.                 return $qb;
  145.             },
  146.             'group_by' => function (Country $country) {
  147.                 return $country->getContinent()->getName();
  148.             },
  149.             'row_attr' => ['class' => 'mb-3 col-lg-6 col-sm-12'],
  150.             'label' => 'Second Country',
  151.             'choice_label' => 'name',
  152.         ])
  153.         // ->add('agreeTerms', CheckboxType::class, [
  154.         //     'mapped' => false,
  155.         //     'constraints' => [
  156.         //         new IsTrue([
  157.         //             'message' => 'You should agree to our terms.',
  158.         //         ]),
  159.         //     ],
  160.         // ])
  161.         ->add('plainPassword'PasswordType::class, [
  162.             // instead of being set onto the object directly,
  163.             // this is read and encoded in the controller
  164.             'mapped' => false,
  165.             'attr' => ['autocomplete' => 'new-password'],
  166.             'constraints' => [
  167.                 new NotBlank([
  168.                     'message' => 'Please enter a password',
  169.                 ]),
  170.                 new Length([
  171.                     'min' => 6,
  172.                     'minMessage' => 'Your password should be at least {{ limit }} characters',
  173.                     // max length allowed by Symfony for security reasons
  174.                     'max' => 4096,
  175.                 ]),
  176.             ],
  177.         ])
  178.         ;
  179.     }
  180.     public function configureOptions(OptionsResolver $resolver): void
  181.     {
  182.         $resolver->setDefaults([
  183.             'data_class' => Referee::class,
  184.         ]);
  185.     }
  186. }