[FEATURE] Add attribute "multiple" to f:form.upload viewhelper. 94/33194/7
authorJost Baron <jost@netzkoenig.de>
Tue, 7 Oct 2014 20:26:45 +0000 (22:26 +0200)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Sun, 18 Jan 2015 13:37:05 +0000 (14:37 +0100)
This makes it possible to upload multiple files with one upload field.

Resolves: #47666
Releases: master
Change-Id: If048a75d20472ee4bedbd64912a4f2d4a5c0205d
Reviewed-on: http://review.typo3.org/33194
Reviewed-by: Helmut Hummel <helmut.hummel@typo3.org>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
typo3/sysext/core/Documentation/Changelog/master/Feature-47666-AttributeMulitpleForFormUploadViewhelper.rst [new file with mode: 0644]
typo3/sysext/fluid/Classes/ViewHelpers/Form/UploadViewHelper.php
typo3/sysext/fluid/Tests/Unit/ViewHelpers/Form/UploadViewHelperTest.php

diff --git a/typo3/sysext/core/Documentation/Changelog/master/Feature-47666-AttributeMulitpleForFormUploadViewhelper.rst b/typo3/sysext/core/Documentation/Changelog/master/Feature-47666-AttributeMulitpleForFormUploadViewhelper.rst
new file mode 100644 (file)
index 0000000..dbf1660
--- /dev/null
@@ -0,0 +1,17 @@
+=====================================================================
+Feature: #47666 - Attribute \"multiple\" for f:form.upload Viewhelper
+=====================================================================
+
+Description
+===========
+
+The Viewhelper allows now an attribute \"multiple\", that will provide
+a possibility to upload several files at once.
+
+.. code-block:: html
+       <f:form.upload property="files" multiple="multiple" />
+
+Will result in the according HTML tag providing the field content as array.
+
+Be aware, that you need to prepare the incoming value for the property mapping yourself,
+by writing your own TypeConverter.
\ No newline at end of file
index 9ceee33..f5bc9e6 100644 (file)
@@ -51,6 +51,7 @@ class UploadViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormFie
        public function initializeArguments() {
                parent::initializeArguments();
                $this->registerTagAttribute('disabled', 'string', 'Specifies that the input element should be disabled when the page loads');
+               $this->registerTagAttribute('multiple', 'string', 'Specifies that the file input element should allow multiple selection of files');
                $this->registerArgument('errorClass', 'string', 'CSS class to set if there are errors for this view helper', FALSE, 'f3-form-error');
                $this->registerUniversalTagAttributes();
        }
@@ -68,7 +69,13 @@ class UploadViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormFie
                        $this->registerFieldNameForFormTokenGeneration($name . '[' . $fieldName . ']');
                }
                $this->tag->addAttribute('type', 'file');
-               $this->tag->addAttribute('name', $name);
+
+               if (isset($this->arguments['multiple'])) {
+                       $this->tag->addAttribute('name', $name . '[]');
+               } else {
+                       $this->tag->addAttribute('name', $name);
+               }
+
                $this->setErrorClassAttribute();
                return $this->tag->render();
        }
index 1423b69..796d497 100644 (file)
@@ -70,4 +70,22 @@ class UploadViewHelperTest extends \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\
                $this->viewHelper->render();
        }
 
-}
+       /**
+        * @test
+        */
+       public function renderSetsAttributeNameAsArrayIfMultipleIsGiven() {
+               /** @var \TYPO3\CMS\Fluid\Core\ViewHelper\TagBuilder $tagBuilder */
+               $tagBuilder = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Fluid\Core\ViewHelper\TagBuilder::class);
+               $tagBuilder->addAttribute('multiple', 'multiple');
+               $this->viewHelper->_set('tag', $tagBuilder);
+               $arguments = array(
+                       'name' => 'someName',
+                       'multiple' => 'multiple'
+               );
+               $this->viewHelper->setArguments($arguments);
+               $this->viewHelper->initialize();
+               $result = $this->viewHelper->render();
+               $this->assertEquals('<input multiple="multiple" type="file" name="someName[]" />', $result);
+       }
+
+}
\ No newline at end of file