11
11
12
12
namespace FOS \UserBundle \Form \Type ;
13
13
14
- use Symfony \Component \Security \Core \Validator \Constraint \UserPassword ;
15
14
use Symfony \Component \Form \FormBuilderInterface ;
16
15
use Symfony \Component \OptionsResolver \OptionsResolverInterface ;
17
16
use Symfony \Component \Form \AbstractType ;
17
+ use Symfony \Component \Security \Core \Validator \Constraint \UserPassword as OldUserPassword ;
18
+ use Symfony \Component \Security \Core \Validator \Constraints \UserPassword ;
18
19
19
20
class ChangePasswordFormType extends AbstractType
20
21
{
@@ -30,11 +31,18 @@ public function __construct($class)
30
31
31
32
public function buildForm (FormBuilderInterface $ builder , array $ options )
32
33
{
34
+ if (class_exists ('Symfony\Component\Security\Core\Validator\Constraints\UserPassword ' )) {
35
+ $ constraint = new UserPassword ();
36
+ } else {
37
+ // Symfony 2.1 support with the old constraint class
38
+ $ constraint = new OldUserPassword ();
39
+ }
40
+
33
41
$ builder ->add ('current_password ' , 'password ' , array (
34
42
'label ' => 'form.current_password ' ,
35
43
'translation_domain ' => 'FOSUserBundle ' ,
36
44
'mapped ' => false ,
37
- 'constraints ' => new UserPassword () ,
45
+ 'constraints ' => $ constraint ,
38
46
));
39
47
$ builder ->add ('plainPassword ' , 'repeated ' , array (
40
48
'type ' => 'password ' ,
0 commit comments