8000 bug #25102 [Form] Fixed ContextErrorException in FileType (chihiro-ad… · symfony/symfony@a809ab2 · GitHub
[go: up one dir, main page]

Skip to content

Commit a809ab2

Browse files
bug #25102 [Form] Fixed ContextErrorException in FileType (chihiro-adachi)
This PR was squashed before being merged into the 2.7 branch (closes #25102). Discussion ---------- [Form] Fixed ContextErrorException in FileType | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #25063 | License | MIT | Doc PR | -- Fixed an issue that ContextErrorException occurs when multiple is enabled. Commits ------- 1b408e6 [Form] Fixed ContextErrorException in FileType
2 parents e2add8b + 1b408e6 commit a809ab2

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/Symfony/Component/Form/Extension/Core/Type/FileType.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,13 @@ public function buildForm(FormBuilderInterface $builder, array $options)
3434

3535
if ($options['multiple']) {
3636
$data = array();
37+
$files = $event->getData();
3738

38-
foreach ($event->getData() as $file) {
39+
if (!is_array($files)) {
40+
$files = array();
41+
}
42+
43+
foreach ($files as $file) {
3944
if ($requestHandler->isFileUpload($file)) {
4045
$data[] = $file;
4146
}

src/Symfony/Component/Form/Tests/Extension/Core/Type/FileTypeTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,24 @@ public function testMultipleSubmittedFilePathsAreDropped(RequestHandlerInterface
158158
$this->assertCount(1, $form->getData());
159159
}
160160

161+
/**
162+
* @dataProvider requestHandlerProvider
163+
*/
164+
public function testSubmitNonArrayValueWhenMultiple(RequestHandlerInterface $requestHandler)
165+
{
166+
$form = $this->factory
167+
->createBuilder(static::TESTED_TYPE, null, array(
168+
'multiple' => true,
169+
))
170+
->setRequestHandler($requestHandler)
171+
->getForm();
172+
$form->submit(null);
173+
174+
$this->assertSame(array(), $form->getData());
175+
$this->assertSame(array(), $form->getNormData());
176+
$this->assertSame(array(), $form->getViewData());
177+
}
178+
161179
public function requestHandlerProvider()
162180
{
163181
return array(

0 commit comments

Comments
 (0)
0