[Form][2.4] added an option for multiple files upload (closes #1400)

This commit is contained in:
Bilal Amarni 2013-06-07 16:12:58 +02:00 committed by Fabien Potencier
parent ea913e07e5
commit c8c6448168
3 changed files with 29 additions and 0 deletions

View File

@ -1,6 +1,10 @@
CHANGELOG
=========
2.5.0
------
* added an option for multiple files upload
2.3.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');