Skip to content

Commit

Permalink
bug #25102 [Form] Fixed ContextErrorException in FileType (chihiro-ad…
Browse files Browse the repository at this point in the history
…achi)

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
  • Loading branch information
nicolas-grekas committed Nov 23, 2017
2 parents e2add8b + 1b408e6 commit a809ab2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Symfony/Component/Form/Extension/Core/Type/FileType.php
Expand Up @@ -34,8 +34,13 @@ public function buildForm(FormBuilderInterface $builder, array $options)

if ($options['multiple']) {
$data = array();
$files = $event->getData();

foreach ($event->getData() as $file) {
if (!is_array($files)) {
$files = array();
}

foreach ($files as $file) {
if ($requestHandler->isFileUpload($file)) {
$data[] = $file;
}
Expand Down
Expand Up @@ -158,6 +158,24 @@ public function testMultipleSubmittedFilePathsAreDropped(RequestHandlerInterface
$this->assertCount(1, $form->getData());
}

/**
* @dataProvider requestHandlerProvider
*/
public function testSubmitNonArrayValueWhenMultiple(RequestHandlerInterface $requestHandler)
{
$form = $this->factory
->createBuilder(static::TESTED_TYPE, null, array(
'multiple' => true,
))
->setRequestHandler($requestHandler)
->getForm();
$form->submit(null);

$this->assertSame(array(), $form->getData());
$this->assertSame(array(), $form->getNormData());
$this->assertSame(array(), $form->getViewData());
}

public function requestHandlerProvider()
{
return array(
Expand Down

0 comments on commit a809ab2

Please sign in to comment.