8000 feature #8224 [Form][2.4] added an option for multiple files upload (… · symfony/symfony@67ae8fa · GitHub
[go: up one dir, main page]

Skip to content

Commit 67ae8fa

Browse files
committed
feature #8224 [Form][2.4] added an option for multiple files upload (closes #1400) (bamarni)
This PR was squashed before being merged into the 2.5-dev branch (closes #8224). Discussion ---------- [Form][2.4] added an option for multiple files upload (closes #1400) | Q | A | ------------- | --- | Bug fix? | [no] | New feature? | [yes] | BC breaks? | [no] | Deprecations? | [no] | Tests pass? | [yes] | Fixed tickets | [#1400] | License | MIT | Doc PR | [todo] Commits ------- c8c6448 [Form][2.4] added an option for multiple files upload (closes #1400)
2 parents c1051d5 + c8c6448 commit 67ae8fa

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

src/Symfony/Component/Form/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
2.5.0
5+
------
6+
7+
* added an option for multiple files upload
8+
49
2.4.0
510
-----
611

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ class FileType extends AbstractType
2323
*/
2424
public function buildView(FormView $view, FormInterface $form, array $options)
2525
{
26+
if ($options['multiple']) {
27+
$view->vars['full_name'] .= '[]';
28+
$view->vars['attr']['multiple'] = 'multiple';
29+
}
30+
2631
$view->vars = array_replace($view->vars, array(
2732
'type' => 'file',
2833
'value' => '',
@@ -48,6 +53,7 @@ public function setDefaultOptions(OptionsResolverInterface $resolver)
4853
'compound' => false,
4954
'data_class' => 'Symfony\Component\HttpFoundation\File\File',
5055
'empty_data' => null,
56+
'multiple' => false,
5157
));
5258
}
5359

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,25 @@ public function testSubmitEmpty()
4444
$this->assertNull($form->getData());
4545
}
4646

47+
public function testSubmitMultiple()
48+
{
49+
$form = $this->factory->createBuilder('file', null, array(
50+
'multiple' => true
51+
))->getForm();
52+
53+
$data = array(
54+
$this->createUploadedFileMock('abcdef', 'first.jpg', true),
55+
$this->createUploadedFileMock('zyxwvu', 'second.jpg', true),
56+
);
57+
58+
$form->submit($data);
59+
$this->assertSame($data, $form->getData());
60+
61+
$view = $form->createView();
62+
$this->assertSame('file[]', $view->vars['full_name']);
63+
$this->assertArrayHasKey('multiple', $view->vars['attr']);
64+
}
65+
4766
public function testDontPassValueToView()
4867
{
4968
$form = $this->factory->create('file');

0 commit comments

Comments
 (0)
0