[BUGFIX] Respect empty allowedMimeTypes for file uploads 97/56197/2
authorRalf Zimmermann <ralf.zimmermann@tritum.de>
Thu, 22 Feb 2018 23:13:26 +0000 (00:13 +0100)
committerAlexander Opitz <opitz.alexander@googlemail.com>
Wed, 2 May 2018 12:35:04 +0000 (14:35 +0200)
Make it possible to allow all mime types (except php) within file upload
form elements.
Since there are some default mime types configured within the ext:form
standard setup, you have to remove this default mime types within your
form definition (or reconfigure the default values within your custom
ext:form setup).

FileUpload:

properties:
  allowedMimeTypes:
    0: null
    1: null
    2: null
    3: null

ImageUpload:

properties:
  allowedMimeTypes:
    0: null
    1: null
    2: null

Releases: master, 8.7
Resolves: #82670
Change-Id: Ifa07cceb47978b913f36b8607d4df4724ae22eef
Reviewed-on: https://review.typo3.org/56197
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Stephan GroƟberndt <stephan.grossberndt@typo3.org>
Reviewed-by: Ralf Zimmermann <ralf.zimmermann@tritum.de>
Reviewed-by: Frank Naegler <frank.naegler@typo3.org>
Tested-by: Frank Naegler <frank.naegler@typo3.org>
Reviewed-by: Alexander Opitz <opitz.alexander@googlemail.com>
Tested-by: Alexander Opitz <opitz.alexander@googlemail.com>
typo3/sysext/form/Classes/Mvc/Property/PropertyMappingConfiguration.php

index 9adf724..17cc24d 100644 (file)
@@ -1,5 +1,5 @@
 <?php
-declare(strict_types=1);
+declare(strict_types = 1);
 namespace TYPO3\CMS\Form\Mvc\Property;
 
 /*
@@ -53,11 +53,21 @@ class PropertyMappingConfiguration
             /** @var \TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration $propertyMappingConfiguration */
             $propertyMappingConfiguration = $renderable->getRootForm()->getProcessingRule($renderable->getIdentifier())->getPropertyMappingConfiguration();
 
-            $mimeTypeValidator = GeneralUtility::makeInstance(ObjectManager::class)
-                ->get(MimeTypeValidator::class, ['allowedMimeTypes' => $renderable->getProperties()['allowedMimeTypes']]);
+            $allowedMimeTypes = [];
+            $validators = [];
+
+            if (is_array($renderable->getProperties()['allowedMimeTypes'])) {
+                $allowedMimeTypes = array_filter($renderable->getProperties()['allowedMimeTypes']);
+            }
+
+            if (!empty($allowedMimeTypes)) {
+                $mimeTypeValidator = GeneralUtility::makeInstance(ObjectManager::class)
+                    ->get(MimeTypeValidator::class, ['allowedMimeTypes' => $renderable->getProperties()['allowedMimeTypes']]);
+                $validators = [$mimeTypeValidator];
+            }
 
             $uploadConfiguration = [
-                UploadedFileReferenceConverter::CONFIGURATION_FILE_VALIDATORS => [$mimeTypeValidator],
+                UploadedFileReferenceConverter::CONFIGURATION_FILE_VALIDATORS => $validators,
                 UploadedFileReferenceConverter::CONFIGURATION_UPLOAD_CONFLICT_MODE => 'rename',
             ];