src/Form/RegistrationFormType.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\Form;
  3. use Symfony\Component\Form\Extension\Core\Type\TextType;
  4. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  5. use Symfony\Component\Form\Extension\Core\Type\PasswordType;
  6. use Symfony\Component\Form\Extension\Core\Type\CountryType;
  7. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  8. use App\Entity\Group;
  9. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  10. use Symfony\Component\Form\AbstractType;
  11. use Symfony\Component\Form\FormBuilderInterface;
  12. use Symfony\Component\OptionsResolver\OptionsResolver;
  13. use Symfony\Component\Validator\Constraints as Assert;
  14. use Symfony\Component\Form\Extension\Core\Type as Type;
  15. use App\Entity\User;
  16. class RegistrationFormType extends AbstractType
  17. {
  18.     public function buildForm(FormBuilderInterface $builder, array $options): void
  19.     {
  20.         $builder
  21.             ->add('company'TextType::class, [
  22.                 'label'     => false,
  23.                 'mapped'    => false,
  24.                 'constraints'   => new Assert\NotBlank(['groups' => 'Registration'])
  25.             ])
  26.             ->add('email'EmailType::class, [
  27.                 'label'     => false,
  28.                 'constraints'   => new Assert\Email(['groups' => 'Registration'])
  29.             ])
  30.             ->add('username'null, [
  31.                 'label'     => false,
  32.             ])
  33.             ->add('plainPassword'PasswordType::class, [
  34.                 'label'     => false,
  35.             ])
  36.             ->add('package'EntityType::class, array(
  37.                 'class' => Group::class,
  38.                 'constraints' => new Assert\NotNull([
  39.                     'groups' => 'Registration',
  40.                     'message' => 'Proszę wybrać pakiet.'
  41.                 ]),
  42.                 'mapped'    => false,
  43.                 'label'     => false,
  44.                 // 'placeholder' => 'Plan',
  45.             ))
  46.             ->add('country'CountryType::class, [
  47.                 'constraints'   => new Assert\NotNull([
  48.                     'groups'    => 'Registration',
  49.                     'message'   => 'Proszę wybrać kraj.'
  50.                 ]),
  51.                 'mapped'    => false,
  52.                 'label'     => false,
  53.                 'placeholder'   => 'Kraj',
  54.             ])
  55.             ->add('agree'CheckboxType::class, array(
  56.                 'label'     => "form.user.agree",
  57.                 'mapped'    => false,
  58.                 'constraints'   => new Assert\NotBlank(['groups' => 'Registration'])
  59.             ));
  60.     }
  61.     public function configureOptions(OptionsResolver $resolver): void
  62.     {
  63.         $resolver->setDefaults(array(
  64.             'data_class' => User::class,
  65.             'csrf_token_id' => 'registration',
  66.             // BC for SF < 2.8
  67.             'intention'  => 'registration',
  68.         ));
  69.     }
  70.     public function getBlockPrefix()
  71.     {
  72.         return 'app_user_registration';
  73.     }
  74. }