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] weaken the rejection of submitted array data#29911
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
| 'error_bubbling' =>false, | ||
| 'compound' =>$compound, | ||
| // submitted arrays are dealt with in data transformers | ||
| 'accept_multiple_values' =>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.
Not sure if that's the best name. I could also imagine something likeaccept_array_data.
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.
Suggestion:accept_unstructured_data? "Array" could be mistaken for a flat array without special string keys, just like multiple values on aTextType.
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.
'scalar' => false?
nicolas-grekas commentedJan 17, 2019
Will that make the reported breaks work again? Eg submitting a json-decoded array in a TextType? |
OskarStark commentedJan 17, 2019
which PR are you talking about? 🤔 |
althaus commentedJan 17, 2019 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@OskarStark See#29809 for the main discussion triggered by PR#29307 . |
althaus commentedJan 17, 2019
What'd the behaviour of the |
xabbuh commentedJan 17, 2019
@nicolas-grekas As long as you do not explicitly set the But what this will allow easily again having a custom type like this: class UnstructuredTypeextends AbstractType{} @althaus Yes, if you are not explicitly about the type being used and the |
alexander-schranz commentedJan 17, 2019 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@xabbuh if I'm interpereting it correctly I could use for unstructured data this then: useSymfony\Component\Form\Extension\Core\Type\FormType;$builder->add('some_unstructured_data', FormType::class'); |
xabbuh commentedJan 17, 2019
@alexander-schranz Yes, that should work (that basically is the same as this test:https://github.com/symfony/symfony/pull/29911/files#diff-de65be85a5affed1f499b79d96965419R1062). But I'd be happy if you could confirm that in your application context. |
| $this->form->add($this->getBuilder('foo',null,null, ['compound' =>true])->getForm()); | ||
| $this->form->submit([ | ||
| 'foo' => ['foo'], |
alexander-schranzJan 17, 2019 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
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.
would also add test for a nested array not just a list:
['foo' => ['foo' =>'foo','bar' => ['baz' =>'baz', ] ]]
alexander-schranz commentedJan 17, 2019
@xabbuh will test it in the application at the evening. Thank you for having a look at the issue! |
xabbuh commentedJan 17, 2019
@alexander-schranz makes sense, done |
| { | ||
| $resolver->setDefaults([ | ||
| 'compound' =>false, | ||
| 'accept_multiple_values' =>false, |
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.
@xabbuh this should set to true until 5.0 to avoid the bc break which was introduce in 3.4.21, else applications which did work before 3.4.21 still would crash.
nicolas-grekas commentedJan 21, 2019
I'm not sure at all we should do this change. |
althaus commentedJan 21, 2019
I'm pretty sure that 9 out of 10 didn't do this on purpose, but either by accident or due to lacking docs back then. The Form component really can be a b**ch sometimes. It's the only one forcing us to rework code parts every now and then due to some "fix". :/ I can also see that adding a fire-and-forget option just for this small thing on all those classes could raise more headache than it solves. So I'd be glad if someone can imagine a solution working for both sides. |
fnagel commentedJan 21, 2019
True that, but even big bundles like RestBundle using that "hack" and recommend it in their docs. |
nicolas-grekas commentedJan 21, 2019
time to fix them! |
dmaicher commentedJan 21, 2019
I'm also not sure I would fix this by adding another option. I find it too confusing to have
In the end the fix for all affected users would be something like this here, or not? |
xabbuh commentedJan 21, 2019
@dmaicher Basically yes, except that the type could be shortened to not have to include the |
xabbuh commentedJan 25, 2019
closing here as it doesn't look like the proposed change is of interest |
Uh oh!
There was an error while loading.Please reload this page.
It seems that the bugfix made in#29307 seems to break quite some applications. I therefore suggest that we solve the issue a bit different by introducing a new
accept_multiple_valuesoption. This value will benullby default which means no checks will be performed for backwards compatibility. The core form types do explicitly set this value tofalseif they expect the submitted data to be strings. If a form is compound, the option value will automatically default totrue.Since from my experience most custom form types have child forms, they are already compound and so do accept arrays. Nothing will change for them. Other custom types will not have the check as long as they do not extend one of the built-in types that have this check enabled.
In Symfony 4.3 we can then deprecate the
nulldefault value so that each type must opt for eithertrueorfalseas the value in 5.0.