Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[Form] Created FormErrorBag#9099
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
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.
Please remove the leading underscore. We don't use it in Symfony
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.
I used it because invalid is not a real property of the object, it's just a helper property. But I'll remove it
wouterj commentedSep 24, 2013
I've fixed the tests, added some things for BC (see below) and added the last missing features. I think it's ready for review@stof @bschussek
|
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.
not sure if this is needed...
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.
Yes, but you can changev2.4.0 to2.4.
stof commentedSep 24, 2013
I think your ArrayAccess is not BC as the offset does not concern only errors but also child error collections. So getting |
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.
Why do we need to support arrays 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.
some tests are failing without this. BTW, do you know why the tests are failing now? It seems there is another BC bug...
wouterj commentedOct 1, 2013
fixed all comments. I know I'm one day after the feature freeze, but I'd like to see this included in 2.4... |
fabpot commentedOct 1, 2013
@wouterj You're lucky as I'm still working on merging the last PRs for 2.4... let's wait for @bschussek thoughts first. |
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.
missing phpdoc for many methods
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.
do we really want to have PHPdoc for PHP build-in methods, like __toString etc?
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.
no
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.
yes because otherwise it's not documented what the string representation actually returns
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.
and this is one of the main points of 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.
also its not doccumented that it accepts a parameter
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.
the string representation wasn't documented on getErrorsAsString() too, I don't really know why we should do it here. And the parameter is only for internal use.
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.
where is the parameter used internally?
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's used to indent the children forms with 4 spaces
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.
ok as long as its not used outside the 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.
missing bc break info
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.
fixed
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.
what i also mean is that it should be tagged with [BC BREAK], see other changelog entries
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.
also getErrors now returns all errors, whereas it previously returned only direct child errors, or?
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.
@Tobion no it does not. It returns a RecusiveIterator instead of an array. So youcan have all errors if you wrap it in aRecursiveIteratorIterator, but the default iteration still gives you only the form errors only (and not the direct child errors as you said in your comment)
asm89 commentedOct 11, 2013
@fabpot @bschussek Any chance of getting this in |
src/Symfony/Component/Form/Form.php Outdated
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 should be$this->getErrors()->__toString($level)
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.
why? Level should be the default, 0, and explicitly calling a magic method seems wrong to me. But if there is any reason why this is better or if this is the CS, I'm happy to change this
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.
@wouterj because if you ignore the$level argument, you are not providing BC totally (even if it was considered as an internal argument, I'm sure some people were using 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.
fixed
hugohenrique commentedNov 25, 2013
ping |
asm89 commentedNov 27, 2013
ping@fabpot @bschussek I guess this won't make 2.4... |
Koc commentedDec 11, 2013
is it possible to convert this bag to array like ? Where key is form field full name and value is list of the errors for field. It is useful for ajax responses (bind tooltips with errors to fields) |
wouterj commentedDec 25, 2013
@Koc no, that's not possible with the method itself. But with some array changer functions, you can create something like that. |
src/Symfony/Component/Form/Form.php Outdated
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.
should be 2.5 andConvert instead ofCovert.
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.
Also, can you put everything on the same line?
fabpot commentedDec 28, 2013
@wouterj Besides some small typos, looks good to me. Can you also rebase on current master and add a ticket for the documentation? Thanks. |
This is fully BC with returning an array and it deprecatesForm::getErrorsAsString()
wouterj commentedDec 28, 2013
@fabbot everything is now fixed and rebased |
wouterj commentedDec 28, 2013
doc issue:symfony/symfony-docs#3397 |
fabpot commentedDec 28, 2013
apparently, tests are broken |
wouterj commentedDec 28, 2013
I'm now stuck... Maybe someone can help me? When using the RecursiveIterator directly, it should only return the However, in the Imagine array( [0] =>FormError instance (...), [child] =>FormErrorBag instance (...)) When iterating, the following things happen:
In the 5th step it should not have returned the How can we fix this, so that the 5th step isn't executed? We can't add a test on instance in the |
igorw commentedDec 28, 2013
From what I can tell, you really have two different cases. And you should not be trying to make both work with the same iterator instance. The original iterator is a FormErrorBag that may recursively contain other FormErrorBag instances. I'll call it Case A is looking at the top level errors only. In simple terms, this means Case B is recursively walking over over the nested So what you really want is |
igorw commentedDec 28, 2013
After looking at the current implementation I can also pinpoint the problem. It is calling What it comes down to is this. Currently, you are trying to do the recursion inside |
wouterj commentedDec 30, 2013
I think you right@igorw we can't mix them into one class. It would be nice if we could though... However, we have to be BC with an array, so I propose to have a @bschussek I'd love to hear your opinion about this. 🎆 |
wouterj commentedDec 31, 2013
Closing in favor of#9914 |
The only BC break in this PR is checking it with is_array. Iterating
over the array works just the same as previously:
RecursiveIteratorresults in onlyiterating over the errors of the current form.
RecursiveIteratorIteratorresults in iterating overall errors recursively.
Todo
__toString()support and deprecatingForm::getErrorsAsString().Form:getErrors()