<?php
/*
* This file is part of EC-CUBE
*
* Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
*
* http://www.ec-cube.co.jp/
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Eccube\Form\Type\Front;
use Eccube\Common\EccubeConfig;
use Eccube\Form\Type\AddressType;
use Eccube\Form\Type\KanaType;
use Eccube\Form\Type\NameType;
use Eccube\Form\Type\PhoneNumberType;
use Eccube\Form\Type\PostalType;
use Eccube\Form\Validator\Email;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Validator\Constraints as Assert;
//@## ADD START 2021-10-07 upseek
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
//@## ADD END 2021-10-07 upseek
//@## ADD START 2024-07-17 upseek
use Eccube\Form\Validator\RecaptchaV3;
//@## ADD END 2024-07-17 upseek
class ContactType extends AbstractType
{
/**
* @var EccubeConfig
*/
protected $eccubeConfig;
/**
* ContactType constructor.
*
* @param EccubeConfig $eccubeConfig
*/
public function __construct(EccubeConfig $eccubeConfig)
{
$this->eccubeConfig = $eccubeConfig;
}
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('name', NameType::class, [
'required' => true,
])
->add('kana', KanaType::class, [
'required' => false,
])
->add('postal_code', PostalType::class, [
'required' => false,
])
->add('address', AddressType::class, [
'required' => false,
])
->add('phone_number', PhoneNumberType::class, [
'required' => false,
])
//@##ADD START 2023-10-23 upseek
->add('company_name', TextType::class, [
'required' => false,
'constraints' => [
new Assert\Length([
'max' => $this->eccubeConfig['eccube_stext_len'],
]),
],
])
//@##ADD END
->add('email', EmailType::class, [
'constraints' => [
new Assert\NotBlank(),
new Email(null, null, $this->eccubeConfig['eccube_rfc_email_check'] ? 'strict' : null),
],
])
->add('contents', TextareaType::class, [
'constraints' => [
new Assert\NotBlank(),
new Assert\Length([
'max' => $this->eccubeConfig['eccube_lltext_len'],
])
],
]);
//@## ADD START 2021-10-07 upseek
$builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
$data = $event->getData();
if(!empty($data['product_id'])) {
$form = $event->getForm();
$form->add('product_name', TextType::class, [
'required' => true,
'mapped' => true,
]);
}
$form = $event->getForm();
});
//@## ADD END 2021-10-07 upseek
//@## ADD START 2024-07-17 upseek
$builder->add('recaptcha_response', TextType::class, [
'constraints' => [
new Assert\NotBlank(),
new RecaptchaV3($this->eccubeConfig['recaptcha_v3_secretkey'],$this->eccubeConfig['recaptcha_v3_score_threshold']),
],
]);
//@## ADD END 2024-07-17 upseek
}
/**
* {@inheritdoc}
*/
public function getBlockPrefix()
{
return 'contact';
}
}