Skip to content

Commit

Permalink
Changed the constraint to the new one
Browse files Browse the repository at this point in the history
  • Loading branch information
stof committed May 25, 2013
1 parent 4a2d9ea commit 6b4e4a2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
12 changes: 10 additions & 2 deletions Form/Type/ChangePasswordFormType.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,28 @@

namespace FOS\UserBundle\Form\Type;

use Symfony\Component\Security\Core\Validator\Constraint\UserPassword;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Security\Core\Validator\Constraint\UserPassword as OldUserPassword;
use Symfony\Component\Security\Core\Validator\Constraints\UserPassword;

class ChangePasswordFormType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
if (class_exists('Symfony\Component\Security\Core\Validator\Constraints\UserPassword')) {
$constraint = new UserPassword();
} else {
// Symfony 2.1 support with the old constraint class
$constraint = new OldUserPassword();
}

$builder->add('current_password', 'password', array(
'label' => 'form.current_password',
'translation_domain' => 'FOSUserBundle',
'mapped' => false,
'constraints' => new UserPassword(),
'constraints' => $constraint,
));
$builder->add('new', 'repeated', array(
'type' => 'password',
Expand Down
12 changes: 10 additions & 2 deletions Form/Type/ProfileFormType.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Symfony\Component\Security\Core\Validator\Constraint\UserPassword;
use Symfony\Component\Security\Core\Validator\Constraint\UserPassword as OldUserPassword;
use Symfony\Component\Security\Core\Validator\Constraints\UserPassword;

class ProfileFormType extends AbstractType
{
Expand All @@ -30,13 +31,20 @@ public function __construct($class)

public function buildForm(FormBuilderInterface $builder, array $options)
{
if (class_exists('Symfony\Component\Security\Core\Validator\Constraints\UserPassword')) {
$constraint = new UserPassword();
} else {
// Symfony 2.1 support with the old constraint class
$constraint = new OldUserPassword();
}

$this->buildUserForm($builder, $options);

$builder->add('current_password', 'password', array(
'label' => 'form.current_password',
'translation_domain' => 'FOSUserBundle',
'mapped' => false,
'constraints' => new UserPassword(),
'constraints' => $constraint,
));
}

Expand Down

0 comments on commit 6b4e4a2

Please sign in to comment.