src/Eccube/Form/Type/SearchProductBlockType.php line 23

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;
  13. use Eccube\Repository\CategoryRepository;
  14. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  15. use Symfony\Component\Form\AbstractType;
  16. use Symfony\Component\Form\Extension\Core\Type\SearchType;
  17. use Symfony\Component\Form\FormBuilderInterface;
  18. use Symfony\Component\OptionsResolver\OptionsResolver;
  19. class SearchProductBlockType extends AbstractType
  20. {
  21.     /**
  22.      * @var CategoryRepository
  23.      */
  24.     protected $categoryRepository;
  25.     public function __construct(CategoryRepository $categoryRepository)
  26.     {
  27.         $this->categoryRepository $categoryRepository;
  28.     }
  29.     /**
  30.      * {@inheritdoc}
  31.      */
  32.     public function buildForm(FormBuilderInterface $builder, array $options)
  33.     {
  34.         $Categories $this->categoryRepository
  35.             ->getList(nulltrue);
  36.         $builder->add('category_id'EntityType::class, [
  37.             'class' => 'Eccube\Entity\Category',
  38.             'choice_label' => 'NameWithLevel',
  39.             'choices' => $Categories,
  40.             'placeholder' => 'common.select__all_products',
  41.             'required' => false,
  42.         ]);
  43.         $builder->add('name'SearchType::class, [
  44.             'required' => false,
  45.             'label' => 'common.search_keyword',
  46.             'attr' => [
  47.                 'maxlength' => 50,
  48.             ],
  49.         ]);
  50.     }
  51.     /**
  52.      * {@inheritdoc}
  53.      */
  54.     public function configureOptions(OptionsResolver $resolver)
  55.     {
  56.         $resolver->setDefaults([
  57.             'csrf_protection' => false,
  58.             'allow_extra_fields' => true,
  59.         ]);
  60.     }
  61.     /**
  62.      * {@inheritdoc}
  63.      */
  64.     public function getBlockPrefix()
  65.     {
  66.         return 'search_product_block';
  67.     }
  68. }