app/Plugin/Paid4/Form/Type/PaidNameKanaType.php line 16

Open in your IDE?
  1. <?php
  2. /*
  3.  * Copyright(c) 2020 RACCOON HOLDINGS, Inc. All rights reserved.
  4.  * https://paid.jp/
  5.  */
  6. namespace Plugin\Paid4\Form\Type;
  7. use Eccube\Common\EccubeConfig;
  8. use Symfony\Component\Form\AbstractType;
  9. use Symfony\Component\Form\FormBuilderInterface;
  10. use Symfony\Component\OptionsResolver\OptionsResolver;
  11. use Symfony\Component\Validator\Constraints as Assert;
  12. class PaidNameKanaType extends AbstractType
  13. {
  14.     /**
  15.      * @var \Eccube\Common\EccubeConfig
  16.      */
  17.     protected $eccubeConfig;
  18.     /**
  19.      * KanaType constructor.
  20.      *
  21.      * @param EccubeConfig $eccubeConfig
  22.      */
  23.     public function __construct(EccubeConfig $eccubeConfig)
  24.     {
  25.         $this->eccubeConfig $eccubeConfig;
  26.     }
  27.     /**
  28.      * @param FormBuilderInterface $builder
  29.      * @param array $options
  30.      */
  31.     public function buildForm(FormBuilderInterface $builder, array $options)
  32.     {
  33.         // ひらがなをカタカナに変換する
  34.         // 引数はmb_convert_kanaのもの
  35.         $builder->addEventSubscriber(new \Plugin\Paid4\Form\EventListener\ConvertKanaListener('CV'));
  36.     }
  37.     /**
  38.      * @param OptionsResolver $resolver
  39.      */
  40.     public function configureOptions(OptionsResolver $resolver)
  41.     {
  42.         $resolver->setDefaults([
  43.             'lastname_options' => [
  44.                 'attr' => [
  45.                     'placeholder' => 'common.last_name_kana',
  46.                 ],
  47.                 'constraints' => [
  48.                     new Assert\Regex([
  49.                         'pattern' => '/^[ァ-ヶヲ-゚ー]+$/u',
  50.                         'message' => 'form_error.kana_only',
  51.                     ]),
  52.                     new Assert\Length([
  53.                         'max' => $this->eccubeConfig['paid4.stext_len'],
  54.                     ]),
  55.                 ],
  56.             ],
  57.             'firstname_options' => [
  58.                 'attr' => [
  59.                     'placeholder' => 'common.first_name_kana',
  60.                 ],
  61.                 'constraints' => [
  62.                     new Assert\Regex([
  63.                         'pattern' => '/^[ァ-ヶヲ-゚ー]+$/u',
  64.                         'message' => 'form_error.kana_only',
  65.                     ]),
  66.                     new Assert\Length([
  67.                         'max' => $this->eccubeConfig['paid4.stext_len'],
  68.                     ]),
  69.                 ],
  70.             ],
  71.         ]);
  72.     }
  73.     /**
  74.      * {@inheritdoc}
  75.      */
  76.     public function getParent()
  77.     {
  78.         return PaidNameType::class;
  79.     }
  80.     /**
  81.      * {@inheritdoc}
  82.      */
  83.     public function getBlockPrefix()
  84.     {
  85.         return 'kana';
  86.     }
  87. }