app/Plugin/SearchPlus42/Form/Extension/SearchProductBlockExtension.php line 75

Open in your IDE?
  1. <?php
  2. /*
  3. * Plugin Name : SearchPlus
  4. *
  5. * Copyright (C) BraTech Co., Ltd. All Rights Reserved.
  6. * http://www.bratech.co.jp/
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace Plugin\SearchPlus42\Form\Extension;
  12. use Doctrine\ORM\EntityManagerInterface;
  13. use Eccube\Form\Type\SearchProductBlockType;
  14. use Plugin\SearchPlus42\Service\SearchPlusService;
  15. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  16. use Symfony\Component\Form\AbstractTypeExtension;
  17. use Symfony\Component\Form\Extension\Core\Type;
  18. use Symfony\Component\Form\FormBuilderInterface;
  19. class SearchProductBlockExtension extends AbstractTypeExtension
  20. {
  21.     private $entityManager;
  22.     private $searchPlusService;
  23.     public function __construct(
  24.             EntityManagerInterface $entityManager,
  25.             SearchPlusService $searchPlusService
  26.             )
  27.     {
  28.         $this->entityManager $entityManager;
  29.         $this->searchPlusService $searchPlusService;
  30.     }
  31.     public function buildForm(FormBuilderInterface $builder, array $options)
  32.     {
  33.         if($this->searchPlusService->checkInstallPlugin('ProductPlus42')){
  34.             $productItemRepository $this->entityManager->getRepository('Plugin\ProductPlus42\Entity\ProductItem');
  35.             $ProductItems $productItemRepository->findAll();
  36.             $builder $this->searchPlusService->createBuilder($builder$ProductItems);
  37.         }
  38.         if(method_exists('Eccube\Entity\Product','getMaker')){
  39.             $builder
  40.                   ->add('maker_id',EntityType::class, [
  41.                         'class' => 'Plugin\Maker42\Entity\Maker',
  42.                         'query_builder' => function ($er) {
  43.                             return $er->createQueryBuilder('m')
  44.                             ->orderBy('m.sort_no''DESC');
  45.                         },
  46.                         'choice_label' => 'name',
  47.                         'label' => trans('maker.admin.maker'),
  48.                         'multiple' => true,
  49.                         'expanded' => true,
  50.                         'required' => false,
  51.                         'mapped' => false,
  52.                         'placeholder' => 'common.select__all_makers',
  53.             ]);
  54.         }
  55.         $builder
  56.                 ->add('pmin'Type\NumberType::class, [
  57.                     'required' => false,
  58.                     ])
  59.                 ->add('pmax'Type\NumberType::class, [
  60.                     'required' => false,
  61.                     ])
  62.                 ->add('instock'Type\CheckboxType::class, [
  63.                     'label' => trans('searchplus.block.label.instock'),
  64.                     'required' => false,
  65.                     ])
  66.                 ->add('tag_id'EntityType::class, [
  67.                     'class' => 'Eccube\Entity\Tag',
  68.                     'query_builder' => function ($er) {
  69.                         return $er->createQueryBuilder('t')
  70.                         ->orderBy('t.sort_no''DESC');
  71.                     },
  72.                     'label' => trans('admin.product.tag'),
  73.                     'multiple' => true,
  74.                     'expanded' => true,
  75.                     'required' => false,
  76.                     'mapped' => false,
  77.                     ]);
  78.     }
  79.     public static function getExtendedTypes(): iterable
  80.     {
  81.         return [SearchProductBlockType::class];
  82.     }
  83. }