I'm using FOSuserBundle, I have overridden registration and login form and they work fine but overriding change password form doesn't work. It is still read from the original class in vendor \ friendsofsymfony \ user-bundle \ FOS \ UserBundle \ Form \ Type \ ChangePasswordFormType
ChangePasswordFormType.php
<?php
namespace Boutique\UserBundle\Form\Type;
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;
use FOS\UserBundle\Form\Type\ChangePasswordFormType as BaseType;
class ChangePasswordFormType extends BaseType
{
private $class;
/**
* @param string $class The User class name
*/
public function __construct($class)
{
$this->class = $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();
}
$builder->add('current_password', 'password', array(
'label' => 'actuelle',
'translation_domain' => 'FOSUserBundle',
'mapped' => false,
'constraints' => $constraint,
));
$builder->add('plainPassword', 'repeated', array(
'type' => 'password',
'options' => array('translation_domain' => 'FOSUserBundle'),
'first_options' => array('label' => 'form.new_password'),
'second_options' => array('label' => 'form.new_password_confirmation'),
'invalid_message' => 'fos_user.password.mismatch',
));
}
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => $this->class,
'intention' => 'change_password',
));
}
public function getName()
{
return 'boutique_user_change_password';
}
}
services.yml
boutique_user.change_password.form.type:
class: Boutique\UserBundle\Form\Type\ChangePasswordFormType
arguments: [%fos_user.model.user.class%]
tags:
- { name: form.type, alias: boutique_user_change_password }
config.yml
fos_user:
db_driver: orm
firewall_name: main
user_class: Boutique\UserBundle\Entity\User
registration:
confirmation:
from_email: # Use this node only if you don't want the global email address for the confirmation email
address: [email protected]
sender_name: no-reply
enabled: false # change to true for required email confirmation
template: FOSUserBundle:Registration:email.txt.twig
form:
type: boutique_user_registration
name: fos_user_registration_form
validation_groups: [Registration, Default]
profile:
form:
type: boutique_user_profile_edit