[BUGFIX] Allow to upload online media via file list 47/54847/4
authorBenni Mack <benni@typo3.org>
Wed, 29 Nov 2017 08:48:00 +0000 (09:48 +0100)
committerSusanne Moog <susanne.moog@typo3.org>
Wed, 29 Nov 2017 09:04:28 +0000 (10:04 +0100)
It was not possible due to a form name mixup to add online media files
via the FileList in TYPO3 v9 anymore.

Related: #82436
Related: #81763
Resolves: #83151
Releases: master
Change-Id: Ica0ed049f685bf20b98f0a599adf61ec3874017a
Reviewed-on: https://review.typo3.org/54847
Reviewed-by: Andreas Fernandez <typo3@scripting-base.de>
Tested-by: Andreas Fernandez <typo3@scripting-base.de>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Susanne Moog <susanne.moog@typo3.org>
Tested-by: Susanne Moog <susanne.moog@typo3.org>
typo3/sysext/backend/Classes/Controller/OnlineMediaController.php
typo3/sysext/backend/Resources/Private/Templates/File/CreateFolder.html
typo3/sysext/recordlist/Classes/View/FolderUtilityRenderer.php

index 68898d8..da17237 100644 (file)
@@ -16,6 +16,7 @@ namespace TYPO3\CMS\Backend\Controller;
 
 use Psr\Http\Message\ResponseInterface;
 use Psr\Http\Message\ServerRequestInterface;
+use TYPO3\CMS\Core\Http\RedirectResponse;
 use TYPO3\CMS\Core\Localization\LanguageService;
 use TYPO3\CMS\Core\Messaging\FlashMessage;
 use TYPO3\CMS\Core\Messaging\FlashMessageService;
@@ -56,15 +57,15 @@ class OnlineMediaController
     }
 
     /**
-     * Process add media request
+     * Process add media request, and redirects to the previous page
      *
      * @param ServerRequestInterface $request
-     * @param ResponseInterface $response
      * @return ResponseInterface
      */
-    public function mainAction(ServerRequestInterface $request, ResponseInterface $response)
+    public function mainAction(ServerRequestInterface $request)
     {
-        $files = $request->getParsedBody()['file'];
+        $files = $request->getParsedBody()['data'];
+        $redirect = $request->getParsedBody()['redirect'];
         $newMedia = [];
         if (isset($files['newMedia'])) {
             $newMedia = (array)$files['newMedia'];
@@ -92,18 +93,18 @@ class OnlineMediaController
                     );
                 }
                 $this->addFlashMessage($flashMessage);
+                if (empty($redirect) && $media['redirect']) {
+                    $redirect = $media['redirect'];
+                }
             }
         }
 
-        $redirect = isset($request->getParsedBody()['redirect']) ? $request->getParsedBody()['redirect'] : $request->getQueryParams()['redirect'];
         $redirect = GeneralUtility::sanitizeLocalUrl($redirect);
         if ($redirect) {
-            $response = $response
-                ->withHeader('Location', GeneralUtility::locationHeaderUrl($redirect))
-                ->withStatus(303);
+            return new RedirectResponse($redirect, 303);
         }
 
-        return $response;
+        throw new \RuntimeException('No redirect after uploading a media found, probably a mis-use of the template not sending the proper Return URL.', 1511945040);
     }
 
     /**
index b4045c5..2bf66a9 100644 (file)
@@ -62,7 +62,7 @@
                 </div>
                 <div class="form-group">
                     <input class="btn btn-default" type="submit" value="{f:translate(key: 'LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:online_media.new_media.submit')}" />
-                    <input type="hidden" name="data[newMedia][0][redirect]" value="{returnUrl}" />
+                    <input type="hidden" name="redirect" value="{returnUrl}" />
                 </div>
             </div>
         </form>
index b65d4fd..ca212c1 100644 (file)
@@ -219,7 +219,7 @@ class FolderUtilityRenderer
             $markup[] = implode(' ', $fileExtList);
             $markup[] = '</div>';
             $markup[] = '</div>';
-            $markup[] = '<input type="hidden" name="data[newMedia][0][redirect]" value="' . htmlspecialchars($redirectValue) . '" />';
+            $markup[] = '<input type="hidden" name="redirect" value="' . htmlspecialchars($redirectValue) . '" />';
             $markup[] = '</form>';
 
             $code .= implode(LF, $markup);