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)
This commit is contained in:
Fabien Potencier 2013-12-17 13:58:30 +01:00
commit 67ae8fab19
3 changed files with 30 additions and 0 deletions

View File

@ -1,6 +1,11 @@
CHANGELOG
=========
2.5.0
------
* added an option for multiple files upload
2.4.0
-----

View File

@ -23,6 +23,11 @@ class FileType extends AbstractType
*/
public function buildView(FormView $view, FormInterface $form, array $options)
{
if ($options['multiple']) {
$view->vars['full_name'] .= '[]';
$view->vars['attr']['multiple'] = 'multiple';
}
$view->vars = array_replace($view->vars, array(
'type' => 'file',
'value' => '',
@ -48,6 +53,7 @@ class FileType extends AbstractType
'compound' => false,
'data_class' => 'Symfony\Component\HttpFoundation\File\File',
'empty_data' => null,
'multiple' => false,
));
}

View File

@ -44,6 +44,25 @@ class FileTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
$this->assertNull($form->getData());
}
public function testSubmitMultiple()
{
$form = $this->factory->createBuilder('file', null, array(
'multiple' => true
))->getForm();
$data = array(
$this->createUploadedFileMock('abcdef', 'first.jpg', true),
$this->createUploadedFileMock('zyxwvu', 'second.jpg', true),
);
$form->submit($data);
$this->assertSame($data, $form->getData());
$view = $form->createView();
$this->assertSame('file[]', $view->vars['full_name']);
$this->assertArrayHasKey('multiple', $view->vars['attr']);
}
public function testDontPassValueToView()
{
$form = $this->factory->create('file');