Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.6k
[Form] Created FormErrorBag (Approach 2)#9914
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
This is fully BC with returning an array and it deprecatesForm::getErrorsAsString()
It's now an IteratorAggregate with ArrayAccess. At normal use, it onlyreturns the root errors. When calling FormErrorBag#getAllErrors() it willreturn a RecursiveArrayIterator, iterating over all form errors.
you need to clone the FormErrorBag when cloning the Form as it is an object now. Otherwise errors will be shared between both forms |
// for BC | ||
if (is_array($childrenErrors)) { | ||
$_collection = new FormErrorBag(); |
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 don't use the leading undescore in Symfony
I thinkadding the errors to the bags is problematic, because now we store the errors in two different locations which we need to synchronize. I found a better and simpler approach using just iterators now that I'm going to post as PR shortly. That approach is somewhat similar to yours, but uses a different perspective (temporary iterators instead of permanent bags). |
replaced by#9918 |
From#9099 :
The only BC break in this PR is checking it with is_array.
It turns out that the previous approach, using recursive iterators, couldn't work in practise. That's why I introduce, with the help of@igorw, a new approach. When using it normally, it can be accessed as an array and when iterating it will iterate only over the root errors (this is BC). When calling
FormErrorBag->getAllErrors()
aRecursiveArrayIterator
is returned, iterating over all errors.