app/Plugin/TabaCMS2/Form/Type/PostSearchType.php line 27

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\TextareaType;
  18. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  19. use Symfony\Component\Form\Extension\Core\Type\DateType;
  20. use Symfony\Component\Form\Extension\Core\Type\FileType;
  21. use Symfony\Component\Form\Extension\Core\Type\HiddenType;
  22. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  23. use Doctrine\ORM\EntityRepository;
  24. use Doctrine\ORM\EntityManagerInterface;
  25. class PostSearchType extends AbstractType
  26. {
  27.     /**
  28.      *
  29.      * @var EntityManagerInterface
  30.      */
  31.     protected $entityManager;
  32.     /**
  33.      *
  34.      * @var array
  35.      */
  36.     private $eccubeConfig;
  37.     /**
  38.      *
  39.      * @param EccubeConfig $eccubeConfig
  40.      */
  41.     public function __construct(EntityManagerInterface $entityManagerEccubeConfig $eccubeConfig)
  42.     {
  43.         $this->entityManager $entityManager;
  44.         $this->eccubeConfig $eccubeConfig;
  45.     }
  46.     /**
  47.      *
  48.      * @param FormBuilderInterface $builder
  49.      * @param array $options
  50.      */
  51.     public function buildForm(FormBuilderInterface $builder, array $options)
  52.     {
  53.         $data $options['data'];
  54.         $builder->setMethod('GET');
  55.         $builder
  56.         ->add('type_id'HiddenType::class, array(
  57.             'label' => '投稿タイプID',
  58.             'required' => true,
  59.             'constraints' => array()
  60.         ))
  61.         ->add('category_id'EntityType::class, array(
  62.             'label' => 'カテゴリー',
  63.             'required' => false,
  64.             'class' => Constants::$ENTITY['CATEGORY'],
  65.             'placeholder' => '選択してください',
  66.             'empty_data' => null,
  67.             'constraints' => array(),
  68.             'query_builder' => function (EntityRepository $er) use ($data) {
  69.                 return $er->createQueryBuilder('c')
  70.                     ->where('c.typeId = :typeId')
  71.                     ->setParameter('typeId'$data['type_id'])
  72.                     ->orderBy('c.orderNo''ASC');
  73.             }
  74.         ))
  75.         ->add('public_div'ChoiceType::class, array(
  76.             'label' => '公開区分',
  77.             'required' => false,
  78.             'choices' => array_merge(['すべて' => ''],Post::$PUBLIC_DIV_ARRAY),
  79.             'multiple' => false,
  80.             'expanded' => true
  81.         ))
  82.         ->add('priority_flg'ChoiceType::class, array(
  83.             'label' => '固定表示',
  84.             'required' => false,
  85.             'choices' => Post::$PRIORITY_FLG_ARRAY,
  86.             'multiple' => false,
  87.             'expanded' => true
  88.         ))
  89.         ->add('content_div'ChoiceType::class, array(
  90.             'label' => '投稿内容区分',
  91.             'required' => false,
  92.             'choices' => Post::$CONTENT_DIV_ARRAY,
  93.             'multiple' => false,
  94.             'expanded' => true
  95.         ))
  96.         ->add('keyword'TextType::class, array(
  97.             'label' => 'キーワード',
  98.             'required' => false,
  99.             'constraints' => array(
  100.                 new Assert\Length(array(
  101.                     'max' => 255
  102.                 ))
  103.             )
  104.         ))
  105.         ->add('memo'TextareaType::class, array(
  106.             'label' => 'メモ',
  107.             'required' => false,
  108.             'help' => 'メモを残すことができます。',
  109.             'constraints' => array(
  110.                 new Assert\Length(array(
  111.                     'max' => $this->eccubeConfig['eccube_ltext_len']
  112.                 ))
  113.             )
  114.         ));
  115.     }
  116.     /**
  117.      *
  118.      * {@inheritdoc}
  119.      */
  120.     public function getBlockPrefix()
  121.     {
  122.         return '';
  123.     }
  124. }