app/Customize/Form/Type/Front/ContactType.php line 33

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 Customize\Form\Type\Front;
  13. use Eccube\Common\EccubeConfig;
  14. use Eccube\Form\Type\AddressType;
  15. use Eccube\Form\Type\KanaType;
  16. use Eccube\Form\Type\NameType;
  17. use Eccube\Form\Type\PhoneNumberType;
  18. use Eccube\Form\Type\PostalType;
  19. use Eccube\Form\Validator\Email;
  20. use Symfony\Component\Form\AbstractType;
  21. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  22. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  23. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  24. use Symfony\Component\Form\Extension\Core\Type\TextType;
  25. use Symfony\Component\Form\FormBuilderInterface;
  26. use Symfony\Component\Validator\Constraints as Assert;
  27. use Eccube\Repository\BaseInfoRepository;
  28. use Customize\Entity\School;
  29. class ContactType extends AbstractType
  30. {
  31.     /**
  32.      * @var EccubeConfig
  33.      */
  34.     protected $eccubeConfig;
  35.     /**
  36.      * @var BaseInfoRepository
  37.      */
  38.     protected $baseInfoRepository;
  39.     /**
  40.      * ContactType constructor.
  41.      *
  42.      * @param EccubeConfig $eccubeConfig
  43.      */
  44.     public function __construct(EccubeConfig $eccubeConfigBaseInfoRepository $baseInfoRepository)
  45.     {
  46.         $this->eccubeConfig $eccubeConfig;
  47.         $this->baseInfoRepository $baseInfoRepository;
  48.     }
  49.     /**
  50.      * {@inheritdoc}
  51.      */
  52.     public function buildForm(FormBuilderInterface $builder, array $options)
  53.     {
  54.         $builder
  55.             ->add('name'NameType::class, [
  56.                 'label' => 'お名前',
  57.                 'required' => true,
  58.             ])
  59.             ->add('kana'KanaType::class, [
  60.                 'label' => 'お名前(フリガナ)',
  61.                 'required' => false,
  62.             ])
  63.             ->add('postal_code'PostalType::class, [
  64.                 'required' => false,
  65.             ])
  66.             ->add('address'AddressType::class, [
  67.                 'label' => '住所',
  68.                 'required' => false,
  69.             ])
  70.             ->add('phone_number'PhoneNumberType::class, [
  71.                 'label' => '電話番号',
  72.                 'required' => false,
  73.             ])
  74.             ->add('email'EmailType::class, [
  75.                 'label' => 'メールアドレス',
  76.             ])
  77.             ->add('contents'TextareaType::class, [
  78.                 'label' => 'お問い合わせ内容',
  79.                 'constraints' => [
  80.                     new Assert\NotBlank(),
  81.                 ],
  82.             ])
  83.             ->add('school_year'TextType::class, array(
  84.                 'label'     => '学年',
  85.                 'required' => false,
  86.             ))
  87.             ->add('school_class'TextType::class, array(
  88.                 'label'     => 'クラス',
  89.                 'required' => false,
  90.             ));
  91.             $baseinfo $this->baseInfoRepository->findOneBy([]);
  92.             if($baseinfo->getContactSchoolVisibleType()==School::SHOW || $baseinfo->getContactSchoolVisibleType()==School::MUST_SHOW)
  93.             {
  94.                 $builder->add('school'EntityType::class, array(
  95.                     'label' => '学校',
  96.                     'required' => $baseinfo->getContactSchoolVisibleType()==School::MUST_SHOW,
  97.                     'class' => 'Customize\Entity\School',
  98.                     'expanded' => false,
  99.                     'multiple' => false,
  100.                     'choice_label' => 'school_name',
  101.                     'placeholder' => '選択してください',
  102.                 ));
  103.             }
  104.     }
  105.     /**
  106.      * {@inheritdoc}
  107.      */
  108.     public function getBlockPrefix()
  109.     {
  110.         return 'contact';
  111.     }
  112. }