[TASK] Fluidification of ReplaceFileController 26/50726/3
authorMichael Oehlhof <typo3@oehlhof.de>
Thu, 1 Dec 2016 12:27:49 +0000 (13:27 +0100)
committerJan Helke <typo3@helke.de>
Fri, 2 Dec 2016 10:00:21 +0000 (11:00 +0100)
Resolves: #78764
Releases: master
Change-Id: I0cdedd33540a917ba7744f3dad96c7b728967fad
Reviewed-on: https://review.typo3.org/50726
Reviewed-by: Alexander Stehlik <alexander.stehlik@gmail.com>
Tested-by: Alexander Stehlik <alexander.stehlik@gmail.com>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Gianluigi Martino <gmartino27@gmail.com>
Tested-by: Gianluigi Martino <gmartino27@gmail.com>
Reviewed-by: Alexander Rothmund <alexander@rothmund.ch>
Tested-by: Alexander Rothmund <alexander@rothmund.ch>
Reviewed-by: Jan Helke <typo3@helke.de>
Tested-by: Jan Helke <typo3@helke.de>
typo3/sysext/backend/Classes/Controller/File/ReplaceFileController.php
typo3/sysext/backend/Resources/Private/Templates/File/ReplaceFile.html [new file with mode: 0644]

index 76dcefb..2087879 100644 (file)
@@ -24,6 +24,7 @@ use TYPO3\CMS\Core\Resource\Exception\InsufficientFileAccessPermissionsException
 use TYPO3\CMS\Core\Resource\Folder;
 use TYPO3\CMS\Core\Resource\ResourceFactory;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Fluid\View\StandaloneView;
 use TYPO3\CMS\Lang\LanguageService;
 
 /**
@@ -149,52 +150,11 @@ class ReplaceFileController extends AbstractModule
      */
     public function main()
     {
-        $lang = $this->getLanguageService();
-        $code = '<form action="'
-            . htmlspecialchars(BackendUtility::getModuleUrl('tce_file'))
-            . '" role="form" method="post" name="editform" enctype="multipart/form-data">';
-
-        // Making the formfields for renaming:
-        $code .= '
-                       <div class="form-group">
-                               <input type="checkbox" value="1" id="keepFilename" name="file[replace][1][keepFilename]"> <label for="keepFilename">'
-            . $lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:file_replace.php.keepfiletitle')
-            . '</label>
-                       </div>
-
-                       <div class="form-group">
-                               <label for="file_replace">' . $lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:file_replace.php.selectfile') . '</label>
-                               <div class="input-group col-xs-6">
-                                       <input type="text" name="fakefile" id="fakefile" class="form-control input-xlarge" readonly>
-                                       <a class="input-group-addon btn btn-primary" onclick="TYPO3.jQuery(\'#file_replace\').click();">'
-            . $lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:file_replace.php.browse')
-            . '</a>
-                               </div>
-                               <input class="form-control" type="file" id="file_replace" name="replace_1" style="visibility: hidden;" />
-                       </div>
-
-                       <script>
-                       TYPO3.jQuery(\'#file_replace\').change(function(){
-                               TYPO3.jQuery(\'#fakefile\').val(TYPO3.jQuery(this).val());
-                       });
-                       </script>
-
-                       <input type="hidden" name="overwriteExistingFiles" value="replace" />
-                       <input type="hidden" name="file[replace][1][data]" value="1" />
-                       <input type="hidden" name="file[replace][1][uid]" value="' . $this->uid . '" />
-               ';
-        // Making submit button:
-        $code .= '
-                               <div class="form-group">
-                                       <input class="btn btn-primary" type="submit" value="'
-            . htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:file_replace.php.submit')) . '" />
-                                       <input class="btn btn-danger" type="submit" value="'
-            . htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.cancel'))
-            . '" onclick="backToList(); return false;" />
-                                       <input type="hidden" name="redirect" value="' . htmlspecialchars($this->returnUrl) . '" />
-                               </div>
-               ';
-        $code .= '</form>';
+        // Assign variables used by the fluid template
+        $assigns = [];
+        $assigns['moduleUrlTceFile'] = BackendUtility::getModuleUrl('tce_file');
+        $assigns['uid'] = $this->uid;
+        $assigns['returnUrl'] = $this->returnUrl;
 
         $buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
         // csh button
@@ -207,14 +167,20 @@ class ReplaceFileController extends AbstractModule
         if ($this->returnUrl) {
             $returnButton = $buttonBar->makeLinkButton()
                 ->setHref($this->returnUrl)
-                ->setTitle($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.goBack'))
+                ->setTitle($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.goBack'))
                 ->setIcon($this->moduleTemplate->getIconFactory()->getIcon('actions-view-go-back', Icon::SIZE_SMALL));
             $buttonBar->addButton($returnButton);
         }
 
-        $this->content .= '<h1>' . $lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:file_replace.php.pagetitle') . '</h1>';
-        // Add the HTML as a section:
-        $this->content .= '<div>' . $code . '</div>';
+        // Rendering of the output via fluid
+        $view = GeneralUtility::makeInstance(StandaloneView::class);
+        $view->setTemplateRootPaths([GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Templates')]);
+        $view->setPartialRootPaths([GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Partials')]);
+        $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName(
+            'EXT:backend/Resources/Private/Templates/File/ReplaceFile.html'
+        ));
+        $view->assignMultiple($assigns);
+        $this->content = $view->render();
 
         $this->moduleTemplate->setContent($this->content);
     }
diff --git a/typo3/sysext/backend/Resources/Private/Templates/File/ReplaceFile.html b/typo3/sysext/backend/Resources/Private/Templates/File/ReplaceFile.html
new file mode 100644 (file)
index 0000000..5edd477
--- /dev/null
@@ -0,0 +1,37 @@
+<h1><f:translate key="LLL:EXT:lang/locallang_core.xlf:file_replace.php.pagetitle" /></h1>
+<div>
+    <form action="{moduleUrlTceFile}" role="form" method="post" name="editform" enctype="multipart/form-data">
+    <div class="form-group">
+        <input type="checkbox" value="1" id="keepFilename" name="file[replace][1][keepFilename]">
+        <label for="keepFilename"><f:translate key="LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:file_replace.php.keepfiletitle" /></label>
+    </div>
+
+    <div class="form-group">
+        <label for="file_replace"><f:translate key="LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:file_replace.php.selectfile" /></label>
+        <div class="input-group col-xs-6">
+            <input type="text" name="fakefile" id="fakefile" class="form-control input-xlarge" readonly>
+            <a class="input-group-addon btn btn-primary" onclick="TYPO3.jQuery('#file_replace').click();">
+                <f:translate key="LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:file_replace.php.browse" />
+            </a>
+        </div>
+        <input class="form-control" type="file" id="file_replace" name="replace_1" style="visibility: hidden;" />
+    </div>
+
+    <script>
+        TYPO3.jQuery('#file_replace').change(function(){
+        TYPO3.jQuery('#fakefile').val(TYPO3.jQuery(this).val());
+        });
+    </script>
+
+    <input type="hidden" name="overwriteExistingFiles" value="replace" />
+    <input type="hidden" name="file[replace][1][data]" value="1" />
+    <input type="hidden" name="file[replace][1][uid]" value="{uid}" />
+
+    <div class="form-group">
+        <input class="btn btn-primary" type="submit" value="{f:translate(key: 'LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:file_replace.php.submit')}" />
+        <input class="btn btn-danger" type="submit" value="{f:translate(key: 'LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.cancel')}"
+             onclick="backToList(); return false;" />
+        <input type="hidden" name="redirect" value="{returnUrl}" />
+    </div>
+    </form>
+</div>