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. /*▼RZ 2025.08.04 EDIT 会社名を必須項目に変更 RZ▼*/
  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. */
  70.             ->add('company_name'TextType::class, [
  71.                 'required' => true,
  72.                 'constraints' => [
  73.                     new Assert\NotBlank(),
  74.                     new Assert\Length([
  75.                         'max' => $this->eccubeConfig['eccube_stext_len'],
  76.                     ]),
  77.                 ],
  78.             ])
  79.             ->add('representative_name'TextType::class, [
  80.                 'required' => true,
  81.                 'constraints' => [
  82.                     new Assert\NotBlank(),
  83.                     new Assert\Length([
  84.                         'max' => $this->eccubeConfig['eccube_stext_len'],
  85.                     ]),
  86.                 ],
  87.             ])
  88.             ->add('homepage_url'TextType::class, [
  89.                             'required' => true,
  90.                 'constraints' => [
  91.                     new Assert\NotBlank(),
  92.                     new Assert\Length([
  93.                         'max' => $this->eccubeConfig['eccube_stext_len'],
  94.                     ]),
  95.                 ],
  96.             ])
  97. /*▲RZ 2025.08.04 EDIT 会社名を必須項目に変更 RZ▲*/
  98.             ->add('postal_code'PostalType::class)
  99.             ->add('address'AddressType::class)
  100.             ->add('phone_number'PhoneNumberType::class, [
  101.                 'required' => true,
  102.             ])
  103.             ->add('email'RepeatedEmailType::class)
  104.             ->add('plain_password'RepeatedPasswordType::class)
  105.             ->add('birth'BirthdayType::class, [
  106.                 'required' => false,
  107.                 'input' => 'datetime',
  108.                 'years' => range(date('Y'), date('Y') - $this->eccubeConfig['eccube_birth_max']),
  109.                 'widget' => 'choice',
  110.                 'placeholder' => ['year' => '----''month' => '--''day' => '--'],
  111.                 'constraints' => [
  112.                     new Assert\LessThanOrEqual([
  113.                         'value' => date('Y-m-d'strtotime('-1 day')),
  114.                         'message' => 'form_error.select_is_future_or_now_date',
  115.                     ]),
  116.                 ],
  117.             ])
  118.             ->add('sex'SexType::class, [
  119.                 'required' => false,
  120.             ])
  121.             ->add('job'JobType::class, [
  122.                 'required' => false,
  123.             ]);
  124.         $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
  125.             $Customer $event->getData();
  126.             if ($Customer instanceof Customer && !$Customer->getId()) {
  127.                 $form $event->getForm();
  128.                 $form->add('user_policy_check'CheckboxType::class, [
  129.                         'required' => true,
  130.                         'label' => null,
  131.                         'mapped' => false,
  132.                         'constraints' => [
  133.                             new Assert\NotBlank(),
  134.                         ],
  135.                     ]);
  136.             }
  137.         }
  138.         );
  139.         $builder->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) {
  140.             $form $event->getForm();
  141.             /** @var Customer $Customer */
  142.             $Customer $event->getData();
  143.             if ($Customer->getPlainPassword() != '' && $Customer->getPlainPassword() == $Customer->getEmail()) {
  144.                 $form['plain_password']['first']->addError(new FormError(trans('common.password_eq_email')));
  145.             }
  146.         });
  147.     }
  148.     /**
  149.      * {@inheritdoc}
  150.      */
  151.     public function configureOptions(OptionsResolver $resolver)
  152.     {
  153.         $resolver->setDefaults([
  154.             'data_class' => 'Eccube\Entity\Customer',
  155.         ]);
  156.     }
  157.     /**
  158.      * {@inheritdoc}
  159.      */
  160.     public function getBlockPrefix()
  161.     {
  162.         // todo entry,mypageで共有されているので名前を変更する
  163.         return 'entry';
  164.     }
  165. }