app/Customize/Form/Type/Front/SchoolCertificationType.php line 69

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 Symfony\Component\Form\AbstractType;
  15. use Symfony\Component\Form\Extension\Core\Type\TextType;
  16. use Symfony\Component\Form\FormBuilderInterface;
  17. use Symfony\Component\Form\FormError;
  18. use Symfony\Component\Form\FormEvent;
  19. use Symfony\Component\Form\FormEvents;
  20. use Symfony\Component\OptionsResolver\OptionsResolver;
  21. use Symfony\Component\Validator\Constraints as Assert;
  22. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  23. use Customize\Repository\SchoolRepository;
  24. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  25. class SchoolCertificationType extends AbstractType
  26. {
  27.     /**
  28.      * @var EccubeConfig
  29.      */
  30.     protected $eccubeConfig;
  31.     protected $session;
  32.     /**
  33.      * @var SchoolRepository
  34.      */
  35.     protected $schoolRepository;
  36.     /**
  37.      * EntryType constructor.
  38.      *
  39.      * @param EccubeConfig $eccubeConfig
  40.      */
  41.     public function __construct(EccubeConfig $eccubeConfigSchoolRepository $schoolRepositorySessionInterface $session)
  42.     {
  43.         $this->eccubeConfig $eccubeConfig;
  44.         $this->schoolRepository $schoolRepository;
  45.         $this->session $session;
  46.     }
  47.     /**
  48.      * {@inheritdoc}
  49.      */
  50.     public function buildForm(FormBuilderInterface $builder, array $options)
  51.     {
  52.         $builder
  53.         ->add('school_key'TextType::class, array(
  54.             'label' => '学校キー',
  55.             'attr' => [
  56.                 'placeholder' => '学校キー',
  57.             ],
  58.             'required' => true,
  59.         ));
  60.         $School null;
  61.         $SchoolId $this->session->get('eccube.school');
  62.         if ($SchoolId 0) {
  63.             $School $this->schoolRepository->find($SchoolId);
  64.         }
  65.         if ($School == null) {
  66.             $builder->add('School'EntityType::class, array(
  67.                 'required' => true,
  68.                 'label' => '学校',
  69.                 'class' => 'Customize\Entity\School',
  70.                 'choice_label' => 'school_name',
  71.                 'placeholder' => '選択してください',
  72.                 'query_builder' => function (\Customize\Repository\SchoolRepository $sr) {
  73.                     return $sr->createQueryBuilder('s')
  74.                         ->andWhere('s.visible_flg = 1')
  75.                         ->orderBy('s.school_order''ASC');
  76.                 }
  77.             ));
  78.         }
  79.     }
  80.     /**
  81.      * {@inheritdoc}
  82.      */
  83.     public function configureOptions(OptionsResolver $resolver)
  84.     {
  85.     }
  86.     /**
  87.      * {@inheritdoc}
  88.      */
  89.     public function getBlockPrefix()
  90.     {
  91.         return 'school_certification';
  92.     }
  93. }