src/Eccube/Form/Type/SearchProductType.php line 29

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 Doctrine\ORM\EntityManagerInterface;
  14. use Eccube\Entity\Master\ProductListMax;
  15. use Eccube\Entity\Master\ProductListOrderBy;
  16. use Eccube\Form\Type\Master\ProductListMaxType;
  17. use Eccube\Form\Type\Master\ProductListOrderByType;
  18. use Eccube\Repository\CategoryRepository;
  19. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  20. use Symfony\Component\Form\AbstractType;
  21. use Symfony\Component\Form\Extension\Core\Type\HiddenType;
  22. use Symfony\Component\Form\Extension\Core\Type\SearchType;
  23. use Symfony\Component\Form\FormBuilderInterface;
  24. use Symfony\Component\OptionsResolver\OptionsResolver;
  25. class SearchProductType extends AbstractType
  26. {
  27.     /**
  28.      * @var CategoryRepository
  29.      */
  30.     protected $categoryRepository;
  31.     /**
  32.      * @var EntityManagerInterface
  33.      */
  34.     protected $entityManager;
  35.     /**
  36.      * SearchProductType constructor.
  37.      *
  38.      * @param CategoryRepository $categoryRepository
  39.      */
  40.     public function __construct(CategoryRepository $categoryRepositoryEntityManagerInterface $entityManager)
  41.     {
  42.         $this->categoryRepository $categoryRepository;
  43.         $this->entityManager $entityManager;
  44.     }
  45.     /**
  46.      * {@inheritdoc}
  47.      */
  48.     public function buildForm(FormBuilderInterface $builder, array $options)
  49.     {
  50.         $Categories $this->categoryRepository
  51.             ->getList(nulltrue);
  52.         $builder->add('mode'HiddenType::class, [
  53.             'data' => 'search',
  54.         ]);
  55.         $builder->add('category_id'EntityType::class, [
  56.             'class' => 'Eccube\Entity\Category',
  57.             'choice_label' => 'NameWithLevel',
  58.             'choices' => $Categories,
  59.             'placeholder' => 'common.select__all_products',
  60.             'required' => false,
  61.         ]);
  62.         $builder->add('name'SearchType::class, [
  63.             'required' => false,
  64.             'attr' => [
  65.                 'maxlength' => 50,
  66.             ],
  67.         ]);
  68.         $builder->add('pageno'HiddenType::class, []);
  69.         $builder->add('disp_number'ProductListMaxType::class, [
  70.             'label' => false,
  71.             'choices' => $this->entityManager->getRepository(ProductListMax::class)->findBy([], ['sort_no' => 'ASC']),
  72.         ]);
  73.         $builder->add('orderby'ProductListOrderByType::class, [
  74.             'label' => false,
  75.             'choices' => $this->entityManager->getRepository(ProductListOrderBy::class)->findBy([], ['sort_no' => 'ASC']),
  76.         ]);
  77.     }
  78.     /**
  79.      * {@inheritdoc}
  80.      */
  81.     public function configureOptions(OptionsResolver $resolver)
  82.     {
  83.         $resolver->setDefaults([
  84.             'csrf_protection' => false,
  85.             'allow_extra_fields' => true,
  86.         ]);
  87.     }
  88.     /**
  89.      * {@inheritdoc}
  90.      */
  91.     public function getBlockPrefix()
  92.     {
  93.         return 'search_product';
  94.     }
  95. }