app/Plugin/Paid4/Form/Type/PaidTextKanaType.php line 17

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\Extension\Core\Type\TextType;
  10. use Symfony\Component\Form\FormBuilderInterface;
  11. use Symfony\Component\OptionsResolver\OptionsResolver;
  12. use Symfony\Component\Validator\Constraints as Assert;
  13. class PaidTextKanaType extends AbstractType
  14. {
  15.     /**
  16.      * @var \Eccube\Common\EccubeConfig
  17.      */
  18.     protected $eccubeConfig;
  19.     /**
  20.      * KanaType constructor.
  21.      *
  22.      * @param EccubeConfig $eccubeConfig
  23.      */
  24.     public function __construct(EccubeConfig $eccubeConfig)
  25.     {
  26.         $this->eccubeConfig $eccubeConfig;
  27.     }
  28.     /**
  29.      * @param FormBuilderInterface $builder
  30.      * @param array $options
  31.      */
  32.     public function buildForm(FormBuilderInterface $builder, array $options)
  33.     {
  34.         // ひらがなをカタカナに変換する
  35.         // 引数はmb_convert_kanaのもの
  36.         $builder->addEventSubscriber(new \Eccube\Form\EventListener\ConvertKanaListener('CV'));
  37.     }
  38.     /**
  39.      * @param OptionsResolver $resolver
  40.      */
  41.     public function configureOptions(OptionsResolver $resolver)
  42.     {
  43.         $resolver->setDefaults([
  44.             'options' => [],
  45.             'attr' => [],
  46.             'constraints' => [
  47.                 new Assert\Regex([
  48.                     'pattern' => '/^[ァ-ヶヲ-゚ー]+$/u',
  49.                     'message' => 'form_error.kana_only',
  50.                 ]),
  51.                 new Assert\Length([
  52.                     'max' => $this->eccubeConfig['paid4.stext_len'],
  53.                 ]),
  54.             ],
  55.         ]);
  56.     }
  57.     /**
  58.      * {@inheritdoc}
  59.      */
  60.     public function getParent()
  61.     {
  62.         return TextType::class;
  63.     }
  64.     /**
  65.      * {@inheritdoc}
  66.      */
  67.     public function getBlockPrefix()
  68.     {
  69.         return 'kana';
  70.     }
  71. }