app/Plugin/ProductReview42/Form/Type/ProductReviewType.php line 29

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 Plugin\ProductReview42\Form\Type;
  13. use Eccube\Common\EccubeConfig;
  14. use Eccube\Form\Type\Master\SexType;
  15. use Symfony\Component\Form\AbstractType;
  16. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  17. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  18. use Symfony\Component\Form\Extension\Core\Type\TextType;
  19. use Symfony\Component\Form\FormBuilderInterface;
  20. use Symfony\Component\Validator\Constraints as Assert;
  21. /**
  22.  * Class ProductReviewType
  23.  * [商品レビュー]-[レビューフロント]用Form.
  24.  */
  25. class ProductReviewType extends AbstractType
  26. {
  27.     /**
  28.      * @var EccubeConfig
  29.      */
  30.     protected $eccubeConfig;
  31.     /**
  32.      * ProductReviewType constructor.
  33.      *
  34.      * @param EccubeConfig $eccubeConfig
  35.      */
  36.     public function __construct(EccubeConfig $eccubeConfig)
  37.     {
  38.         $this->eccubeConfig $eccubeConfig;
  39.     }
  40.     /**
  41.      * build form.
  42.      *
  43.      * @param FormBuilderInterface $builder
  44.      * @param array                $options
  45.      */
  46.     public function buildForm(FormBuilderInterface $builder, array $options)
  47.     {
  48.         $config $this->eccubeConfig;
  49.         $builder
  50.             ->add('reviewer_name'TextType::class, [
  51.                 'label' => 'product_review.form.product_review.reviewer_name',
  52.                 'constraints' => [
  53.                     new Assert\NotBlank(),
  54.                     new Assert\Length(['max' => $config['eccube_stext_len']]),
  55.                 ],
  56.                 'attr' => [
  57.                     'maxlength' => $config['eccube_stext_len'],
  58.                 ],
  59.             ])
  60.             ->add('reviewer_url'TextType::class, [
  61.                 'label' => 'product_review.form.product_review.reviewer_url',
  62.                 'required' => false,
  63.                 'constraints' => [
  64.                     new Assert\Url(),
  65.                     new Assert\Length(['max' => $config['eccube_mltext_len']]),
  66.                 ],
  67.                 'attr' => [
  68.                     'maxlength' => $config['eccube_mltext_len'],
  69.                 ],
  70.             ])
  71.             ->add('sex'SexType::class, [
  72.                 'required' => false,
  73.             ])
  74.             ->add('recommend_level'ChoiceType::class, [
  75.                 'label' => 'product_review.form.product_review.recommend_level',
  76.                 'choices' => array_flip([
  77.                     '5' => '★★★★★',
  78.                     '4' => '★★★★',
  79.                     '3' => '★★★',
  80.                     '2' => '★★',
  81.                     '1' => '★',
  82.                 ]),
  83.                 'expanded' => true,
  84.                 'multiple' => false,
  85.                 'placeholder' => false,
  86.                 'constraints' => [
  87.                     new Assert\NotBlank(),
  88.                 ],
  89.             ])
  90.             ->add('title'TextType::class, [
  91.                 'label' => 'product_review.form.product_review.title',
  92.                 'constraints' => [
  93.                     new Assert\NotBlank(),
  94.                     new Assert\Length(['max' => 50]),
  95.                 ],
  96.                 'attr' => [
  97.                     'maxlength' => $config['eccube_stext_len'],
  98.                 ],
  99.             ])
  100.             ->add('comment'TextareaType::class, [
  101.                 'label' => 'product_review.form.product_review.comment',
  102.                 'constraints' => [
  103.                     new Assert\NotBlank(),
  104.                     new Assert\Length(['max' => $config['eccube_ltext_len']]),
  105.                 ],
  106.                 'attr' => [
  107.                     'maxlength' => $config['eccube_ltext_len'],
  108.                 ],
  109.             ]);
  110.     }
  111. }