src/Form/Main/AffiliationContactType.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Form\Main;
  3. use App\Services\TranslationManager;
  4. use Symfony\Component\Form\AbstractType;
  5. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  6. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  7. use Symfony\Component\Form\FormBuilderInterface;
  8. use Symfony\Component\OptionsResolver\OptionsResolver;
  9. use Symfony\Component\Validator\Constraints\Email;
  10. use Symfony\Component\Validator\Constraints\NotBlank;
  11. final class AffiliationContactType extends AbstractType
  12. {
  13.     protected $recaptchaKey;
  14.     protected $recaptchaTestKey;
  15.     private $environment;
  16.     /**
  17.      * AffiliationContactType constructor.
  18.      * @param $recaptchaKey
  19.      * @param $recaptchaTestKey
  20.      * @param $environment
  21.      */
  22.     public function __construct($recaptchaKey$recaptchaTestKey$environment)
  23.     {
  24.         $this->recaptchaKey $recaptchaKey;
  25.         $this->recaptchaTestKey $recaptchaTestKey;
  26.         $this->environment $environment;
  27.     }
  28.     public function buildForm(FormBuilderInterface $builder, array $options)
  29.     {
  30.         if ('test' == $this->environment) {
  31.             $recaptchaKey $this->recaptchaTestKey;
  32.         } else {
  33.             $recaptchaKey $this->recaptchaKey;
  34.         }
  35.         $builder
  36.             ->add('firstName')
  37.             ->add('lastName')
  38.             ->add(
  39.                 'email',
  40.                 EmailType::class,
  41.                 [
  42.                     'constraints' => [
  43.                         new Email(),
  44.                         new NotBlank()
  45.                     ]
  46.                 ]
  47.             )
  48.             ->add('title')
  49.             ->add('message')
  50.             ->add(
  51.                 'submit',
  52.                 SubmitType::class,
  53.                 [
  54.                     "attr" => [
  55.                         "class" => "g-recaptcha btn btn-primary btn-lg",
  56.                         "id" => "aff-form-submit-btn",
  57.                         "data-sitekey" => $recaptchaKey,
  58.                         "data-callback" => "onSubmit"
  59.                     ]
  60.                 ]
  61.             )
  62.         ;
  63.     }
  64.     /**
  65.      * {@inheritdoc}
  66.      */
  67.     public function configureOptions(OptionsResolver $resolver)
  68.     {
  69.         $resolver->setDefaults(['translation_domain' => TranslationManager::TRANSLATION_DOMAIN_SITE]);
  70.     }
  71. }