Skip to content

[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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from

Conversation

wouterj
Copy link
Member

@wouterj wouterj commented Dec 31, 2013

From #9099 :

Q A
Bug fix? no
New feature? yes
BC breaks? yes
Deprecations? yes
Tests pass? don't know yet...
Fixed tickets #7205
License MIT
Doc PR symfony/symfony-docs#3397

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() a RecursiveArrayIterator is returned, iterating over all errors.

This is fully BC with returning an array and it deprecates
Form::getErrorsAsString()
It's now an IteratorAggregate with ArrayAccess. At normal use, it only
returns the root errors. When calling FormErrorBag#getAllErrors() it will
return a RecursiveArrayIterator, iterating over all form errors.
@wouterj wouterj mentioned this pull request Dec 31, 2013
4 tasks
@stof
Copy link
Member

stof commented Dec 31, 2013

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

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

@webmozart
Copy link
Contributor

I think adding 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).

@webmozart
Copy link
Contributor

replaced by #9918

@webmozart webmozart closed this Dec 31, 2013
@wouterj wouterj deleted the fix_7205_1 branch December 31, 2013 16:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants