-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Form] Filter arrays out of scalar form types #29307
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
Conversation
src/Symfony/Component/Form/Extension/Core/Type/CollectionType.php
Outdated
Show resolved
Hide resolved
b7da2a5
to
8281731
Compare
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.
Thanks! Finally closing this old issue 🎉
f3d312f
to
60faaf1
Compare
Now with tests, ready. |
60faaf1
to
f78eaa3
Compare
@@ -93,14 +93,6 @@ public function testThrowExceptionIfDefaultProtocolIsInvalid() | |||
)); | |||
} | |||
|
|||
public function testSubmitWithNonStringDataDoesNotBreakTheFixUrlProtocolListener() |
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.
Interesting test 😄
"multiple" is exactly the info we're missing to decide if we allow arrays or not: form types that know how to deal with array of values don't have to be compound, and "multiple" is their way to express they still deal with arrays. Note that this is already what we use, that's why the patch is so simple yet it works and tests are green. |
Can we check if the type is actual multiple, i.e. Is the same check needed vice versa? If the submitted data is scalar and the type is compound/multiple? |
@ro0NL that's how I first wrote the patch, but the tests broke all around. The reason is that we don't need to decide if arrays are allowed. Instead we need to decide if arrays are dealt with at the form type level. All form types that declare multiple true/false can do that. |
c377561
to
d7faca2
Compare
d7faca2
to
000e4aa
Compare
rebased - ready |
…kas) This PR was merged into the 3.4 branch. Discussion ---------- [Form] Filter arrays out of scalar form types | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #4102 | License | MIT | Doc PR | - Replaces fix #20935 Commits ------- 000e4aa [Form] Filter arrays out of scalar form types
…nges (Zales0123) This PR was merged into the 1.2 branch. Discussion ---------- | Q | A | --------------- | ----- | Branch? | 1.2 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Related tickets | related to symfony/symfony#29307 | License | MIT Due to the latest Symfony 4.1.10/3.4.21 release and changes introduced in linked PR, a bug in select attribute type araised 🌤 Apparently, possible to select values in attribute configuration was saved with `TextType` form type, even though `SelectAttributeValueTranslationsType` should be used. It was somehow parsed before, but know it's not possible and this PR fixes this absurdity 🖖 Commits ------- 51f7ec2 Fix select attributes according to recent Symfony form changes b80fa00 Fix test in ResourceBundle (taken from #10062)
…nges (Zales0123) This PR was merged into the 1.2 branch. Discussion ---------- | Q | A | --------------- | ----- | Branch? | 1.2 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Related tickets | related to symfony/symfony#29307 | License | MIT Due to the latest Symfony 4.1.10/3.4.21 release and changes introduced in linked PR, a bug in select attribute type araised 🌤 Apparently, possible to select values in attribute configuration was saved with `TextType` form type, even though `SelectAttributeValueTranslationsType` should be used. It was somehow parsed before, but know it's not possible and this PR fixes this absurdity 🖖 Commits ------- 51f7ec2481d67270ed66b9879fc57702e4fafb76 Fix select attributes according to recent Symfony form changes b80fa003a4a279c9204465b6189027db50c2285e Fix test in ResourceBundle (taken from #10062)
…nges (Zales0123) This PR was merged into the 1.2 branch. Discussion ---------- | Q | A | --------------- | ----- | Branch? | 1.2 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Related tickets | related to symfony/symfony#29307 | License | MIT Due to the latest Symfony 4.1.10/3.4.21 release and changes introduced in linked PR, a bug in select attribute type araised 🌤 Apparently, possible to select values in attribute configuration was saved with `TextType` form type, even though `SelectAttributeValueTranslationsType` should be used. It was somehow parsed before, but know it's not possible and this PR fixes this absurdity 🖖 Commits ------- 51f7ec2481d67270ed66b9879fc57702e4fafb76 Fix select attributes according to recent Symfony form changes b80fa003a4a279c9204465b6189027db50c2285e Fix test in ResourceBundle (taken from #10062)
I was using the type of |
I'm on the same situation. Things worked before this update |
This code can help you to bind an array with a TextType by serializing the array before the submit. $builder->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) {
$event->setData(array_map(function ($value) {
return serialize($value);
}, $event->getData()));
}) |
Replaces fix #20935