[TASK] Use ModuleTemplateAPI for Controller\File\ReplaceFileController 67/43967/6
authorroman.schuermann <roman.schuermann@wmdb.de>
Sat, 10 Oct 2015 16:35:58 +0000 (18:35 +0200)
committerWouter Wolters <typo3@wouterwolters.nl>
Sun, 11 Oct 2015 21:31:50 +0000 (23:31 +0200)
Releases: master
Resolves: #70409
Change-Id: Ib49619c4b8e1eb004676d219a05930bc036a4e12
Reviewed-on: http://review.typo3.org/43967
Reviewed-by: Mathias Schreiber <mathias.schreiber@wmdb.de>
Tested-by: Mathias Schreiber <mathias.schreiber@wmdb.de>
Reviewed-by: Roman Schürmann <roman.schuermann@wmdb.de>
Tested-by: Roman Schürmann <roman.schuermann@wmdb.de>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
typo3/sysext/backend/Classes/Controller/File/ReplaceFileController.php
typo3/sysext/backend/Resources/Private/Templates/file_replace.html [deleted file]

index a846259..5e6445a 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 namespace TYPO3\CMS\Backend\Controller\File;
 
-/**
+/*
  * This file is part of the TYPO3 CMS project.
  *
  * It is free software; you can redistribute it and/or modify it under
@@ -14,7 +14,7 @@ namespace TYPO3\CMS\Backend\Controller\File;
  * The TYPO3 project - inspiring people to share!
  */
 
-use TYPO3\CMS\Backend\Template\DocumentTemplate;
+use TYPO3\CMS\Backend\Module\AbstractModule;
 use TYPO3\CMS\Backend\Utility\BackendUtility;
 use TYPO3\CMS\Core\Imaging\Icon;
 use TYPO3\CMS\Core\Imaging\IconFactory;
@@ -29,8 +29,9 @@ use Psr\Http\Message\ServerRequestInterface;
 /**
  * Script Class for the rename-file form
  */
-class ReplaceFileController
+class ReplaceFileController extends AbstractModule
 {
+
     /**
      * Document template object
      *
@@ -74,15 +75,11 @@ class ReplaceFileController
     public $content;
 
     /**
-     * @var IconFactory
-     */
-    protected $iconFactory;
-
-    /**
      * Constructor
      */
     public function __construct()
     {
+        parent::__construct();
         $GLOBALS['SOBE'] = $this;
         $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
         $this->init();
@@ -98,20 +95,25 @@ class ReplaceFileController
     protected function init()
     {
         // Initialize GPvars:
-        $this->uid = (int) GeneralUtility::_GP('uid');
+        $this->uid = (int)GeneralUtility::_GP('uid');
+        $lang = $this->getLanguageService();
 
         $this->returnUrl = GeneralUtility::sanitizeLocalUrl(GeneralUtility::_GP('returnUrl'));
         // Cleaning and checking uid
         if ($this->uid > 0) {
-            $this->fileOrFolderObject = ResourceFactory::getInstance()->retrieveFileOrFolderObject('file:' . $this->uid);
+            $this->fileOrFolderObject = ResourceFactory::getInstance()
+                ->retrieveFileOrFolderObject('file:' . $this->uid);
         }
         if (!$this->fileOrFolderObject) {
-            $title = $this->getLanguageService()->sL('LLL:EXT:lang/locallang_mod_file_list.xlf:paramError', true);
-            $message = $this->getLanguageService()->sL('LLL:EXT:lang/locallang_mod_file_list.xlf:targetNoDir', true);
+            $title = $lang->sL('LLL:EXT:lang/locallang_mod_file_list.xlf:paramError', true);
+            $message = $lang->sL('LLL:EXT:lang/locallang_mod_file_list.xlf:targetNoDir', true);
             throw new \RuntimeException($title . ': ' . $message, 1436895930);
         }
         if ($this->fileOrFolderObject->getStorage()->getUid() === 0) {
-            throw new InsufficientFileAccessPermissionsException('You are not allowed to access files outside your storages', 1436895931);
+            throw new InsufficientFileAccessPermissionsException(
+                'You are not allowed to access files outside your storages',
+                1436895931
+            );
         }
 
         // If a folder should be renamed, AND the returnURL should go to the old directory name, the redirect is forced
@@ -122,20 +124,23 @@ class ReplaceFileController
             $parsedUrl = parse_url($this->returnUrl);
             $queryParts = GeneralUtility::explodeUrl2Array(urldecode($parsedUrl['query']));
             if ($queryParts['id'] === $this->fileOrFolderObject->getCombinedIdentifier()) {
-                $this->returnUrl = str_replace(urlencode($queryParts['id']), urlencode($this->fileOrFolderObject->getStorage()->getRootLevelFolder()->getCombinedIdentifier()), $this->returnUrl);
+                $this->returnUrl = str_replace(
+                    urlencode($queryParts['id']),
+                    urlencode($this->fileOrFolderObject->getStorage()->getRootLevelFolder()->getCombinedIdentifier()),
+                    $this->returnUrl
+                );
             }
         }
-        // Setting icon and title
-        $icon = $this->iconFactory->getIcon('apps-filetree-root', Icon::SIZE_SMALL)->render();
-        $this->title = $icon . htmlspecialchars($this->fileOrFolderObject->getStorage()->getName()) . ': ' . htmlspecialchars($this->fileOrFolderObject->getIdentifier());
-        // Setting template object
-        $this->doc = GeneralUtility::makeInstance(DocumentTemplate::class);
-        $this->doc->setModuleTemplate('EXT:backend/Resources/Private/Templates/file_replace.html');
-        $this->doc->JScode = $this->doc->wrapScriptTags('
-                       function backToList() {
-                               top.goToModule("file_FilelistList");
-                       }
-               ');
+
+        $pathInfo = [
+            'combined_identifier' => $this->fileOrFolderObject->getCombinedIdentifier(),
+        ];
+        $this->moduleTemplate->getDocHeaderComponent()->setMetaInformation($pathInfo);
+        $this->moduleTemplate->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/ClickMenu');
+        $this->moduleTemplate->addJavaScriptCode(
+            'ReplaceFileOnlineJavaScript',
+            'function backToList() {top.goToModule("file_FilelistList");}'
+        );
     }
 
     /**
@@ -145,27 +150,28 @@ class ReplaceFileController
      */
     public function main()
     {
-        // Make page header:
-        $this->content = $this->doc->startPage($this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:file_replace.php.pagetitle'));
-        $pageContent = $this->doc->header($this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:file_replace.php.pagetitle'));
-        $pageContent .= $this->doc->spacer(5);
-        $pageContent .= $this->doc->divider(5);
-
-        $code = '<form action="' . htmlspecialchars(BackendUtility::getModuleUrl('tce_file')) . '" role="form" method="post" name="editform" enctype="multipart/form-data">';
+        $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">' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:file_replace.php.keepfiletitle') . '</label>
+                               <input type="checkbox" value="1" id="keepFilename" name="file[replace][1][keepFilename]"> <label for="keepFilename">'
+            . $lang->sL('LLL:EXT:lang/locallang_core.xlf:file_replace.php.keepfiletitle')
+            . '</label>
                        </div>
 
                        <div class="form-group">
-                               <label for="file_replace">' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:file_replace.php.selectfile') . '</label>
+                               <label for="file_replace">' . $lang->sL('LLL:EXT:lang/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();">' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:file_replace.php.browse') . '</a>
+                                       <a class="input-group-addon btn btn-primary" onclick="TYPO3.jQuery(\'#file_replace\').click();">'
+            . $lang->sL('LLL:EXT:lang/locallang_core.xlf:file_replace.php.browse')
+            . '</a>
                                </div>
-                               <input class="form-control" type="file" id="file_replace" multiple="false" name="replace_1" style="visibility: hidden;" />
+                               <input class="form-control" type="file" id="file_replace" name="replace_1" style="visibility: hidden;" />
                        </div>
 
                        <script>
@@ -181,35 +187,37 @@ class ReplaceFileController
         // Making submit button:
         $code .= '
                                <div class="form-group">
-                                       <input class="btn btn-primary" type="submit" value="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:file_replace.php.submit', true) . '" />
-                                       <input class="btn btn-danger" type="submit" value="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.cancel', true) . '" onclick="backToList(); return false;" />
+                                       <input class="btn btn-primary" type="submit" value="'
+            . $lang->sL('LLL:EXT:lang/locallang_core.xlf:file_replace.php.submit', true) . '" />
+                                       <input class="btn btn-danger" type="submit" value="'
+            . $lang->sL('LLL:EXT:lang/locallang_core.xlf:labels.cancel', true)
+            . '" onclick="backToList(); return false;" />
                                        <input type="hidden" name="redirect" value="' . htmlspecialchars($this->returnUrl) . '" />
                                </div>
                ';
         $code .= '</form>';
-        // Add the HTML as a section:
-        $pageContent .= $code;
-        $docHeaderButtons = array(
-                'back' => ''
-        );
-        $docHeaderButtons['csh'] = BackendUtility::cshItem('xMOD_csh_corebe', 'file_rename');
-        // Back
+
+        $buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
+        // csh button
+        $cshButton = $buttonBar->makeHelpButton()
+            ->setModuleName('xMOD_csh_corebe')
+            ->setFieldName('file_rename');
+        $buttonBar->addButton($cshButton);
+
+        // Back button
         if ($this->returnUrl) {
-            $docHeaderButtons['back'] = '<a href="' . htmlspecialchars(GeneralUtility::linkThisUrl($this->returnUrl))
-                . '" class="typo3-goBack" title="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.goBack', true) . '">'
-                . $this->iconFactory->getIcon('actions-view-go-back', Icon::SIZE_SMALL)->render()
-                . '</a>';
+            $returnButton = $buttonBar->makeLinkButton()
+                ->setHref(GeneralUtility::linkThisUrl($this->returnUrl))
+                ->setTitle($lang->sL('LLL:EXT:lang/locallang_core.xlf:labels.goBack', true))
+                ->setIcon($this->moduleTemplate->getIconFactory()->getIcon('actions-view-go-back', Icon::SIZE_SMALL));
+            $buttonBar->addButton($returnButton);
         }
+
+        $this->content .= '<h1>' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:file_replace.php.pagetitle') . '</h1>';
         // Add the HTML as a section:
-        $markerArray = array(
-                'CSH' => $docHeaderButtons['csh'],
-                'FUNC_MENU' => BackendUtility::getFuncMenu($this->id, 'SET[function]', $this->MOD_SETTINGS['function'], $this->MOD_MENU['function']),
-                'CONTENT' => $pageContent,
-                'PATH' => $this->title
-        );
-        $this->content .= $this->doc->moduleBody(array(), $docHeaderButtons, $markerArray);
-        $this->content .= $this->doc->endPage();
-        $this->content = $this->doc->insertStylesAndJS($this->content);
+        $this->content .= $this->moduleTemplate->section('', $code);
+
+        $this->moduleTemplate->setContent($this->content);
     }
 
     /**
@@ -223,23 +231,11 @@ class ReplaceFileController
     {
         $this->main();
 
-        $response->getBody()->write($this->content);
+        $response->getBody()->write($this->moduleTemplate->renderContent());
         return $response;
     }
 
     /**
-     * Outputting the accumulated content to screen
-     *
-     * @return void
-     * @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8, use the mainAction() method instead
-     */
-    public function printContent()
-    {
-        GeneralUtility::logDeprecatedFunction();
-        echo $this->content;
-    }
-
-    /**
      * @return LanguageService
      */
     protected function getLanguageService()
diff --git a/typo3/sysext/backend/Resources/Private/Templates/file_replace.html b/typo3/sysext/backend/Resources/Private/Templates/file_replace.html
deleted file mode 100644 (file)
index f656ef2..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-<!-- ###FULLDOC### begin -->
-<div class="typo3-fullDoc">
-       <div id="typo3-docheader">
-               <div class="typo3-docheader-functions">
-                       <div class="left">###CSH### ###FUNC_MENU###</div>
-                       <div class="right">###PATH###</div>
-               </div>
-               <div class="typo3-docheader-buttons">
-                       <div class="left">###BUTTONLIST_LEFT###</div>
-                       <div class="right">###BUTTONLIST_RIGHT###</div>
-               </div>
-       </div>
-
-       <div id="typo3-docbody">
-               <div id="typo3-inner-docbody">
-                       ###CONTENT###
-               </div>
-       </div>
-</div>
-<!-- ###FULLDOC### end -->
-
-<!-- Grouping the icons on top -->
-
-<!-- ###BUTTON_GROUP_WRAP### -->
-<div class="buttongroup">###BUTTONS###</div>
-<!-- ###BUTTON_GROUP_WRAP### -->
-
-<!-- ###BUTTON_GROUPS_LEFT### -->
-<!-- ###BUTTON_GROUP4### -->###BACK###<!-- ###BUTTON_GROUP4### -->
-<!-- ###BUTTON_GROUPS_LEFT### -->
-
-<!-- ###BUTTON_GROUPS_RIGHT### -->
-<!-- ###BUTTON_GROUP1### --><!-- ###BUTTON_GROUP1### -->
-<!-- ###BUTTON_GROUPS_RIGHT### -->
\ No newline at end of file