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.                 'required' => false,
  60.             ])
  61.             ->add('company_name'TextType::class, [
  62.                 'required' => false,
  63.                 'constraints' => [
  64.                     new Assert\Length([
  65.                         'max' => $this->eccubeConfig['eccube_stext_len'],
  66.                     ]),
  67.                 ],
  68.             ])
  69.             ->add('postal_code'PostalType::class)
  70.             ->add('address'AddressType::class)
  71.             ->add('phone_number'PhoneNumberType::class, [
  72.                 'required' => true,
  73.             ])
  74.             ->add('email'RepeatedEmailType::class)
  75.             ->add('plain_password'RepeatedPasswordType::class)
  76.             ->add('birth'BirthdayType::class, [
  77.                 'required' => true,
  78.                 'input' => 'datetime',
  79.                 'years' => range(date('Y'), date('Y') - $this->eccubeConfig['eccube_birth_max']),
  80.                 'widget' => 'choice',
  81.                 'placeholder' => ['year' => '----''month' => '--''day' => '--'],
  82.                 'constraints' => [
  83.                     new Assert\NotBlank(),
  84.                     new Assert\LessThanOrEqual([
  85.                         'value' => date('Y-m-d'strtotime('-1 day')),
  86.                         'message' => 'form_error.select_is_future_or_now_date',
  87.                     ]),
  88.                 ],
  89.             ])
  90.             ->add('sex'SexType::class, [
  91.                 'required' => false,
  92.             ])
  93.             ->add('job'JobType::class, [
  94.                 'required' => false,
  95.             ]);
  96.         $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
  97.             $Customer $event->getData();
  98.             if ($Customer instanceof Customer && !$Customer->getId()) {
  99.                 $form $event->getForm();
  100.                 $form->add('user_policy_check'CheckboxType::class, [
  101.                         'required' => true,
  102.                         'label' => null,
  103.                         'mapped' => false,
  104.                         'constraints' => [
  105.                             new Assert\NotBlank(),
  106.                         ],
  107.                     ]);
  108.             }
  109.         }
  110.         );
  111.         $builder->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) {
  112.             $form $event->getForm();
  113.             /** @var Customer $Customer */
  114.             $Customer $event->getData();
  115.             if ($Customer->getPlainPassword() != '' && $Customer->getPlainPassword() == $Customer->getEmail()) {
  116.                 $form['plain_password']['first']->addError(new FormError(trans('common.password_eq_email')));
  117.             }
  118.         });
  119.     }
  120.     /**
  121.      * {@inheritdoc}
  122.      */
  123.     public function configureOptions(OptionsResolver $resolver)
  124.     {
  125.         $resolver->setDefaults([
  126.             'data_class' => 'Eccube\Entity\Customer',
  127.         ]);
  128.     }
  129.     /**
  130.      * {@inheritdoc}
  131.      */
  132.     public function getBlockPrefix()
  133.     {
  134.         // todo entry,mypageで共有されているので名前を変更する
  135.         return 'entry';
  136.     }
  137. }