2 declare(strict_types = 1);
18 use Psr\Http\Message\ResponseInterface;
19 use Psr\Http\Message\ServerRequestInterface;
46 'title' =>
'Using $title of class RenameFileController from outside is discouraged as this variable is only used for internal storage.',
47 'target' =>
'Using $target of class RenameFileController from outside is discouraged as this variable is only used for internal storage.',
48 'returnUrl' =>
'Using $returnUrl of class RenameFileController from outside is discouraged as this variable is only used for internal storage.',
49 'content' =>
'Using $content of class RenameFileController from outside is discouraged as this variable is only used for internal storage.',
101 $this->moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class);
113 public function mainAction(ServerRequestInterface $request): ResponseInterface
125 public function main()
127 trigger_error(
'RenameFileController->main() will be replaced by protected method renderContent() in TYPO3 v10.0. Do not call from other extension.', E_USER_DEPRECATED);
137 protected function init(ServerRequestInterface $request): void
139 $parsedBody = $request->getParsedBody();
140 $queryParams = $request->getQueryParams();
143 $this->target = $parsedBody[
'target'] ?? $queryParams[
'target'] ??
null;
144 $this->returnUrl = GeneralUtility::sanitizeLocalUrl($parsedBody[
'returnUrl'] ?? $queryParams[
'returnUrl'] ??
'');
149 if (!$this->fileOrFolderObject) {
151 $message = $this->
getLanguageService()->
sL(
'LLL:EXT:filelist/Resources/Private/Language/locallang_mod_file_list.xlf:targetNoDir');
152 throw new \RuntimeException(
$title .
': ' . $message, 1294586844);
154 if ($this->fileOrFolderObject->getStorage()->getUid() === 0) {
155 throw new InsufficientFileAccessPermissionsException(
'You are not allowed to access files outside your storages', 1375889840);
162 if ($this->fileOrFolderObject instanceof Folder) {
163 $parsedUrl = parse_url($this->returnUrl);
164 $queryParts = GeneralUtility::explodeUrl2Array(urldecode($parsedUrl[
'query']));
165 if ($queryParts[
'id'] === $this->fileOrFolderObject->getCombinedIdentifier()) {
166 $this->returnUrl = str_replace(
167 urlencode($queryParts[
'id']),
168 urlencode($this->fileOrFolderObject->getStorage()->getRootLevelFolder()->getCombinedIdentifier()),
176 'combined_identifier' => $this->fileOrFolderObject->getCombinedIdentifier(),
178 $this->moduleTemplate->getDocHeaderComponent()->setMetaInformation($pathInfo);
181 $this->moduleTemplate->getPageRenderer()->loadRequireJsModule(
'TYPO3/CMS/Backend/ContextMenu');
182 $this->moduleTemplate->getPageRenderer()->loadRequireJsModule(
'TYPO3/CMS/Backend/RenameFile');
185 $this->moduleTemplate->addJavaScriptCode(
186 'RenameFileInlineJavaScript',
187 'function backToList() {top.goToModule("file_FilelistList");}'
198 $uriBuilder = GeneralUtility::makeInstance(\
TYPO3\CMS\Backend\Routing\UriBuilder::class);
199 $assigns[
'moduleUrlTceFile'] = (string)$uriBuilder->buildUriFromRoute(
'tce_file');
202 if ($this->fileOrFolderObject instanceof
Folder) {
203 $fileIdentifier = $this->fileOrFolderObject->getCombinedIdentifier();
204 $targetLabel =
'file_rename.php.label.target.folder';
206 $fileIdentifier = $this->fileOrFolderObject->getUid();
207 $targetLabel =
'file_rename.php.label.target.file';
209 $assigns[
'destination'] = $this->fileOrFolderObject->getParentFolder()->getCombinedIdentifier();
212 $assigns[
'fileName'] = $this->fileOrFolderObject->getName();
213 $assigns[
'fileIdentifier'] = $fileIdentifier;
214 $assigns[
'fieldLabel'] = $targetLabel;
217 $buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
220 $cshButton = $buttonBar->makeHelpButton()
221 ->setModuleName(
'xMOD_csh_corebe')
222 ->setFieldName(
'file_rename');
223 $buttonBar->addButton($cshButton);
226 if ($this->returnUrl) {
227 $backButton = $buttonBar->makeLinkButton()
228 ->setHref($this->returnUrl)
229 ->setTitle($this->
getLanguageService()->sL(
'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.goBack'))
230 ->setIcon($this->moduleTemplate->getIconFactory()->getIcon(
'actions-close',
Icon::SIZE_SMALL));
231 $buttonBar->addButton($backButton);
235 $saveAndCloseButton = $buttonBar->makeInputButton()
236 ->setName(
'_saveandclose')
238 ->setShowLabelText(
true)
239 ->setClasses(
't3js-submit-file-rename')
240 ->setForm(
'RenameFileController')
241 ->setTitle($this->
getLanguageService()->sL(
'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:file_edit.php.saveAndClose'))
242 ->setIcon($this->moduleTemplate->getIconFactory()->getIcon(
'actions-document-save-close',
Icon::SIZE_SMALL));
246 $this->moduleTemplate->getPageRenderer()->addInlineLanguageLabelArray([
247 'file_rename.actions.cancel' => $this->
getLanguageService()->sL(
'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:file_rename.actions.cancel'),
248 'file_rename.actions.rename' => $this->
getLanguageService()->sL(
'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:file_rename.actions.rename'),
249 'file_rename.actions.override' => $this->
getLanguageService()->sL(
'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:file_rename.actions.override'),
250 'file_rename.exists.title' => $this->
getLanguageService()->sL(
'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:file_rename.exists.title'),
251 'file_rename.exists.description' => $this->
getLanguageService()->sL(
'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:file_rename.exists.description'),
255 $view = GeneralUtility::makeInstance(StandaloneView::class);
256 $view->setTemplateRootPaths([GeneralUtility::getFileAbsFileName(
'EXT:backend/Resources/Private/Templates')]);
257 $view->setPartialRootPaths([GeneralUtility::getFileAbsFileName(
'EXT:backend/Resources/Private/Partials')]);
258 $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName(
259 'EXT:backend/Resources/Private/Templates/File/RenameFile.html'
261 $view->assignMultiple($assigns);
262 $this->content = $view->render();
263 $this->moduleTemplate->setContent($this->content);