<?php
namespace App\Form\Front;
use App\Constant\ContactUserType;
use App\Entity\ContactMessage;
use EWZ\Bundle\RecaptchaBundle\Form\Type\EWZRecaptchaType;
use EWZ\Bundle\RecaptchaBundle\Validator\Constraints\IsTrue as RecaptchaTrue;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Routing\RouterInterface;
class ContactType extends AbstractType
{
private $router;
public function __construct(RouterInterface $router)
{
$this->router = $router;
}
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('recaptcha', EWZRecaptchaType::class, [
'attr' => [
'options' => [
'theme' => 'light',
'type' => 'image',
'size' => 'small'
]
],
'mapped' => false,
'constraints' => array(
new RecaptchaTrue()
)
])
->add('subject', TextType::class, array('label' => 'label.subject'))
->add('firstname', TextType::class, array('label' => 'label.firstname'))
->add('lastname', TextType::class, array('label' => 'label.lastname'))
->add('email', EmailType::class, array('label' => 'label.email'))
->add('phone', TextType::class, array('label' => 'label.phone'))
->add('company', TextType::class, array('label' => 'label.company', 'required' => false))
->add('userType', ChoiceType::class, array(
'label' => 'label.userType',
'choices' => ContactUserType::getList(),
))
->add('message', TextareaType::class, array('label' => 'label.message'))
->add('optin', CheckboxType::class, array('label' => 'label.acceptOptin', 'required' => true))
;
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => ContactMessage::class,
'translation_domain' => 'front',
'type' => '',
));
}
}