src/Eccube/Form/Type/RepeatedEmailType.php line 26

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;
  13. use Eccube\Common\EccubeConfig;
  14. use Eccube\Form\Validator\Email;
  15. use Symfony\Component\Form\AbstractType;
  16. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  17. use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
  18. use Symfony\Component\OptionsResolver\Options;
  19. use Symfony\Component\OptionsResolver\OptionsResolver;
  20. use Symfony\Component\Validator\Constraints as Assert;
  21. use Symfony\Component\Form\Extension\Core\Type\TextType;
  22. class RepeatedEmailType extends AbstractType
  23. {
  24.     /**
  25.      * @var EccubeConfig
  26.      */
  27.     protected $eccubeConfig;
  28.     /**
  29.      * ContactType constructor.
  30.      *
  31.      * @param EccubeConfig $eccubeConfig
  32.      */
  33.     public function __construct(EccubeConfig $eccubeConfig)
  34.     {
  35.         $this->eccubeConfig $eccubeConfig;
  36.     }
  37.     /**
  38.      * {@inheritdoc}
  39.      */
  40.     public function configureOptions(OptionsResolver $resolver)
  41.     {
  42.         $resolver->setDefaults([
  43.             'entry_type' => TextType::class,
  44.             'required' => true,
  45.             'invalid_message' => 'form_error.same_email',
  46.             'options' => [
  47.                 'constraints' => [
  48.                     new Assert\NotBlank(),
  49.                     new Assert\Length([
  50.                         'max' => $this->eccubeConfig['eccube_email_len'],
  51.                     ]),
  52.                 ],
  53.             ],
  54.             'first_options' => [
  55.                 'attr' => [
  56.                     'placeholder' => 'common.mail_address_sample',
  57.                 ],
  58.             ],
  59.             'second_options' => [
  60.                 'attr' => [
  61.                     'placeholder' => 'common.repeated_confirm',
  62.                 ],
  63.             ],
  64.             'error_bubbling' => false,
  65.             'trim' => true,
  66.             'error_mapping' => function (Options $options) {
  67.                 return ['.' => $options['second_name']];
  68.             },
  69.         ]);
  70.     }
  71.     /**
  72.      * {@inheritdoc}
  73.      */
  74.     public function getParent()
  75.     {
  76.         return RepeatedType::class;
  77.     }
  78.     /**
  79.      * {@inheritdoc}
  80.      */
  81.     public function getBlockPrefix()
  82.     {
  83.         return 'repeated_email';
  84.     }
  85. }