<?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\SearchType;
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\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\EntityManagerInterface;
class FrontPostSearchType 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('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('keyword', SearchType::class, array(
'label' => 'キーワード',
'required' => false,
'constraints' => array(
new Assert\Length(array(
'max' => 255
))
)
))
->add('search', SubmitType::class, [
'label' => '検索'
]);
}
/**
*
* {@inheritdoc}
*/
public function getBlockPrefix()
{
return '';
}
}