[BUGFIX] Streamline creating text files in filelist module 03/59303/3
authorOliver Hader <oliver@typo3.org>
Fri, 28 Dec 2018 15:06:15 +0000 (16:06 +0100)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Fri, 11 Jan 2019 13:24:37 +0000 (14:24 +0100)
The filelist module allows to create files and redirects to an
according editing view in case the file extension is configured
in $GLOBALS['TYPO3_CONF_VARS']['SYS']['textfile_ext']. However,
any file - except those in file-deny pattern - can be created,
but only text files can be edited directly.

Since this was kind of misleading, creating any file is still
possible, however there's no redirect anymore in case it's not
a text file. Wording in filelist module's view has been adjusted.

Resolves: #72404
Releases: master, 9.5, 8.7
Change-Id: Ibb48769aa571e880d0f5f58cfb650cade3cdb1e0
Reviewed-on: https://review.typo3.org/59303
Tested-by: TYPO3com <noreply@typo3.com>
Reviewed-by: Jörg Bösche <typo3@joergboesche.de>
Reviewed-by: Mona Muzaffar <mona.muzaffar@gmx.de>
Tested-by: Mona Muzaffar <mona.muzaffar@gmx.de>
Reviewed-by: Stefanos Karasavvidis <sk@karasavvidis.gr>
Tested-by: Stefanos Karasavvidis <sk@karasavvidis.gr>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
typo3/sysext/backend/Classes/Controller/File/FileController.php
typo3/sysext/backend/Resources/Private/Templates/File/CreateFolder.html
typo3/sysext/core/Resources/Private/Language/locallang_core.xlf

index 1f19c12..a9dcdde 100644 (file)
@@ -124,15 +124,7 @@ class FileController
         if ($request->getParsedBody()['edit'] ?? '') {
             /** @var File $file */
             $file = $this->fileData['newfile'][0];
-            $properties = $file->getProperties();
-            $urlParameters = [
-                'target' =>  $properties['storage'] . ':' . $properties['identifier']
-            ];
-            if ($this->redirect) {
-                $urlParameters['returnUrl'] = $this->redirect;
-            }
-            $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
-            $this->redirect = (string)$uriBuilder->buildUriFromRoute('file_edit', $urlParameters);
+            $this->redirect = $this->getFileEditRedirect($file) ?? $this->redirect;
         }
         if ($this->redirect) {
             return new RedirectResponse(
@@ -262,6 +254,30 @@ class FileController
     }
 
     /**
+     * Gets URI to be used for editing given file (if file extension is defined in textfile_ext)
+     *
+     * @param File $file to be edited
+     * @return string|null URI to be redirected to
+     * @throws \TYPO3\CMS\Backend\Routing\Exception\RouteNotFoundException
+     */
+    protected function getFileEditRedirect(File $file): ?string
+    {
+        $textFileExtensionList = $GLOBALS['TYPO3_CONF_VARS']['SYS']['textfile_ext'] ?? '';
+        if (!GeneralUtility::inList($textFileExtensionList, $file->getExtension())) {
+            return null;
+        }
+        $properties = $file->getProperties();
+        $urlParameters = [
+            'target' =>  $properties['storage'] . ':' . $properties['identifier']
+        ];
+        if ($this->redirect) {
+            $urlParameters['returnUrl'] = $this->redirect;
+        }
+        $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
+        return (string)$uriBuilder->buildUriFromRoute('file_edit', $urlParameters);
+    }
+
+    /**
      * Redirecting the user after the processing has been done.
      * Might also display error messages directly, if any.
      *
index d23bf5f..8875a05 100644 (file)
@@ -81,7 +81,7 @@
                                     <input type="hidden" name="data[newfile][0][target]" value="{target}" />
                                 </div>
                                 <div class="help-block">
-                                    <f:translate key="LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:cm.allowedFileExtensions" /><br>
+                                    <f:translate key="LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:cm.allowedEditableTextFileExtensions" /><br>
                                     <f:for each="{txtFileExtList}" as="fileExt">
                                         <span class="label label-success">{fileExt}</span>
                                     </f:for>
index 260e726..a88561d 100644 (file)
@@ -1120,6 +1120,9 @@ Do you want to refresh it now?</source>
                        <trans-unit id="cm.allowedFileExtensions">
                                <source>Allowed file extensions</source>
                        </trans-unit>
+                       <trans-unit id="cm.allowedEditableTextFileExtensions">
+                               <source>Allowed editable text file extensions</source>
+                       </trans-unit>
                        <trans-unit id="cm.allowEmbedSources">
                                <source>Allowed media sources</source>
                        </trans-unit>