src/Eccube/Form/Type/KanaType.php line 22

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;
  13. use Eccube\Common\EccubeConfig;
  14. use Symfony\Component\Form\AbstractType;
  15. use Symfony\Component\Form\FormBuilderInterface;
  16. use Symfony\Component\OptionsResolver\OptionsResolver;
  17. use Symfony\Component\Validator\Constraints as Assert;
  18. class KanaType extends AbstractType
  19. {
  20.     /**
  21.      * @var \Eccube\Common\EccubeConfig
  22.      */
  23.     protected $eccubeConfig;
  24.     /**
  25.      * KanaType constructor.
  26.      *
  27.      * @param EccubeConfig $eccubeConfig
  28.      */
  29.     public function __construct(EccubeConfig $eccubeConfig)
  30.     {
  31.         $this->eccubeConfig $eccubeConfig;
  32.     }
  33.     /**
  34.      * {@inheritdoc}
  35.      */
  36.     public function buildForm(FormBuilderInterface $builder, array $options)
  37.     {
  38.         // ひらがなをカタカナに変換する
  39.         // 引数はmb_convert_kanaのもの
  40.         $builder->addEventSubscriber(new \Eccube\Form\EventListener\ConvertKanaListener('CV'));
  41.     }
  42.     /**
  43.      * {@inheritdoc}
  44.      */
  45.     public function configureOptions(OptionsResolver $resolver)
  46.     {
  47.         $resolver->setDefaults([
  48.             'lastname_options' => [
  49.                 'attr' => [
  50.                     'placeholder' => 'common.last_name_kana',
  51.                 ],
  52.                 'constraints' => [
  53.                     new Assert\Regex([
  54. /*▼RZ 2024.11.27 EDIT 名前にスペースを入力されるのを許可する▼*/
  55. /*
  56.                         'pattern' => '/^[ァ-ヶヲ-゚ー]+$/u',
  57. */
  58.                         'pattern' => '/^[ァ-ヶヲ-゚ー  ]+$/u',
  59. /*▲RZ 2024.11.27 EDIT 名前にスペースを入力されるのを許可する▲*/
  60.                         'message' => 'form_error.kana_only',
  61.                     ]),
  62.                     new Assert\Length([
  63.                         'max' => $this->eccubeConfig['eccube_kana_len'],
  64.                     ]),
  65.                 ],
  66.             ],
  67.             'firstname_options' => [
  68.                 'attr' => [
  69.                     'placeholder' => 'common.first_name_kana',
  70.                 ],
  71.                 'constraints' => [
  72.                     new Assert\Regex([
  73. /*▼RZ 2024.11.27 EDIT 名前にスペースを入力されるのを許可する▼*/
  74. /*
  75.                         'pattern' => '/^[ァ-ヶヲ-゚ー]+$/u',
  76. */
  77.                         'pattern' => '/^[ァ-ヶヲ-゚ー  ]+$/u',
  78. /*▲RZ 2024.11.27 EDIT 名前にスペースを入力されるのを許可する▲*/
  79.                         'message' => 'form_error.kana_only',
  80.                     ]),
  81.                     new Assert\Length([
  82.                         'max' => $this->eccubeConfig['eccube_kana_len'],
  83.                     ]),
  84.                 ],
  85.             ],
  86.         ]);
  87.     }
  88.     /**
  89.      * {@inheritdoc}
  90.      */
  91.     public function getParent()
  92.     {
  93.         return NameType::class;
  94.     }
  95.     /**
  96.      * {@inheritdoc}
  97.      */
  98.     public function getBlockPrefix()
  99.     {
  100.         return 'kana';
  101.     }
  102. }