src/Form/Payment/FundingType.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Form\Payment;
  3. use App\Entity\Account\User;
  4. use Karser\Recaptcha3Bundle\Form\Recaptcha3Type;
  5. use Karser\Recaptcha3Bundle\Validator\Constraints\Recaptcha3;
  6. use Symfony\Component\Form\AbstractType;
  7. use Symfony\Component\Form\Extension\Core\Type\TelType;
  8. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  9. use Symfony\Component\Form\Extension\Core\Type\TextType;
  10. use Symfony\Component\Form\FormBuilderInterface;
  11. use Symfony\Component\OptionsResolver\OptionsResolver;
  12. use Symfony\Component\Security\Core\Security;
  13. use Symfony\Component\Validator\Constraints\NotBlank;
  14. class FundingType extends AbstractType
  15. {
  16.     public function __construct(
  17.         private Security $security
  18.     )
  19.     {
  20.     }
  21.     public function buildForm(FormBuilderInterface $builder, array $options): void
  22.     {
  23.         $user $this->security->getUser();
  24.         $builder
  25.             ->add('paymentMeaning'TextType::class, [
  26.                 'label' => 'funding.form.payment_meaning.label',
  27.                 'required' => true,
  28.                 'constraints' => new NotBlank(),
  29.             ])
  30.             ->add('status'TextType::class, [
  31.                 'label' => 'funding.form.status.label',
  32.                 'required' => true,
  33.                 'constraints' => new NotBlank(),
  34.             ])
  35.             ->add('lastName'TextType::class, [
  36.                 'label' => 'funding.form.last_name.label',
  37.                 'data' => $user instanceof User $user->getLastname() : '',
  38.                 'attr' => [
  39.                     'readonly' => $user instanceof User
  40.                 ],
  41.                 'required' => true,
  42.                 'constraints' => new NotBlank(),
  43.             ])
  44.             ->add('firstName'TextType::class, [
  45.                 'label' => 'funding.form.first_name.label',
  46.                 'data' => $user instanceof User $user->getFirstName() : '',
  47.                 'attr' => [
  48.                     'readonly' => $user instanceof User
  49.                 ],
  50.                 'required' => true,
  51.                 'constraints' => new NotBlank(),
  52.             ])
  53.             ->add('mail'TextType::class, [
  54.                 'label' => 'funding.form.mail.label',
  55.                 'data' => $user instanceof User $user->getEmail() : '',
  56.                 'attr' => [
  57.                     'readonly' => $user instanceof User
  58.                 ],
  59.                 'required' => true,
  60.                 'constraints' => new NotBlank(),
  61.             ])
  62.             ->add('phone'TelType::class, [
  63.                 'required' => true,
  64.                 'label' => 'funding.form.phone.label',
  65.             ])
  66.             ->add('message'TextareaType::class, [
  67.                 'label' => 'funding.form.message.label',
  68.                 'required' => true,
  69.                 'constraints' => new NotBlank(),
  70.             ])
  71.             ->add('captcha'Recaptcha3Type::class, [
  72.                 'constraints' => new Recaptcha3([
  73.                     'message' => 'karser_recaptcha3.message',
  74.                 ]),
  75.                 'action_name' => 'registration',
  76.                 'locale' => $options['locale'],
  77.             ]);
  78.     }
  79.     public function configureOptions(OptionsResolver $resolver): void
  80.     {
  81.         $resolver->setDefaults([
  82.             'locale' => 'fr',
  83.         ]);
  84.     }
  85. }