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

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\Form\Validator\Email;
  14. use Eccube\Common\EccubeConfig;
  15. use Eccube\Entity\Customer;
  16. use Eccube\Form\Type\AddressType;
  17. use Eccube\Form\Type\KanaType;
  18. use Eccube\Form\Type\Master\JobType;
  19. use Eccube\Form\Type\Master\SexType;
  20. use Eccube\Form\Type\NameType;
  21. use Eccube\Form\Type\PhoneNumberType;
  22. use Eccube\Form\Type\PostalType;
  23. use Eccube\Form\Type\RepeatedEmailType;
  24. use Eccube\Form\Type\RepeatedPasswordType;
  25. use Symfony\Component\Form\Extension\Core\Type\PasswordType;
  26. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  27. use Symfony\Component\Form\AbstractType;
  28. use Symfony\Component\Form\Extension\Core\Type\BirthdayType;
  29. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  30. use Symfony\Component\Form\Extension\Core\Type\TextType;
  31. use Symfony\Component\Form\FormBuilderInterface;
  32. use Symfony\Component\Form\FormError;
  33. use Symfony\Component\Form\FormEvent;
  34. use Symfony\Component\Form\FormEvents;
  35. use Symfony\Component\OptionsResolver\OptionsResolver;
  36. use Symfony\Component\Security\Core\Validator\Constraints\UserPassword;
  37. use Symfony\Component\Validator\Constraints as Assert;
  38. class EntryType extends AbstractType
  39. {
  40.     /**
  41.      * @var EccubeConfig
  42.      */
  43.     protected $eccubeConfig;
  44.     /**
  45.      * EntryType constructor.
  46.      *
  47.      * @param EccubeConfig $eccubeConfig
  48.      */
  49.     public function __construct(EccubeConfig $eccubeConfig)
  50.     {
  51.         $this->eccubeConfig $eccubeConfig;
  52.     }
  53.     /**
  54.      * {@inheritdoc}
  55.      */
  56.     public function buildForm(FormBuilderInterface $builder, array $options)
  57.     {
  58.         $builder
  59.             ->add('name'NameType::class, [
  60.                 'required' => true,
  61.             ])
  62.             ->add('kana'KanaType::class, [])
  63.             ->add('company_name'TextType::class, [
  64.                 'required' => true,
  65.                 'constraints' => [
  66.                     new Assert\NotBlank(),
  67.                     new Assert\Length([
  68.                         'max' => $this->eccubeConfig['eccube_stext_len'],
  69.                     ]),
  70.                 ],
  71.             ])
  72.             ->add('postal_code'PostalType::class)
  73.             ->add('address'AddressType::class)
  74.             ->add('phone_number'PhoneNumberType::class, [
  75.                 'required' => true,
  76.             ])
  77.             // ->add('email', RepeatedEmailType::class)
  78.             ->add('email'EmailType::class, [
  79.                 'required' => true,
  80.                 'constraints' => [
  81.                     new Assert\NotBlank(),
  82.                     new Email(nullnull$this->eccubeConfig['eccube_rfc_email_check'] ? 'strict' null),
  83.                     new Assert\Length([
  84.                         'max' => $this->eccubeConfig['eccube_email_len'],
  85.                     ]),
  86.                 ],
  87.             ])
  88.             // ->add('plain_password', RepeatedPasswordType::class)
  89.             ->add('plain_password'TextType::class, [
  90.                 'required' => true,
  91.                 'constraints' => [
  92.                     // new Assert\NotBlank(),
  93.                     new Assert\Length([
  94.                         'min' => $this->eccubeConfig['eccube_password_min_len'],
  95.                         'max' => $this->eccubeConfig['eccube_password_max_len'],
  96.                     ]),
  97.                     new Assert\Regex([
  98.                         'pattern' => $this->eccubeConfig['eccube_password_pattern'],
  99.                         'message' => 'form_error.password_pattern_invalid',
  100.                     ]),
  101.                 ],
  102.             ])
  103.             ->add('birth'BirthdayType::class, [
  104.                 'required' => false,
  105.                 'input' => 'datetime',
  106.                 'years' => range(date('Y'), date('Y') - $this->eccubeConfig['eccube_birth_max']),
  107.                 'widget' => 'choice',
  108.                 'placeholder' => ['year' => '----''month' => '--''day' => '--'],
  109.                 'constraints' => [
  110.                     new Assert\LessThanOrEqual([
  111.                         'value' => date('Y-m-d'strtotime('-1 day')),
  112.                         'message' => 'form_error.select_is_future_or_now_date',
  113.                     ]),
  114.                 ],
  115.             ])
  116.             ->add('sex'SexType::class, [
  117.                 'required' => false,
  118.             ])
  119.             ->add('job'JobType::class, [
  120.                 'required' => false,
  121.             ]);
  122.         $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
  123.             $Customer $event->getData();
  124.             if ($Customer instanceof Customer && !$Customer->getId()) {
  125.                 $form $event->getForm();
  126.                 $form->add('user_policy_check'CheckboxType::class, [
  127.                         'required' => true,
  128.                         'label' => null,
  129.                         'mapped' => false,
  130.                         'constraints' => [
  131.                             new Assert\NotBlank(),
  132.                         ],
  133.                     ]);
  134.             }
  135.         }
  136.         );
  137.         $builder->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) {
  138.             $form $event->getForm();
  139.             /** @var Customer $Customer */
  140.             $Customer $event->getData();
  141.             if ($Customer->getPlainPassword() != '' && $Customer->getPlainPassword() == $Customer->getEmail()) {
  142.                 $form['plain_password']->addError(new FormError(trans('common.password_eq_email')));
  143.             }
  144.         });
  145.     }
  146.     /**
  147.      * {@inheritdoc}
  148.      */
  149.     public function configureOptions(OptionsResolver $resolver)
  150.     {
  151.         $resolver->setDefaults([
  152.             'data_class' => 'Eccube\Entity\Customer',
  153.         ]);
  154.     }
  155.     /**
  156.      * {@inheritdoc}
  157.      */
  158.     public function getBlockPrefix()
  159.     {
  160.         // todo entry,mypageで共有されているので名前を変更する
  161.         return 'entry';
  162.     }
  163. }