-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DoctrineBridge] In Profiler, Show all fields and values for validation constraints #57963
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
base: 7.4
Are you sure you want to change the base?
[DoctrineBridge] In Profiler, Show all fields and values for validation constraints #57963
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As it touches the Profiler, would it be possible to have a screenshot showing the before/after? 🙂
src/Symfony/Bridge/Doctrine/Validator/Constraints/UniqueEntityValidator.php
Outdated
Show resolved
Hide resolved
@@ -207,16 +207,25 @@ public function validate(mixed $value, Constraint $constraint): void | |||
} | |||
} | |||
|
|||
$errorPath = $constraint->errorPath ?? current($fields); | |||
$invalidValue = $criteria[$errorPath] ?? $criteria[current($fields)]; | |||
$errorPath = $constraint->errorPath ?? implode(', ', array_keys($criteria)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change will break the integration into the Form component as the error now can no longer be mapped back to the corresponding form type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if one field, error stay on field, but if there are many fields, error go on top form instead one arbitrary field
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it'd be great to have a test case that covers the issue that @xabbuh spotted here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking about this PR again I'd say if we were to change anything here the constraint could accept the errorPath
option to be configured as an array which would lead to the violation being added to all these property paths. But doing the suggested change is a no go to me as it breaks the Form integration as explained.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add to all property can be OK but can create backward compatibility breaks,
but actually we have violation on only one field is not good, it's not A field whitch is bad but a group,
if you set firstname and lastname unique, form will respond to you "firstname is incorrect Christian is already used".
That's why put this to the parent form instead one field is preferable.
I think.
I'm trying to do tests and I'll look for an array (or an object stringable) for errorPath
d485469
to
8a7e593
Compare
8924462
to
4d08d19
Compare
When using UniqueEntity with multiple fields, show all fields and all values in profiler for debug quickly.
Before only one value was shown :
in form errors :
After we have all fields :


and in the form, error is not attached to a field but to the top form :