99 * file that was distributed with this source code.
1010 */
1111
12- namespace App \Form \ Type ;
12+ namespace App \Form ;
1313
14+ use App \Entity \User ;
1415use Symfony \Component \Form \AbstractType ;
1516use Symfony \Component \Form \Extension \Core \Type \PasswordType ;
1617use Symfony \Component \Form \Extension \Core \Type \RepeatedType ;
1718use Symfony \Component \Form \FormBuilderInterface ;
19+ use Symfony \Component \OptionsResolver \OptionsResolver ;
1820use Symfony \Component \Security \Core \Validator \Constraints \UserPassword ;
1921use Symfony \Component \Validator \Constraints \Length ;
2022use Symfony \Component \Validator \Constraints \NotBlank ;
2123
2224/**
23- * Defines the custom form field type used to change user's password.
25+ * Defines the form used to change user's password.
2426 *
2527 * @author Romain Monteil <monteil.romain@gmail.com>
2628 */
@@ -37,6 +39,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
3739 new UserPassword (),
3840 ],
3941 'label ' => 'label.current_password ' ,
42+ 'mapped ' => false ,
4043 'attr ' => [
4144 'autocomplete ' => 'off ' ,
4245 ],
@@ -51,12 +54,24 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
5154 ),
5255 ],
5356 'first_options ' => [
57+ 'hash_property_path ' => 'password ' ,
5458 'label ' => 'label.new_password ' ,
5559 ],
60+ 'mapped ' => false ,
5661 'second_options ' => [
5762 'label ' => 'label.new_password_confirm ' ,
5863 ],
5964 ])
6065 ;
6166 }
67+
68+ /**
69+ * {@inheritdoc}
70+ */
71+ public function configureOptions (OptionsResolver $ resolver ): void
72+ {
73+ $ resolver ->setDefaults ([
74+ 'data_class ' => User::class,
75+ ]);
76+ }
6277}
0 commit comments