<?php
/*
* Copyright (C) SPREAD WORKS Inc. All Rights Reserved.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Plugin\TabaCMS2\Form\Type;
use Plugin\TabaCMS2\Common\Constants;
use Plugin\TabaCMS2\Entity\Post;
use Plugin\TabaCMS2\Util\Validator;
use Eccube\Common\EccubeConfig;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Symfony\Component\Form\Extension\Core\Type\FileType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\EntityManagerInterface;
class PostSearchType extends AbstractType
{
/**
*
* @var EntityManagerInterface
*/
protected $entityManager;
/**
*
* @var array
*/
private $eccubeConfig;
/**
*
* @param EccubeConfig $eccubeConfig
*/
public function __construct(EntityManagerInterface $entityManager, EccubeConfig $eccubeConfig)
{
$this->entityManager = $entityManager;
$this->eccubeConfig = $eccubeConfig;
}
/**
*
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$data = $options['data'];
$builder->setMethod('GET');
$builder
->add('type_id', HiddenType::class, array(
'label' => '投稿タイプID',
'required' => true,
'constraints' => array()
))
->add('category_id', EntityType::class, array(
'label' => 'カテゴリー',
'required' => false,
'class' => Constants::$ENTITY['CATEGORY'],
'placeholder' => '選択してください',
'empty_data' => null,
'constraints' => array(),
'query_builder' => function (EntityRepository $er) use ($data) {
return $er->createQueryBuilder('c')
->where('c.typeId = :typeId')
->setParameter('typeId', $data['type_id'])
->orderBy('c.orderNo', 'ASC');
}
))
->add('public_div', ChoiceType::class, array(
'label' => '公開区分',
'required' => false,
'choices' => array_merge(['すべて' => ''],Post::$PUBLIC_DIV_ARRAY),
'multiple' => false,
'expanded' => true
))
->add('priority_flg', ChoiceType::class, array(
'label' => '固定表示',
'required' => false,
'choices' => Post::$PRIORITY_FLG_ARRAY,
'multiple' => false,
'expanded' => true
))
->add('content_div', ChoiceType::class, array(
'label' => '投稿内容区分',
'required' => false,
'choices' => Post::$CONTENT_DIV_ARRAY,
'multiple' => false,
'expanded' => true
))
->add('keyword', TextType::class, array(
'label' => 'キーワード',
'required' => false,
'constraints' => array(
new Assert\Length(array(
'max' => 255
))
)
))
->add('memo', TextareaType::class, array(
'label' => 'メモ',
'required' => false,
'help' => 'メモを残すことができます。',
'constraints' => array(
new Assert\Length(array(
'max' => $this->eccubeConfig['eccube_ltext_len']
))
)
));
}
/**
*
* {@inheritdoc}
*/
public function getBlockPrefix()
{
return '';
}
}