Skip to content

Commit 1f2cd0c

Browse files
committed
Changed the constraint to the new one
1 parent 8cfcf68 commit 1f2cd0c

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

Form/Type/ChangePasswordFormType.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@
1111

1212
namespace FOS\UserBundle\Form\Type;
1313

14-
use Symfony\Component\Security\Core\Validator\Constraint\UserPassword;
1514
use Symfony\Component\Form\FormBuilderInterface;
1615
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
1716
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;
1819

1920
class ChangePasswordFormType extends AbstractType
2021
{
@@ -30,11 +31,18 @@ public function __construct($class)
3031

3132
public function buildForm(FormBuilderInterface $builder, array $options)
3233
{
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+
3341
$builder->add('current_password', 'password', array(
3442
'label' => 'form.current_password',
3543
'translation_domain' => 'FOSUserBundle',
3644
'mapped' => false,
37-
'constraints' => new UserPassword(),
45+
'constraints' => $constraint,
3846
));
3947
$builder->add('plainPassword', 'repeated', array(
4048
'type' => 'password',

Form/Type/ProfileFormType.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
use Symfony\Component\Form\AbstractType;
1515
use Symfony\Component\Form\FormBuilderInterface;
1616
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
17-
use Symfony\Component\Security\Core\Validator\Constraint\UserPassword;
17+
use Symfony\Component\Security\Core\Validator\Constraint\UserPassword as OldUserPassword;
18+
use Symfony\Component\Security\Core\Validator\Constraints\UserPassword;
1819

1920
class ProfileFormType extends AbstractType
2021
{
@@ -30,13 +31,20 @@ public function __construct($class)
3031

3132
public function buildForm(FormBuilderInterface $builder, array $options)
3233
{
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+
3341
$this->buildUserForm($builder, $options);
3442

3543
$builder->add('current_password', 'password', array(
3644
'label' => 'form.current_password',
3745
'translation_domain' => 'FOSUserBundle',
3846
'mapped' => false,
39-
'constraints' => new UserPassword(),
47+
'constraints' => $constraint,
4048
));
4149
}
4250

0 commit comments

Comments
 (0)