<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace App\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use FOS\CKEditorBundle\Form\Type\CKEditorType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints\Email;
use Symfony\Component\Validator\Constraints\NotBlank;
use App\Form\Type\EWZRecaptchaType;
use EWZ\Bundle\RecaptchaBundle\Form\Type\EWZRecaptchaV3Type;
use EWZ\Bundle\RecaptchaBundle\Validator\Constraints\IsTrueV3;
final class ContactType extends AbstractType
{
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('email', EmailType::class, [
'label' => 'sylius.ui.email',
'constraints' => [
new NotBlank([
'message' => 'sylius.contact.email.not_blank',
]),
new Email([
'message' => 'sylius.contact.email.invalid',
]),
],
])
->add('message', CKEditorType::class, [
'label' => 'sylius.ui.message',
'config' => array('skin' => "moono_blue,/build/skins/moono_blue/"),
'constraints' => [
new NotBlank([
'message' => 'sylius.contact.message.not_blank',
]),
],
])
->add('recaptcha', EWZRecaptchaV3Type::class, array(
'action_name' => 'register',
'constraints' => array(
new IsTrueV3()
)))
->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) use ($options): void {
$email = $options['email'];
if (null === $email) {
return;
}
$data = $event->getData();
$data['email'] = $email;
$event->setData($data);
})
;
}
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver): void
{
$resolver
->setDefaults([
'email' => null,
])
;
}
/**
* {@inheritdoc}
*/
public function getBlockPrefix(): string
{
return 'sylius_contact';
}
}