Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No $errorNames in UniqueEntity constraint #19447

Closed
TobiasXy opened this issue Jul 27, 2016 · 4 comments
Closed

No $errorNames in UniqueEntity constraint #19447

TobiasXy opened this issue Jul 27, 2016 · 4 comments

Comments

@TobiasXy
Copy link

It seems all (or at least most) of the base validation constraints (Symfony\Component\Validator\Constraints) set an error code when they are building the ConstraintViolation.

But: The UniqueEntity constraint (\Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity) does not.
I currently create an API where I want to provide the users error codes with every constraint violation.
How am I supposed to do that with the UniqueEntity constraint (or more general with Constraints which do not set an error code)?

Wouldn't it be good to make the error code required for ConstraintViolations?

@jakzal
Copy link
Contributor

jakzal commented Jul 27, 2016

Which error code do you mean? The UniqueConstraintValidator sets the error code just like other validators:

 $this->context->buildViolation($constraint->message)
            ->atPath($errorPath)
            ->setParameter('{{ value }}', $invalidValue)
            ->setInvalidValue($invalidValue)
            ->setCode(UniqueEntity::NOT_UNIQUE_ERROR)
            ->addViolation();

@HeahDude
Copy link
Contributor

#19309 will be part of next releases.

@HeahDude
Copy link
Contributor

and #19333 as well.

@jakzal
Copy link
Contributor

jakzal commented Jul 27, 2016

Cool, closing then :)

@jakzal jakzal closed this as completed Jul 27, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants