Skip to content

[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

Open
wants to merge 6 commits into
base: 7.4
Choose a base branch
from

Conversation

eltharin
Copy link
Contributor

@eltharin eltharin commented Aug 9, 2024

Q A
Branch? 7.2
Bug fix? no
New feature? yes
Deprecations? no
License MIT

When using UniqueEntity with multiple fields, show all fields and all values in profiler for debug quickly.
Before only one value was shown :

image
in form errors :
image

After we have all fields :
image
and in the form, error is not attached to a field but to the top form :
image

Copy link
Member

@alexandre-daubois alexandre-daubois left a 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? 🙂

@@ -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));
Copy link
Member

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.

Copy link
Contributor Author

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

Copy link
Member

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

Copy link
Member

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.

Copy link
Contributor Author

@eltharin eltharin Aug 17, 2024

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

@carsonbot carsonbot changed the title In Profiler, Show all fields and values for validation constraints [DoctrineBridge] In Profiler, Show all fields and values for validation constraints Aug 16, 2024
@eltharin eltharin force-pushed the show_all_fields_and_values_for_validation_constraints branch from d485469 to 8a7e593 Compare September 16, 2024 19:28
@fabpot fabpot modified the milestones: 7.2, 7.3 Nov 20, 2024
@eltharin eltharin force-pushed the show_all_fields_and_values_for_validation_constraints branch from 8924462 to 4d08d19 Compare January 9, 2025 20:26
@fabpot fabpot modified the milestones: 7.3, 7.4 May 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants