src/Eccube/Form/Type/RepeatedPasswordType.php line 29

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 Symfony\Component\Form\AbstractType;
  15. use Symfony\Component\Form\Extension\Core\DataTransformer\ValueToDuplicatesTransformer;
  16. use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
  17. use Symfony\Component\Form\Extension\Core\Type\TextType;
  18. use Symfony\Component\Form\FormBuilderInterface;
  19. use Symfony\Component\OptionsResolver\Options;
  20. use Symfony\Component\OptionsResolver\OptionsResolver;
  21. use Symfony\Component\Validator\Constraints as Assert;
  22. /**
  23.  * Class RepeatedPasswordType
  24.  */
  25. class RepeatedPasswordType extends AbstractType
  26. {
  27.     /**
  28.      * @var EccubeConfig
  29.      */
  30.     protected $eccubeConfig;
  31.     /**
  32.      * RepeatedPasswordType constructor.
  33.      *
  34.      * @param EccubeConfig $eccubeConfig
  35.      */
  36.     public function __construct(EccubeConfig $eccubeConfig)
  37.     {
  38.         $this->eccubeConfig $eccubeConfig;
  39.     }
  40.     /**
  41.      * {@inheritdoc}
  42.      */
  43.     public function configureOptions(OptionsResolver $resolver)
  44.     {
  45.         $resolver->setDefaults([
  46.             'type' => TextType::class, // type password だと入力欄を空にされてしまうので、widgetで対応
  47.             'invalid_message' => 'form_error.same_password',
  48.             'required' => true,
  49.             'trim'=> true,
  50.             'error_bubbling' => false,
  51.             'first_options' => [
  52.                 'attr' => [
  53.                     'placeholder' => trans('common.password_sample', [
  54.                         '%min%' => $this->eccubeConfig['eccube_password_min_len_in_entry'],
  55.                         '%max%' => $this->eccubeConfig['eccube_password_max_len_in_entry'], ]),
  56.                 ],
  57.                 'constraints' => [
  58.                     new Assert\NotBlank(),
  59.                     new Assert\Length([
  60.                         'min' => $this->eccubeConfig['eccube_password_min_len_in_entry'],
  61.                         'max' => $this->eccubeConfig['eccube_password_max_len_in_entry'],
  62.                     ]),
  63.                     new Assert\Regex([
  64.                         'pattern' => $this->eccubeConfig['eccube_password_pattern'],
  65.                         'message' => 'form_error.password_pattern_invalid',
  66.                     ]),
  67.                 ]
  68.             ],
  69.             'second_options' => [
  70.                 'attr' => [
  71.                     'placeholder' => 'common.repeated_confirm',
  72.                 ],
  73.             ],
  74.             'error_mapping' => function (Options $options) {
  75.                 return ['.' => $options['second_name']];
  76.             },
  77.         ]);
  78.     }
  79.     /**
  80.      * {@inheritdoc}
  81.      */
  82.     public function getParent()
  83.     {
  84.         return RepeatedType::class;
  85.     }
  86.     /**
  87.      * {@inheritdoc}
  88.      */
  89.     public function getBlockPrefix()
  90.     {
  91.         return 'repeated_password';
  92.     }
  93. }