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

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\HiddenType;
  28. use Symfony\Component\Form\Extension\Core\Type\TextType;
  29. use Symfony\Component\Form\FormBuilderInterface;
  30. use Symfony\Component\Form\FormError;
  31. use Symfony\Component\Form\FormEvent;
  32. use Symfony\Component\Form\FormEvents;
  33. use Symfony\Component\OptionsResolver\OptionsResolver;
  34. use Symfony\Component\Validator\Constraints as Assert;
  35. class EntryType extends AbstractType
  36. {
  37.     /**
  38.      * @var EccubeConfig
  39.      */
  40.     protected $eccubeConfig;
  41.     /**
  42.      * EntryType constructor.
  43.      *
  44.      * @param EccubeConfig $eccubeConfig
  45.      */
  46.     public function __construct(EccubeConfig $eccubeConfig)
  47.     {
  48.         $this->eccubeConfig $eccubeConfig;
  49.     }
  50.     /**
  51.      * {@inheritdoc}
  52.      */
  53.     public function buildForm(FormBuilderInterface $builder, array $options)
  54.     {
  55.         $builder
  56.             ->add('name'NameType::class, [
  57.                 'required' => true,
  58.             ])
  59.             ->add('kana'KanaType::class, [])
  60.             ->add('company_name'TextType::class, [
  61.                 'required' => false,
  62.                 'constraints' => [
  63.                     new Assert\Length([
  64.                         'max' => $this->eccubeConfig['eccube_stext_len'],
  65.                     ]),
  66.                 ],
  67.             ])
  68.             ->add('company_flg'HiddenType::class, ['data'=> 0,'empty_data'=>0])
  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' => false,
  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\LessThanOrEqual([
  84.                         'value' => date('Y-m-d'strtotime('-1 day')),
  85.                         'message' => 'form_error.select_is_future_or_now_date',
  86.                     ]),
  87.                 ],
  88.             ])
  89.             ->add('sex'SexType::class, [
  90.                 'required' => false,
  91.             ])
  92.             ->add('job'JobType::class, [
  93.                 'required' => false,
  94.             ]);
  95.         $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
  96.             $Customer $event->getData();
  97.             if ($Customer instanceof Customer && !$Customer->getId()) {
  98.                 $form $event->getForm();
  99.                 $form->add('user_policy_check'CheckboxType::class, [
  100.                         'required' => true,
  101.                         'label' => null,
  102.                         'mapped' => false,
  103.                         'constraints' => [
  104.                             new Assert\NotBlank(),
  105.                         ],
  106.                     ]);
  107.             }
  108.         }
  109.         );
  110.         $builder->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) {
  111.             $form $event->getForm();
  112.             /** @var Customer $Customer */
  113.             $Customer $event->getData();
  114.             if ($Customer->getPlainPassword() != '' && $Customer->getPlainPassword() == $Customer->getEmail()) {
  115.                 $form['plain_password']['first']->addError(new FormError(trans('common.password_eq_email')));
  116.             }
  117.         });
  118.     }
  119.     /**
  120.      * {@inheritdoc}
  121.      */
  122.     public function configureOptions(OptionsResolver $resolver)
  123.     {
  124.         $resolver->setDefaults([
  125.             'data_class' => 'Eccube\Entity\Customer',
  126.         ]);
  127.     }
  128.     /**
  129.      * {@inheritdoc}
  130.      */
  131.     public function getBlockPrefix()
  132.     {
  133.         // todo entry,mypageで共有されているので名前を変更する
  134.         return 'entry';
  135.     }
  136. }