-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Form with an EntityType field with multiple=true giving back array and ArrayCollection #23927
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
Comments
I don't understand it completely, but it seems like you're using an EntityType while you should be using a collection type of sorts? |
I added two tests here #23930 |
AFAIK the initial & expected data for Even though, an symfony/src/Symfony/Component/Form/Extension/Core/EventListener/MergeCollectionListener.php Lines 61 to 62 in 1732cc8
Hence Later, you'll needs take care about ambiguous data type resultant. |
However, I think passing an This is where that's not true - when an empty symfony/src/Symfony/Component/Form/Extension/Core/EventListener/MergeCollectionListener.php Lines 83 to 87 in 1732cc8
then the result will be an empty Status: Confirmed |
The solution to be consistent with default data type provided: symfony/src/Symfony/Component/Form/Extension/Core/EventListener/MergeCollectionListener.php Line 83 in 1732cc8
- if (!$dataToMergeInto) {
+ if (null === $dataToMergeInto) { and the resulting data type should be consistent:
@stoccc could you try it? |
@yceruto OK, it works. If I give an |
@stoccc If you prefer, you can provide the fix and update your PR, or let me know to submit a new one :) |
@yceruto ok, I committed your changes |
I have same problem with Symfony 3.3.6 (PHP 5.6) |
…field with multiple=true (stoccc) This PR was squashed before being merged into the 2.7 branch (closes #23980). Discussion ---------- Tests and fix for issue in array model data in EntityType field with multiple=true | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | License | MIT | Fixed tickets | #23927 Provided some tests and the fix for #23927. Rebased to 2.7, replaces #23930 Commits ------- aaba6b4 Tests and fix for issue in array model data in EntityType field with multiple=true
I have a strange behaviour with a form (mapped to an
array
, not to a Entity) containing a field of typeEntityType
withmultiple=true
.If I set that field with initial data an empty
array
, e.g.array()
, after successful submit when I call$form->getData()
I get anArrayCollection
for that field.Instead, if I set that field with initial data a non empty
array
, after a successful submit when I call$form->getData()
I get a simplearray
for that field.Shouldn't I obtain always the same type?
The text was updated successfully, but these errors were encountered: