src/Eccube/Form/Type/Master/ProductListMaxType.php line 24

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\Master;
  13. use Eccube\Entity\Master\ProductListMax;
  14. use Eccube\Form\Type\MasterType;
  15. use Symfony\Component\Form\AbstractType;
  16. use Symfony\Component\Form\FormBuilderInterface;
  17. use Symfony\Component\Form\FormEvent;
  18. use Symfony\Component\Form\FormEvents;
  19. use Symfony\Component\OptionsResolver\OptionsResolver;
  20. class ProductListMaxType extends AbstractType
  21. {
  22.     /**
  23.      * {@inheritdoc}
  24.      */
  25.     public function buildForm(FormBuilderInterface $builder, array $options)
  26.     {
  27.         $builder->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) {
  28.             $options $event->getForm()->getConfig()->getOptions();
  29.             if ($event->getData() === null) {
  30.                 $event->setData((string) $options['choices'][0]->getId());
  31.             }
  32.         });
  33.     }
  34.     /**
  35.      * {@inheritdoc}
  36.      */
  37.     public function configureOptions(OptionsResolver $resolver)
  38.     {
  39.         $resolver->setDefaults([
  40.             'class' => ProductListMax::class,
  41.         ]);
  42.     }
  43.     /**
  44.      * {@inheritdoc}
  45.      */
  46.     public function getBlockPrefix()
  47.     {
  48.         return 'product_list_max';
  49.     }
  50.     /**
  51.      * {@inheritdoc}
  52.      */
  53.     public function getParent()
  54.     {
  55.         return MasterType::class;
  56.     }
  57. }