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

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\PhoneNumberType;
  21. use Eccube\Form\Type\PostalType;
  22. use Eccube\Form\Type\RepeatedEmailType;
  23. use Eccube\Form\Type\RepeatedPasswordType;
  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\FormError;
  30. use Symfony\Component\Form\FormEvent;
  31. use Symfony\Component\Form\FormEvents;
  32. use Symfony\Component\OptionsResolver\OptionsResolver;
  33. use Symfony\Component\Validator\Constraints as Assert;
  34. class EntryType extends AbstractType
  35. {
  36.     /**
  37.      * @var EccubeConfig
  38.      */
  39.     protected $eccubeConfig;
  40.     /**
  41.      * EntryType constructor.
  42.      *
  43.      * @param EccubeConfig $eccubeConfig
  44.      */
  45.     public function __construct(EccubeConfig $eccubeConfig)
  46.     {
  47.         $this->eccubeConfig $eccubeConfig;
  48.     }
  49.     /**
  50.      * {@inheritdoc}
  51.      */
  52.     public function buildForm(FormBuilderInterface $builder, array $options)
  53.     {
  54.         $builder
  55.             ->add('name'NameType::class, [
  56.                 'required' => true,
  57.             ])
  58.             ->add('kana'KanaType::class, [])
  59.             ->add('company_name'TextType::class, [
  60.                 'required' => false,
  61.                 'constraints' => [
  62.                     new Assert\Length([
  63.                         'max' => $this->eccubeConfig['eccube_stext_len'],
  64.                     ]),
  65.                 ],
  66.             ])
  67.             ->add('postal_code'PostalType::class)
  68.             ->add('address'AddressType::class)
  69.             ->add('phone_number'PhoneNumberType::class, [
  70.                 'required' => true,
  71.             ])
  72.             ->add('email'RepeatedEmailType::class)
  73.             ->add('plain_password'RepeatedPasswordType::class)
  74.             ->add('birth'BirthdayType::class, [
  75.                 'required' => false,
  76.                 'input' => 'datetime',
  77.                 'years' => range(date('Y'), date('Y') - $this->eccubeConfig['eccube_birth_max']),
  78.                 'widget' => 'choice',
  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.         $builder->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) {
  109.             $form $event->getForm();
  110.             /** @var Customer $Customer */
  111.             $Customer $event->getData();
  112.             if ($Customer->getPlainPassword() != '' && $Customer->getPlainPassword() == $Customer->getEmail()) {
  113.                 $form['plain_password']['first']->addError(new FormError(trans('common.password_eq_email')));
  114.             }
  115.         });
  116.     }
  117.     /**
  118.      * {@inheritdoc}
  119.      */
  120.     public function configureOptions(OptionsResolver $resolver)
  121.     {
  122.         $resolver->setDefaults([
  123.             'data_class' => 'Eccube\Entity\Customer',
  124.         ]);
  125.     }
  126.     /**
  127.      * {@inheritdoc}
  128.      */
  129.     public function getBlockPrefix()
  130.     {
  131.         // todo entry,mypageで共有されているので名前を変更する
  132.         return 'entry';
  133.     }
  134. }