src/Eccube/Form/Type/Admin/NewsType.php line 28

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of EC-CUBE
  4.  *
  5.  * Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
  6.  *
  7.  * http://www.ec-cube.co.jp/
  8.  *
  9.  * For the full copyright and license information, please view the LICENSE
  10.  * file that was distributed with this source code.
  11.  */
  12. namespace Eccube\Form\Type\Admin;
  13. use Eccube\Common\EccubeConfig;
  14. use Eccube\Entity\News;
  15. use Symfony\Component\Form\AbstractType;
  16. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  17. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  18. use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
  19. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  20. use Symfony\Component\Form\Extension\Core\Type\TextType;
  21. use Symfony\Component\Form\FormBuilderInterface;
  22. use Symfony\Component\OptionsResolver\OptionsResolver;
  23. use Symfony\Component\Validator\Constraints as Assert;
  24. class NewsType extends AbstractType
  25. {
  26.     /**
  27.      * @var EccubeConfig
  28.      */
  29.     protected $eccubeConfig;
  30.     public function __construct(EccubeConfig $eccubeConfig)
  31.     {
  32.         $this->eccubeConfig $eccubeConfig;
  33.     }
  34.     /**
  35.      * {@inheritdoc}
  36.      */
  37.     public function buildForm(FormBuilderInterface $builder, array $options)
  38.     {
  39.         $builder
  40.             ->add('publish_date'DateTimeType::class, [
  41.                 'widget' => 'single_text',
  42.                 'input' => 'datetime',
  43.                 'years' => range($this->eccubeConfig['eccube_news_start_year'], date('Y') + 3),
  44.                 'with_seconds' => true,
  45.                 'constraints' => [
  46.                     new Assert\NotBlank(),
  47.                     new Assert\Range([
  48.                         'min'=> '0003-01-01',
  49.                         'minMessage' => 'form_error.out_of_range',
  50.                     ]),
  51.                 ],
  52.             ])
  53.             ->add('title'TextType::class, [
  54.                 'required' => true,
  55.                 'constraints' => [
  56.                     new Assert\NotBlank(),
  57.                     new Assert\Length(['max' => $this->eccubeConfig['eccube_mtext_len']]),
  58.                 ],
  59.             ])
  60.             ->add('url'TextType::class, [
  61.                 'required' => false,
  62.                 'constraints' => [
  63.                     new Assert\Url(),
  64.                     new Assert\Length(['max' => $this->eccubeConfig['eccube_mtext_len']]),
  65.                 ],
  66.             ])
  67.             ->add('link_method'CheckboxType::class, [
  68.                 'required' => false,
  69.                 'label' => 'admin.content.news.new_window',
  70.                 'value' => '1',
  71.             ])
  72.             ->add('description'TextareaType::class, [
  73.                 'required' => false,
  74.                 'purify_html' => true,
  75.                 'attr' => [
  76.                     'rows' => 8,
  77.                 ],
  78.                 'constraints' => [
  79.                     new Assert\Length(['max' => $this->eccubeConfig['eccube_ltext_len']]),
  80.                 ],
  81.             ])
  82.             ->add('visible'ChoiceType::class, [
  83.                 'label' => false,
  84.                 'choices' => ['admin.content.news.display_status__show' => true'admin.content.news.display_status__hide' => false],
  85.                 'required' => true,
  86.                 'expanded' => false,
  87.             ]);
  88.     }
  89.     /**
  90.      * {@inheritdoc}
  91.      */
  92.     public function configureOptions(OptionsResolver $resolver)
  93.     {
  94.         $resolver->setDefaults([
  95.             'data_class' => News::class,
  96.         ]);
  97.     }
  98.     /**
  99.      * {@inheritdoc}
  100.      */
  101.     public function getBlockPrefix()
  102.     {
  103.         return 'admin_news';
  104.     }
  105. }