0

I want to override only one message in symfony2 default validation message which is :

This value should be the user current password.

this message has as a key security.validator.user_password I tried to override this message by creating BundleName/Resources/config/security.yml.

BundleName/Resources/config/security.yml

security:
    validator:
        user_password: custom message 

I tried xml file and cleared the cache but I get nothing.

Any suggestions ?

2 Answers 2

1

I think you can override using the validation.yml file in your bundle config like said on symfony2 doc.

### src/UserBundle/Resources/config/validation.yml
Acme\UserBundle\Form\Model\ChangePassword:
properties:
   oldPassword:
       - Symfony\Component\Security\Core\Validator\Constraints\UserPassword:
           message: "Wrong value for your current password"
Sign up to request clarification or add additional context in comments.

Comments

0

I found a solution to this when using FOSUserBundle as a parent to my Users bundle:

# Acme\UsersBundle\config\validation.yml
Acme\UsersBundle\Entity\User:
    properties:
        password:
            - Symfony\Component\Security\Core\Validator\Constraints\UserPassword:
                message: Please check your current password and try again

This pattern can be used to override any of the default strings which are shown when validation on a given field in that entity fails.

So to clarify:

  • Acme\UsersBundle\Entity\User: the Entity on which validation is carried out
  • password: the name of the entity attribute you're validating
  • Symfony\etc: the class which is actually doing the validation
  • message: What you want to override with

Hope this helps!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.