app/Customize/Form/Type/BankInfoType.php line 26

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 Customize\Form\Type;
  13. use Eccube\Common\EccubeConfig;
  14. use Customize\Form\Type\Master\BankType;
  15. use Symfony\Component\Form\AbstractType;
  16. use Symfony\Component\Form\Extension\Core\Type\TextType;
  17. use Symfony\Component\Form\FormBuilderInterface;
  18. use Symfony\Component\Form\FormInterface;
  19. use Symfony\Component\Form\FormView;
  20. use Symfony\Component\OptionsResolver\OptionsResolver;
  21. use Symfony\Component\Validator\Constraints as Assert;
  22. class BankInfoType extends AbstractType
  23. {
  24.     /**
  25.      * @var array
  26.      */
  27.     protected $config;
  28.     /**
  29.      * {@inheritdoc}
  30.      *
  31.      * BankType constructor.
  32.      *
  33.      * @param EccubeConfig $eccubeConfig
  34.      */
  35.     public function __construct(EccubeConfig $eccubeConfig)
  36.     {
  37.         $this->config $eccubeConfig;
  38.     }
  39.     /**
  40.      * {@inheritdoc}
  41.      */
  42.     public function buildForm(FormBuilderInterface $builder, array $options)
  43.     {
  44.         $options['bank_name_options']['required'] = $options['required'];
  45.         // required の場合は NotBlank も追加する
  46.         if ($options['required']) {
  47.             $options['bank_name_options']['constraints'] = array_merge([
  48.                 new Assert\NotBlank([]),
  49.             ], $options['bank_name_options']['constraints']);
  50.         }
  51.         if (!isset($options['options']['error_bubbling'])) {
  52.             $options['options']['error_bubbling'] = $options['error_bubbling'];
  53.         }
  54.         $builder
  55.             ->add($options['bank_name_name'], BankType::class, array_merge_recursive($options['options'], $options['bank_name_options']))
  56.         ;
  57.         $builder->setAttribute('bank_name_name'$options['bank_name_name']);
  58.     }
  59.     /**
  60.      * {@inheritdoc}
  61.      */
  62.     public function buildView(FormView $viewFormInterface $form, array $options)
  63.     {
  64.         $builder $form->getConfig();
  65.         $view->vars['bank_name_name'] = $builder->getAttribute('bank_name_name');
  66.     }
  67.     /**
  68.      * {@inheritdoc}
  69.      */
  70.     public function configureOptions(OptionsResolver $resolver)
  71.     {
  72.         $resolver->setDefaults([
  73.             'options' => [],
  74.             'bank_name_options' => [
  75.                 'constraints' => [],
  76.                 'attr' => [
  77.                     'class' => 'p-bank-name',
  78.                     'placeholder' => 'common.bank_name',
  79.                 ],
  80.             ],
  81.             'bank_name_name' => 'bank_name',
  82.             'error_bubbling' => false,
  83.             'inherit_data' => true,
  84.             'trim' => true,
  85.         ]);
  86.     }
  87.     public function getBlockPrefix()
  88.     {
  89.         return 'bank';
  90.     }
  91. }