<?php
namespace Plugin\Blogs42\Form\Type\Admin;
use Eccube\Common\EccubeConfig;
use Plugin\Blogs42\Entity\Category;
use Plugin\Blogs42\Repository\CategoryRepository;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\FileType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormError;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints as Assert;
use Plugin\Blogs42\Entity\Blogs;
/**
* Class BlogsType.
*/
class BlogsType extends AbstractType
{
/**
* @var CategoryRepository
*/
protected $categoryRepository;
/**
* @var EccubeConfig
*/
protected $eccubeConfig;
/**
* BlogsType constructor.
*
* @param CategoryRepository $categoryRepository
* @param EccubeConfig $eccubeConfig
*/
public function __construct(
CategoryRepository $categoryRepository,
EccubeConfig $eccubeConfig
) {
$this->categoryRepository = $categoryRepository;
$this->eccubeConfig = $eccubeConfig;
}
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('publish_date', DateTimeType::class, [
'widget' => 'single_text',
'input' => 'datetime',
'years' => range($this->eccubeConfig['eccube_news_start_year'], date('Y') + 3),
'with_seconds' => true,
'constraints' => [
new Assert\NotBlank(),
new Assert\Range([
'min'=> '0003-01-01',
'minMessage' => 'form_error.out_of_range',
]),
],
])
->add('title', TextType::class, [
'required' => true,
'constraints' => [
new Assert\NotBlank(),
new Assert\Length(['max' => $this->eccubeConfig['eccube_mtext_len']]),
],
])
->add('url', TextType::class, [
'required' => false,
'constraints' => [
new Assert\Url(),
new Assert\Length(['max' => $this->eccubeConfig['eccube_mtext_len']]),
],
])
->add('link_method', CheckboxType::class, [
'required' => false,
'label' => 'admin.content.blogs.new_window',
'value' => '1',
])
->add('blog_description', TextareaType::class, [
'required' => false,
'purify_html' => true,
'attr' => [
'rows' => 8,
],
'constraints' => [
new Assert\Length(['max' => $this->eccubeConfig['eccube_lltext_len']]),
],
])
->add('visible', ChoiceType::class, [
'label' => false,
'choices' => ['admin.content.blogs.display_status__show' => true, 'admin.content.blogs.display_status__hide' => false],
'required' => true,
'expanded' => false,
])
->add('eyecatch_file', FileType::class, [
'label' => 'アイキャッチ画像',
'mapped' => false,
'required' => false,
])
->add('eyecatch_image', HiddenType::class, [
'required' => false,
])
->add('Category', ChoiceType::class, [
'choice_label' => 'Name',
'multiple' => true,
'mapped' => false,
'expanded' => true,
'choices' => $this->categoryRepository->getList(null, true),
'choice_value' => function (Category $Category = null) {
return $Category ? $Category->getId() : null;
},
])
->add('author', TextType::class, [
'required' => false,
'constraints' => [
new Assert\Length([
'max' => $this->eccubeConfig['eccube_stext_len'],
]),
],
])
->add('description', TextType::class, [
'required' => false,
'constraints' => [
new Assert\Length([
'max' => $this->eccubeConfig['eccube_stext_len'],
]),
],
])
->add('keyword', TextType::class, [
'required' => false,
'constraints' => [
new Assert\Length([
'max' => $this->eccubeConfig['eccube_stext_len'],
]),
],
])
->add('meta_robots', TextType::class, [
'required' => false,
'constraints' => [
new Assert\Length([
'max' => $this->eccubeConfig['eccube_stext_len'],
]),
],
])
->add('meta_tags', TextAreaType::class, [
'required' => false,
'constraints' => [
new Assert\Length([
'max' => $this->eccubeConfig['eccube_ltext_len'],
]),
],
])
;
}
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
}
/**
* {@inheritdoc}
*/
public function getBlockPrefix()
{
return 'plugin_blogs';
}
}