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

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