Sometimes the issue occurs because the entity isn't binding the error message to the right field. Using the validation.yml
file gives you more control over how and where the error message should be treated.
# src/Ineat/LinkQuestionBundle/Resources/config/validation.yml
Ineat\LinkQuestionBundle\Entity\LinkRepository:
constraints:
- Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity:
fields: [firstForm, firstQuestion, lastForm, lastQuestion]
errorPath: lastQuestion
message: 'This port is already in use on that host.'
More information here : Symfony - UniqueEntity
Also putting text strings into "translation" files is good practice (even if you only use/have one language). You won't have bits of text lying around in your views / entities / forms / controllers ...
They will all be in you translation folder, in one location. Duplicate strings can also be changed all at once if necessary. It would look like this :
# src/Ineat/LinkQuestionBundle/Resources/config/validation.yml
Ineat\LinkQuestionBundle\Entity\LinkRepository:
constraints:
- Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity:
fields: [firstForm, firstQuestion, lastForm, lastQuestion]
errorPath: lastQuestion
message: 'linkquestion.form.errors.unique'
# src/Ineat/LinkQuestionBundle/Resources/translations/validators.fr.yml
linkquestion:
form:
errors:
unique: "This port is already in use on that host."
# Or which ever structure you choose.
Then just tell your application that it will always be in French.