app/Customize/Form/Type/KanaType.php line 10

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