[BUGFIX] Streamline creating text files in filelist module 10/59410/2
authorAnja Leichsenring <aleichsenring@ab-softlab.de>
Fri, 11 Jan 2019 14:01:02 +0000 (15:01 +0100)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Fri, 11 Jan 2019 15:05:54 +0000 (16:05 +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/59410
Tested-by: TYPO3com <noreply@typo3.com>
Reviewed-by: Mona Muzaffar <mona.muzaffar@gmx.de>
Tested-by: Mona Muzaffar <mona.muzaffar@gmx.de>
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/lang/Resources/Private/Language/locallang_core.xlf

index 70ce8eb..5f1c5b0 100644 (file)
@@ -20,6 +20,7 @@ use TYPO3\CMS\Backend\Utility\BackendUtility;
 use TYPO3\CMS\Core\Imaging\Icon;
 use TYPO3\CMS\Core\Imaging\IconFactory;
 use TYPO3\CMS\Core\Resource\DuplicationBehavior;
+use TYPO3\CMS\Core\Resource\File;
 use TYPO3\CMS\Core\Resource\Folder;
 use TYPO3\CMS\Core\Utility\File\ExtendedFileUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
@@ -166,16 +167,9 @@ class FileController
 
         // go and edit the new created file
         if ($request->getParsedBody()['edit']) {
-            /** @var \TYPO3\CMS\Core\Resource\File $file */
+            /** @var File $file */
             $file = $this->fileData['newfile'][0];
-            $properties = $file->getProperties();
-            $urlParameters = [
-                'target' =>  $properties['storage'] . ':' . $properties['identifier']
-            ];
-            if ($this->redirect) {
-                $urlParameters['returnUrl'] = $this->redirect;
-            }
-            $this->redirect = BackendUtility::getModuleUrl('file_edit', $urlParameters);
+            $this->redirect = $this->getFileEditRedirect($file) ?? $this->redirect;
         }
         if ($this->redirect) {
             return $response
@@ -187,6 +181,29 @@ 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)
+    {
+        $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;
+        }
+        return BackendUtility::getModuleUrl('file_edit', $urlParameters);
+    }
+
+    /**
      * Handles the actual process from within the ajaxExec function
      * therefore, it does exactly the same as the real typo3/tce_file.php
      * but without calling the "finish" method, thus makes it simpler to deal with the
@@ -254,12 +271,12 @@ class FileController
      *
      * The value can be a File, Folder or boolean
      *
-     * @param bool|\TYPO3\CMS\Core\Resource\File|\TYPO3\CMS\Core\Resource\Folder $result
+     * @param bool|File|\TYPO3\CMS\Core\Resource\Folder $result
      * @return bool|string|array
      */
     protected function flattenResultDataValue($result)
     {
-        if ($result instanceof \TYPO3\CMS\Core\Resource\File) {
+        if ($result instanceof File) {
             $thumbUrl = '';
             if (GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], $result->getExtension())) {
                 $processedFile = $result->process(\TYPO3\CMS\Core\Resource\ProcessedFile::CONTEXT_IMAGEPREVIEW, []);
index b6769e8..1991d60 100644 (file)
@@ -79,7 +79,7 @@
                                     <input type="hidden" name="file[newfile][0][target]" value="{target}" />
                                 </div>
                                 <div class="help-block">
-                                    <f:translate key="LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:cm.allowedFileExtensions" /><br>
+                                    <f:translate key="LLL:EXT:lang/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 5dc6ce7..65576dd 100644 (file)
@@ -1101,6 +1101,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>