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
[Form] weaken the rejection of submitted array data #29911
Conversation
@@ -328,6 +328,8 @@ public function configureOptions(OptionsResolver $resolver) | |||
'placeholder' => $placeholderDefault, | |||
'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 like accept_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 a TextType
.
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
?
Will that make the reported breaks work again? Eg submitting a json-decoded array in a TextType? |
which PR are you talking about? 🤔 |
@OskarStark See #29809 for the main discussion triggered by PR #29307 . |
What'd the behaviour of the |
@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 UnstructuredType extends AbstractType
{
} @althaus Yes, if you are not explicitly about the type being used and the |
@xabbuh if I'm interpereting it correctly I could use for unstructured data this then: use Symfony\Component\Form\Extension\Core\Type\FormType;
$builder->add('some_unstructured_data', FormType::class'); |
@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'], |
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',
]
]
]
@xabbuh will test it in the application at the evening. Thank you for having a look at the issue! |
@alexander-schranz makes sense, done |
@@ -37,6 +37,7 @@ public function configureOptions(OptionsResolver $resolver) | |||
{ | |||
$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.
I'm not sure at all we should do this change. |
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. |
True that, but even big bundles like RestBundle using that "hack" and recommend it in their docs. |
time to fix them! |
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? |
@dmaicher Basically yes, except that the type could be shortened to not have to include the |
closing here as it doesn't look like the proposed change is of interest |
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_values
option. This value will benull
by default which means no checks will be performed for backwards compatibility. The core form types do explicitly set this value tofalse
if 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
null
default value so that each type must opt for eithertrue
orfalse
as the value in 5.0.