src/Eccube/Form/Type/Front/EntryType.php line 37

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\Front;
  13. use Eccube\Common\EccubeConfig;
  14. use Eccube\Entity\Customer;
  15. use Eccube\Form\Type\AddressType;
  16. use Eccube\Form\Type\KanaType;
  17. use Eccube\Form\Type\Master\JobType;
  18. use Eccube\Form\Type\Master\SexType;
  19. use Eccube\Form\Type\NameType;
  20. use Eccube\Form\Type\RepeatedEmailType;
  21. use Eccube\Form\Type\RepeatedPasswordType;
  22. use Eccube\Form\Type\PhoneNumberType;
  23. use Eccube\Form\Type\PostalType;
  24. use Symfony\Component\Form\AbstractType;
  25. use Symfony\Component\Form\Extension\Core\Type\BirthdayType;
  26. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  27. use Symfony\Component\Form\Extension\Core\Type\TextType;
  28. use Symfony\Component\Form\FormBuilderInterface;
  29. use Symfony\Component\Form\FormEvent;
  30. use Symfony\Component\Form\FormEvents;
  31. use Symfony\Component\OptionsResolver\OptionsResolver;
  32. use Symfony\Component\Validator\Constraints as Assert;
  33. class EntryType extends AbstractType
  34. {
  35.     /**
  36.      * @var EccubeConfig
  37.      */
  38.     protected $eccubeConfig;
  39.     /**
  40.      * EntryType constructor.
  41.      *
  42.      * @param EccubeConfig $eccubeConfig
  43.      */
  44.     public function __construct(EccubeConfig $eccubeConfig)
  45.     {
  46.         $this->eccubeConfig $eccubeConfig;
  47.     }
  48.     /**
  49.      * {@inheritdoc}
  50.      */
  51.     public function buildForm(FormBuilderInterface $builder, array $options)
  52.     {
  53.         $builder
  54.             ->add('name'NameType::class, [
  55.                 'required' => true,
  56.             ])
  57.             ->add('kana'KanaType::class, [])
  58.             ->add('company_name'TextType::class, [
  59.                 'required' => false,
  60.                 'constraints' => [
  61.                     new Assert\Length([
  62.                         'max' => $this->eccubeConfig['eccube_stext_len'],
  63.                     ]),
  64.                 ],
  65.             ])
  66.             ->add('postal_code'PostalType::class)
  67.             ->add('address'AddressType::class)
  68.             ->add('phone_number'PhoneNumberType::class, [
  69.                 'required' => true,
  70.             ])
  71.             ->add('email'RepeatedEmailType::class)
  72.             ->add('password'RepeatedPasswordType::class)
  73.             ->add('birth'BirthdayType::class, [
  74.                 'required' => false,
  75.                 'input' => 'datetime',
  76.                 'years' => range(date('Y'), date('Y') - $this->eccubeConfig['eccube_birth_max']),
  77.                 'widget' => 'choice',
  78.                 'format' => 'yyyy/MM/dd',
  79.                 'placeholder' => ['year' => '----''month' => '--''day' => '--'],
  80.                 'constraints' => [
  81.                     new Assert\LessThanOrEqual([
  82.                         'value' => date('Y-m-d'strtotime('-1 day')),
  83.                         'message' => 'form_error.select_is_future_or_now_date',
  84.                     ]),
  85.                 ],
  86.             ])
  87.             ->add('sex'SexType::class, [
  88.                 'required' => false,
  89.             ])
  90.             ->add('job'JobType::class, [
  91.                 'required' => false,
  92.             ]);
  93.         $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
  94.             $Customer $event->getData();
  95.             if ($Customer instanceof Customer && !$Customer->getId()) {
  96.                 $form $event->getForm();
  97.                 $form->add('user_policy_check'CheckboxType::class, [
  98.                         'required' => true,
  99.                         'label' => null,
  100.                         'mapped' => false,
  101.                         'constraints' => [
  102.                             new Assert\NotBlank(),
  103.                         ],
  104.                     ]);
  105.             }
  106.         }
  107.         );
  108.     }
  109.     /**
  110.      * {@inheritdoc}
  111.      */
  112.     public function configureOptions(OptionsResolver $resolver)
  113.     {
  114.         $resolver->setDefaults([
  115.             'data_class' => 'Eccube\Entity\Customer',
  116.         ]);
  117.     }
  118.     /**
  119.      * {@inheritdoc}
  120.      */
  121.     public function getBlockPrefix()
  122.     {
  123.         // todo entry,mypageで共有されているので名前を変更する
  124.         return 'entry';
  125.     }
  126. }