app/Plugin/Blogs42/Form/Type/Admin/BlogsType.php line 28

Open in your IDE?
  1. <?php
  2. namespace Plugin\Blogs42\Form\Type\Admin;
  3. use Eccube\Common\EccubeConfig;
  4. use Plugin\Blogs42\Entity\Category;
  5. use Plugin\Blogs42\Repository\CategoryRepository;
  6. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  7. use Symfony\Component\Form\AbstractType;
  8. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  9. use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
  10. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  11. use Symfony\Component\Form\Extension\Core\Type\FileType;
  12. use Symfony\Component\Form\Extension\Core\Type\HiddenType;
  13. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  14. use Symfony\Component\Form\Extension\Core\Type\TextType;
  15. use Symfony\Component\Form\FormBuilderInterface;
  16. use Symfony\Component\Form\FormError;
  17. use Symfony\Component\Form\FormEvent;
  18. use Symfony\Component\Form\FormEvents;
  19. use Symfony\Component\Form\FormInterface;
  20. use Symfony\Component\OptionsResolver\OptionsResolver;
  21. use Symfony\Component\Validator\Constraints as Assert;
  22. use Plugin\Blogs42\Entity\Blogs;
  23. /**
  24.  * Class BlogsType.
  25.  */
  26. class BlogsType extends AbstractType
  27. {
  28.     /**
  29.      * @var CategoryRepository
  30.      */
  31.     protected $categoryRepository;
  32.     /**
  33.      * @var EccubeConfig
  34.      */
  35.     protected $eccubeConfig;
  36.     /**
  37.      * BlogsType constructor.
  38.      *
  39.      * @param CategoryRepository $categoryRepository
  40.      * @param EccubeConfig $eccubeConfig
  41.      */
  42.     public function __construct(
  43.         CategoryRepository $categoryRepository,
  44.         EccubeConfig $eccubeConfig
  45.     ) {
  46.         $this->categoryRepository $categoryRepository;
  47.         $this->eccubeConfig $eccubeConfig;
  48.     }
  49.     /**
  50.      * {@inheritdoc}
  51.      */
  52.     public function buildForm(FormBuilderInterface $builder, array $options)
  53.     {
  54.         $builder
  55.             ->add('publish_date'DateTimeType::class, [
  56.                 'widget' => 'single_text',
  57.                 'input' => 'datetime',
  58.                 'years' => range($this->eccubeConfig['eccube_news_start_year'], date('Y') + 3),
  59.                 'with_seconds' => true,
  60.                 'constraints' => [
  61.                     new Assert\NotBlank(),
  62.                     new Assert\Range([
  63.                         'min'=> '0003-01-01',
  64.                         'minMessage' => 'form_error.out_of_range',
  65.                     ]),
  66.                 ],
  67.             ])
  68.             ->add('title'TextType::class, [
  69.                 'required' => true,
  70.                 'constraints' => [
  71.                     new Assert\NotBlank(),
  72.                     new Assert\Length(['max' => $this->eccubeConfig['eccube_mtext_len']]),
  73.                 ],
  74.             ])
  75.             ->add('url'TextType::class, [
  76.                 'required' => false,
  77.                 'constraints' => [
  78.                     new Assert\Url(),
  79.                     new Assert\Length(['max' => $this->eccubeConfig['eccube_mtext_len']]),
  80.                 ],
  81.             ])
  82.             ->add('link_method'CheckboxType::class, [
  83.                 'required' => false,
  84.                 'label' => 'admin.content.blogs.new_window',
  85.                 'value' => '1',
  86.             ])
  87.             ->add('blog_description'TextareaType::class, [
  88.                 'required' => false,
  89.                 'purify_html' => true,
  90.                 'attr' => [
  91.                     'rows' => 8,
  92.                 ],
  93.                 'constraints' => [
  94.                     new Assert\Length(['max' => $this->eccubeConfig['eccube_lltext_len']]),
  95.                 ],
  96.             ])
  97.             ->add('visible'ChoiceType::class, [
  98.                 'label' => false,
  99.                 'choices' => ['admin.content.blogs.display_status__show' => true'admin.content.blogs.display_status__hide' => false],
  100.                 'required' => true,
  101.                 'expanded' => false,
  102.             ])
  103.             ->add('eyecatch_file'FileType::class, [
  104.                 'label' => 'アイキャッチ画像',
  105.                 'mapped' => false,
  106.                 'required' => false,
  107.             ])
  108.             ->add('eyecatch_image'HiddenType::class, [
  109.                 'required' => false,
  110.             ])
  111.             ->add('Category'ChoiceType::class, [
  112.                 'choice_label' => 'Name',
  113.                 'multiple' => true,
  114.                 'mapped' => false,
  115.                 'expanded' => true,
  116.                 'choices' => $this->categoryRepository->getList(nulltrue),
  117.                 'choice_value' => function (Category $Category null) {
  118.                     return $Category $Category->getId() : null;
  119.                 },
  120.             ])
  121.             ->add('author'TextType::class, [
  122.                 'required' => false,
  123.                 'constraints' => [
  124.                     new Assert\Length([
  125.                         'max' => $this->eccubeConfig['eccube_stext_len'],
  126.                     ]),
  127.                 ],
  128.             ])
  129.             ->add('description'TextType::class, [
  130.                 'required' => false,
  131.                 'constraints' => [
  132.                     new Assert\Length([
  133.                         'max' => $this->eccubeConfig['eccube_stext_len'],
  134.                     ]),
  135.                 ],
  136.             ])
  137.             ->add('keyword'TextType::class, [
  138.                 'required' => false,
  139.                 'constraints' => [
  140.                     new Assert\Length([
  141.                         'max' => $this->eccubeConfig['eccube_stext_len'],
  142.                     ]),
  143.                 ],
  144.             ])
  145.             ->add('meta_robots'TextType::class, [
  146.                 'required' => false,
  147.                 'constraints' => [
  148.                     new Assert\Length([
  149.                         'max' => $this->eccubeConfig['eccube_stext_len'],
  150.                     ]),
  151.                 ],
  152.             ])
  153.             ->add('meta_tags'TextAreaType::class, [
  154.                 'required' => false,
  155.                 'constraints' => [
  156.                     new Assert\Length([
  157.                         'max' => $this->eccubeConfig['eccube_ltext_len'],
  158.                     ]),
  159.                 ],
  160.             ])
  161.         ;
  162.     }
  163.     /**
  164.      * {@inheritdoc}
  165.      */
  166.     public function configureOptions(OptionsResolver $resolver)
  167.     {
  168.     }
  169.     /**
  170.      * {@inheritdoc}
  171.      */
  172.     public function getBlockPrefix()
  173.     {
  174.         return 'plugin_blogs';
  175.     }
  176. }