src/Eccube/Form/Type/Front/ContactType.php line 37

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of EC-CUBE
  4.  *
  5.  * Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
  6.  *
  7.  * http://www.ec-cube.co.jp/
  8.  *
  9.  * For the full copyright and license information, please view the LICENSE
  10.  * file that was distributed with this source code.
  11.  */
  12. namespace Eccube\Form\Type\Front;
  13. use Eccube\Common\EccubeConfig;
  14. use Eccube\Form\Type\AddressType;
  15. use Eccube\Form\Type\KanaType;
  16. use Eccube\Form\Type\NameType;
  17. use Eccube\Form\Type\PhoneNumberType;
  18. use Eccube\Form\Type\PostalType;
  19. use Eccube\Form\Validator\Email;
  20. use Symfony\Component\Form\AbstractType;
  21. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  22. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  23. use Symfony\Component\Form\FormBuilderInterface;
  24. use Symfony\Component\Validator\Constraints as Assert;
  25. //@## ADD START 2021-10-07 upseek
  26. use Symfony\Component\Form\Extension\Core\Type\TextType;
  27. use Symfony\Component\Form\FormEvent;
  28. use Symfony\Component\Form\FormEvents;
  29. //@## ADD END 2021-10-07 upseek
  30. //@## ADD START 2024-07-17 upseek
  31. use Eccube\Form\Validator\RecaptchaV3;
  32. //@## ADD END 2024-07-17 upseek
  33. class ContactType extends AbstractType
  34. {
  35.     /**
  36.      * @var EccubeConfig
  37.      */
  38.     protected $eccubeConfig;
  39.     /**
  40.      * ContactType constructor.
  41.      *
  42.      * @param EccubeConfig $eccubeConfig
  43.      */
  44.     public function __construct(EccubeConfig $eccubeConfig)
  45.     {
  46.         $this->eccubeConfig $eccubeConfig;
  47.     }
  48.     /**
  49.      * {@inheritdoc}
  50.      */
  51.     public function buildForm(FormBuilderInterface $builder, array $options)
  52.     {
  53.         $builder
  54.             ->add('name'NameType::class, [
  55.                 'required' => true,
  56.             ])
  57.             ->add('kana'KanaType::class, [
  58.                 'required' => false,
  59.             ])
  60.             ->add('postal_code'PostalType::class, [
  61.                 'required' => false,
  62.             ])
  63.             ->add('address'AddressType::class, [
  64.                 'required' => false,
  65.             ])
  66.             ->add('phone_number'PhoneNumberType::class, [
  67.                 'required' => false,
  68.             ])
  69. //@##ADD START 2023-10-23 upseek
  70.             ->add('company_name'TextType::class, [
  71.                 'required' => false,
  72.                 'constraints' => [
  73.                     new Assert\Length([
  74.                         'max' => $this->eccubeConfig['eccube_stext_len'],
  75.                     ]),
  76.                 ],
  77.             ])
  78. //@##ADD END
  79.             ->add('email'EmailType::class, [
  80.                 'constraints' => [
  81.                     new Assert\NotBlank(),
  82.                     new Email(nullnull$this->eccubeConfig['eccube_rfc_email_check'] ? 'strict' null),
  83.                 ],
  84.             ])
  85.             ->add('contents'TextareaType::class, [
  86.                 'constraints' => [
  87.                     new Assert\NotBlank(),
  88.                     new Assert\Length([
  89.                         'max' => $this->eccubeConfig['eccube_lltext_len'],
  90.                     ])
  91.                 ],
  92.             ]);
  93. //@## ADD START 2021-10-07 upseek
  94.         $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
  95.             $data $event->getData();
  96.             if(!empty($data['product_id'])) {
  97.                 $form $event->getForm();
  98.                 $form->add('product_name'TextType::class, [
  99.                     'required' => true,
  100.                     'mapped' => true,
  101.                 ]);
  102.             }
  103.             $form $event->getForm();
  104.         });
  105. //@## ADD END 2021-10-07 upseek
  106. //@## ADD START 2024-07-17 upseek
  107.         $builder->add('recaptcha_response'TextType::class, [
  108.             'constraints' => [
  109.                 new Assert\NotBlank(),
  110.                 new RecaptchaV3($this->eccubeConfig['recaptcha_v3_secretkey'],$this->eccubeConfig['recaptcha_v3_score_threshold']),
  111.             ],
  112.         ]);
  113. //@## ADD END 2024-07-17 upseek
  114.     }
  115.     /**
  116.      * {@inheritdoc}
  117.      */
  118.     public function getBlockPrefix()
  119.     {
  120.         return 'contact';
  121.     }
  122. }