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

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.                         'pattern' => '/^[ァ-ヶヲ-゚ー]+$/u',
  55.                         'message' => 'form_error.kana_only',
  56.                     ]),
  57.                     new Assert\Length([
  58.                         'max' => $this->eccubeConfig['eccube_kana_len'],
  59.                     ]),
  60.                 ],
  61.             ],
  62.             'firstname_options' => [
  63.                 'attr' => [
  64.                     'placeholder' => 'common.first_name_kana',
  65.                 ],
  66.                 'constraints' => [
  67.                     new Assert\Regex([
  68.                         'pattern' => '/^[ァ-ヶヲ-゚ー]+$/u',
  69.                         'message' => 'form_error.kana_only',
  70.                     ]),
  71.                     new Assert\Length([
  72.                         'max' => $this->eccubeConfig['eccube_kana_len'],
  73.                     ]),
  74.                 ],
  75.             ],
  76.         ]);
  77.     }
  78.     /**
  79.      * {@inheritdoc}
  80.      */
  81.     public function getParent()
  82.     {
  83.         return NameType::class;
  84.     }
  85.     /**
  86.      * {@inheritdoc}
  87.      */
  88.     public function getBlockPrefix()
  89.     {
  90.         return 'kana';
  91.     }
  92. }