-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Form] FormErrorIterator do not filter only with Constraint causes #28649
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
Conversation
i dont think FormError object should be strict on the type of the Cause.. but this change seems reasonable yes 👍 |
} | ||
|
||
$cause = (string)$cause; | ||
if(\in_array($cause, $codes, true)){ |
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.
don't miss fabbot patch around this line
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.
done :)
Do you guys believe that this change is a BC? An edge case: |
3ac3ab1
to
545dc12
Compare
… is string or object that has a __toString method
545dc12
to
e5275c6
Compare
I think a better solution would be to introduce the concept of error codes in the |
We could also think about having a |
I do like this idea even better.
Can you elaborate a little bit here? Do you mean that FormError can have a Cause and a Code also? |
also see #19496 (comment). Im curious about the proposed API, as we avoid the callback to have convenient API today. This PR just provides more meaning to "code" in the form component (e.g. if the cause is scalar-ish; it's a code). That's valid to me. It's effectively the same as
Other filters fit foreach IMHO. |
*/ | ||
public function testFindByCodesWhenAllCausesAreVariousObjectsOrSimpleStrings($code, $violationsCount) | ||
{ | ||
if (!class_exists(ConstraintViolation::class)) { |
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.
we should not require validator component to test the new feature (we aim for compatibility without it)
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.
FYI this test class on master contains one test case. I have duplicated this test case on the current PR. These lines are the copied code from the previous test case.
Your proposal is to remove them from both test cases?
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.
FYI this test class on master contains one test case
then i suggest to refactor it a bit, and keep a single testFindByCodes()
where the expectations are built dynamically (if validator exists yes/no)
} | ||
|
||
$cause = (string) $cause; | ||
if (\in_array($cause, $codes, true)) { |
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.
id say in_array((string) $cause, ..
What's the status of this pull request? /cc @xabbuh |
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.
LGTM
I dont have the time to work on this.. whoever wants can take it... |
Closing as nobody stepped up to finish this PR. |
I made this PR based on this
In general I believe that the FormError object should be strict on the type of the Cause. It should either be a
ConstraintViolation
object an object that implementstoString
function or a simple string and this should be checked during the construction of the FormError. For me it's too vague what a cause argument is and whatfindByCodes
does.. Althought this PR does not check anything on the construction of the FormError object this can be the first step.I will add tests later if you agree with this PR. Let me know. 😄