app/Plugin/TabaCMS2/Form/Type/FrontPostSearchType.php line 29

Open in your IDE?
  1. <?php
  2. /*
  3.  * Copyright (C) SPREAD WORKS Inc. All Rights Reserved.
  4.  *
  5.  * For the full copyright and license information, please view the LICENSE
  6.  * file that was distributed with this source code.
  7.  */
  8. namespace Plugin\TabaCMS2\Form\Type;
  9. use Plugin\TabaCMS2\Common\Constants;
  10. use Plugin\TabaCMS2\Entity\Post;
  11. use Plugin\TabaCMS2\Util\Validator;
  12. use Eccube\Common\EccubeConfig;
  13. use Symfony\Component\Form\AbstractType;
  14. use Symfony\Component\Form\FormBuilderInterface;
  15. use Symfony\Component\Validator\Constraints as Assert;
  16. use Symfony\Component\Form\Extension\Core\Type\TextType;
  17. use Symfony\Component\Form\Extension\Core\Type\SearchType;
  18. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  19. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  20. use Symfony\Component\Form\Extension\Core\Type\DateType;
  21. use Symfony\Component\Form\Extension\Core\Type\FileType;
  22. use Symfony\Component\Form\Extension\Core\Type\HiddenType;
  23. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  24. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  25. use Doctrine\ORM\EntityRepository;
  26. use Doctrine\ORM\EntityManagerInterface;
  27. class FrontPostSearchType extends AbstractType
  28. {
  29.     /**
  30.      *
  31.      * @var EntityManagerInterface
  32.      */
  33.     protected $entityManager;
  34.     /**
  35.      *
  36.      * @var array
  37.      */
  38.     private $eccubeConfig;
  39.     /**
  40.      *
  41.      * @param EccubeConfig $eccubeConfig
  42.      */
  43.     public function __construct(EntityManagerInterface $entityManagerEccubeConfig $eccubeConfig)
  44.     {
  45.         $this->entityManager $entityManager;
  46.         $this->eccubeConfig $eccubeConfig;
  47.     }
  48.     /**
  49.      *
  50.      * @param FormBuilderInterface $builder
  51.      * @param array $options
  52.      */
  53.     public function buildForm(FormBuilderInterface $builder, array $options)
  54.     {
  55.         $data $options['data'];
  56.         $builder->setMethod('GET');
  57.         $builder->add('category_id'EntityType::class, array(
  58.             'label' => 'カテゴリー',
  59.             'required' => false,
  60.             'class' => Constants::$ENTITY['CATEGORY'],
  61.             'placeholder' => '選択してください',
  62.             'empty_data' => null,
  63.             'constraints' => array(),
  64.             'query_builder' => function (EntityRepository $er) use ($data) {
  65.                 return $er->createQueryBuilder('c')
  66.                     ->where('c.typeId = :typeId')
  67.                     ->setParameter('typeId'$data['type_id'])
  68.                     ->orderBy('c.orderNo''ASC');
  69.             }
  70.         ))
  71.         ->add('keyword'SearchType::class, array(
  72.             'label' => 'キーワード',
  73.             'required' => false,
  74.             'constraints' => array(
  75.                 new Assert\Length(array(
  76.                     'max' => 255
  77.                 ))
  78.             )
  79.         ))
  80.         ->add('search'SubmitType::class, [
  81.             'label' => '検索'
  82.         ]);
  83.     }
  84.     /**
  85.      *
  86.      * {@inheritdoc}
  87.      */
  88.     public function getBlockPrefix()
  89.     {
  90.         return '';
  91.     }
  92. }