[DoctrineBridge][Validator] Expose all fields for message validation failure #38969
+27
−5
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The main reason of the pull request is to improve the way
UniqueEntity
validator provide invalide values for us.Unfortunately, if we use the validator with more than one field, we will only have the first value at our disposal to customize the message that’s displayed when the constraint fails, cause, according to this line:
$invalidValue = isset($criteria[$errorPath]) ? $criteria[$errorPath] : $criteria[$fields[0]];
the message is always mapped to the first field causing the violation.Imagine we have an entity
Dummy
class, and we post ajson
data that looks like this:{"foo": "space", "bar": "github"}
.The result that will be displayed is:
Registration failed, the foo *space* is already exist for *github*"
and that's more specific and friendly.Any way, just let me know if this requires to add some unit tests or some documentation, (if it'is an interesting idea).
Best regards,