app/Customize/Form/Type/Front/EntryType.php line 30

Open in your IDE?
  1. <?php
  2. namespace Customize\Form\Type\Front;
  3. use Eccube\Common\EccubeConfig;
  4. use Eccube\Entity\Customer;
  5. use Customize\Form\Type\AddressType;
  6. use Customize\Form\Type\KanaType;
  7. use Eccube\Form\Type\Master\JobType;
  8. use Eccube\Form\Type\Master\SexType;
  9. use Customize\Form\Type\NameType;
  10. use Eccube\Form\Type\PhoneNumberType;
  11. use Eccube\Form\Type\PostalType;
  12. use Customize\Form\Type\RepeatedEmailType;
  13. use Eccube\Form\Type\RepeatedPasswordType;
  14. use Symfony\Component\Form\AbstractType;
  15. use Symfony\Component\Form\Extension\Core\Type\BirthdayType;
  16. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  17. use Symfony\Component\Form\Extension\Core\Type\TextType;
  18. use Symfony\Component\Form\FormBuilderInterface;
  19. use Symfony\Component\Form\FormError;
  20. use Symfony\Component\Form\FormEvent;
  21. use Symfony\Component\Form\FormEvents;
  22. use Symfony\Component\OptionsResolver\OptionsResolver;
  23. use Symfony\Component\Validator\Constraints as Assert;
  24. // 追加
  25. use Eccube\Common\Constant;
  26. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  27. class EntryType extends AbstractType
  28. {
  29.     /**
  30.      * @var EccubeConfig
  31.      */
  32.     protected $eccubeConfig;
  33.     /**
  34.      * EntryType constructor.
  35.      *
  36.      * @param EccubeConfig $eccubeConfig
  37.      */
  38.     public function __construct(EccubeConfig $eccubeConfig)
  39.     {
  40.         $this->eccubeConfig $eccubeConfig;
  41.     }
  42.     /**
  43.      * {@inheritdoc}
  44.      */
  45.     public function buildForm(FormBuilderInterface $builder, array $options)
  46.     {
  47.         $builder
  48.             ->add('name'NameType::class, [
  49.                 'required' => false,
  50.             ])
  51.             ->add('kana'KanaType::class, [
  52.                 'required' => false,
  53.             ])
  54.             ->add('postal_code'PostalType::class, [
  55.                 'required' => false,
  56.                 'constraints' => [
  57.                     new Assert\NotBlank(),
  58.                 ],
  59.             ])
  60.             ->add('address'AddressType::class, [
  61.                 'required' => false,
  62.             ])
  63.             ->add('company_name'TextType::class, [
  64.                 'required' => false,
  65.             ])
  66.             ->add('phone_number'TextType::class, [
  67.                 'required' => false,
  68.                 'constraints' => [
  69.                     new Assert\NotBlank(),
  70.                 ],
  71.             ])
  72.             ->add('phone2'TextType::class, [
  73.                 'required' => false,
  74.             ])
  75.             ->add('email'RepeatedEmailType::class)
  76.             ->add('plain_password'RepeatedPasswordType::class)
  77.         ;
  78.         $mailmagaFlg null;
  79.         /** @var Customer $Customer */
  80.         $Customer $builder->getData();
  81.         if ($Customer instanceof Customer && $Customer->getId()) {
  82.             $mailmagaFlg $Customer->getMailmagaFlg();
  83.         }
  84.         $moptions = [
  85.             'label' => 'admin.mailmagazine.customer.label_mailmagazine',
  86.             'choices' => [
  87.                 '希望する' => Constant::ENABLED,
  88.                 '希望しない' => Constant::DISABLED,
  89.             ],
  90.             'expanded' => true,
  91.             'multiple' => false,
  92.             'required' => true,
  93.             'constraints' => [
  94.                 new Assert\NotBlank(),
  95.             ],
  96.             'mapped' => true,
  97.             'eccube_form_options' => [
  98.                 'auto_render' => true,
  99.                 'form_theme' => '@MailMagazine42/admin/mailmagazine.twig',
  100.             ],
  101.         ];
  102.         if (!is_null($mailmagaFlg)) {
  103.             $moptions['data'] = $mailmagaFlg;
  104.         }
  105.         $builder->add('mailmaga_flg'ChoiceType::class, $moptions);
  106.         $builder->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) {
  107.             $form $event->getForm();
  108.             /** @var Customer $Customer */
  109.             $Customer $event->getData();
  110.             if ($Customer->getPlainPassword() != '' && $Customer->getPlainPassword() == $Customer->getEmail()) {
  111.                 $form['plain_password']['first']->addError(new FormError(trans('common.password_eq_email')));
  112.             }
  113.         });
  114.     }
  115.     /**
  116.      * {@inheritdoc}
  117.      */
  118.     public function configureOptions(OptionsResolver $resolver)
  119.     {
  120.         $resolver->setDefaults([
  121.             'data_class' => 'Eccube\Entity\Customer',
  122.         ]);
  123.     }
  124.     /**
  125.      * {@inheritdoc}
  126.      */
  127.     public function getBlockPrefix()
  128.     {
  129.         // todo entry,mypageで共有されているので名前を変更する
  130.         return 'entry';
  131.     }
  132. }