<?php
namespace App\Form\Main;
use App\Services\TranslationManager;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints\Email;
use Symfony\Component\Validator\Constraints\NotBlank;
final class AffiliationContactType extends AbstractType
{
protected $recaptchaKey;
protected $recaptchaTestKey;
private $environment;
/**
* AffiliationContactType constructor.
* @param $recaptchaKey
* @param $recaptchaTestKey
* @param $environment
*/
public function __construct($recaptchaKey, $recaptchaTestKey, $environment)
{
$this->recaptchaKey = $recaptchaKey;
$this->recaptchaTestKey = $recaptchaTestKey;
$this->environment = $environment;
}
public function buildForm(FormBuilderInterface $builder, array $options)
{
if ('test' == $this->environment) {
$recaptchaKey = $this->recaptchaTestKey;
} else {
$recaptchaKey = $this->recaptchaKey;
}
$builder
->add('firstName')
->add('lastName')
->add(
'email',
EmailType::class,
[
'constraints' => [
new Email(),
new NotBlank()
]
]
)
->add('title')
->add('message')
->add(
'submit',
SubmitType::class,
[
"attr" => [
"class" => "g-recaptcha btn btn-primary btn-lg",
"id" => "aff-form-submit-btn",
"data-sitekey" => $recaptchaKey,
"data-callback" => "onSubmit"
]
]
)
;
}
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(['translation_domain' => TranslationManager::TRANSLATION_DOMAIN_SITE]);
}
}