2 declare(strict_types = 1);
18 use Psr\Http\Message\ResponseInterface;
19 use Psr\Http\Message\ServerRequestInterface;
44 'doc' =>
'Using $doc of class ReplaceFileController from outside is discouraged as this variable is only used for internal storage.',
45 'title' =>
'Using $title of class ReplaceFileController from outside is discouraged as this variable is only used for internal storage.',
46 'uid' =>
'Using $uid of class ReplaceFileController from outside is discouraged as this variable is only used for internal storage.',
47 'returnUrl' =>
'Using $returnUrl of class ReplaceFileController from outside is discouraged as this variable is only used for internal storage.',
48 'content' =>
'Using $content of class ReplaceFileController from outside is discouraged as this variable is only used for internal storage.',
105 $this->moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class);
117 public function mainAction(ServerRequestInterface $request): ResponseInterface
120 return new HtmlResponse($this->moduleTemplate->renderContent());
126 public function main()
128 trigger_error(
'ReplaceFileController->main() will be replaced by protected method renderContent() in TYPO3 v10.0. Do not call from other extension.', E_USER_DEPRECATED);
139 protected function init(ServerRequestInterface $request): void
141 $parsedBody = $request->getParsedBody();
142 $queryParams = $request->getQueryParams();
146 $this->uid = (int)($parsedBody[
'uid'] ?? $queryParams[
'uid'] ?? 0);
147 $this->returnUrl = GeneralUtility::sanitizeLocalUrl($parsedBody[
'returnUrl'] ?? $queryParams[
'returnUrl'] ??
'');
150 if ($this->uid > 0) {
154 if (!$this->fileOrFolderObject) {
155 $title = $lang->sL(
'LLL:EXT:filelist/Resources/Private/Language/locallang_mod_file_list.xlf:paramError');
156 $message = $lang->sL(
'LLL:EXT:filelist/Resources/Private/Language/locallang_mod_file_list.xlf:targetNoDir');
157 throw new \RuntimeException(
$title .
': ' . $message, 1436895930);
159 if ($this->fileOrFolderObject->getStorage()->getUid() === 0) {
160 throw new InsufficientFileAccessPermissionsException(
161 'You are not allowed to access files outside your storages',
170 if ($this->fileOrFolderObject instanceof Folder) {
171 $parsedUrl = parse_url($this->returnUrl);
172 $queryParts = GeneralUtility::explodeUrl2Array(urldecode($parsedUrl[
'query']));
173 if ($queryParts[
'id'] === $this->fileOrFolderObject->getCombinedIdentifier()) {
174 $this->returnUrl = str_replace(
175 urlencode($queryParts[
'id']),
176 urlencode($this->fileOrFolderObject->getStorage()->getRootLevelFolder()->getCombinedIdentifier()),
183 'combined_identifier' => $this->fileOrFolderObject->getCombinedIdentifier(),
185 $this->moduleTemplate->getDocHeaderComponent()->setMetaInformation($pathInfo);
186 $this->moduleTemplate->getPageRenderer()->loadRequireJsModule(
'TYPO3/CMS/Backend/ContextMenu');
187 $this->moduleTemplate->addJavaScriptCode(
188 'ReplaceFileOnlineJavaScript',
189 'function backToList() {top.goToModule("file_FilelistList");}'
201 $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
202 $assigns[
'moduleUrlTceFile'] = (string)$uriBuilder->buildUriFromRoute(
'tce_file');
206 $buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
208 $cshButton = $buttonBar->makeHelpButton()
209 ->setModuleName(
'xMOD_csh_corebe')
210 ->setFieldName(
'file_rename');
211 $buttonBar->addButton($cshButton);
214 if ($this->returnUrl) {
215 $returnButton = $buttonBar->makeLinkButton()
216 ->setHref($this->returnUrl)
217 ->setTitle($this->
getLanguageService()->
sL(
'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.goBack'))
218 ->setIcon($this->moduleTemplate->getIconFactory()->getIcon(
'actions-view-go-back',
Icon::SIZE_SMALL));
219 $buttonBar->addButton($returnButton);
223 $view = GeneralUtility::makeInstance(StandaloneView::class);
224 $view->setTemplateRootPaths([GeneralUtility::getFileAbsFileName(
'EXT:backend/Resources/Private/Templates')]);
225 $view->setPartialRootPaths([GeneralUtility::getFileAbsFileName(
'EXT:backend/Resources/Private/Partials')]);
226 $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName(
227 'EXT:backend/Resources/Private/Templates/File/ReplaceFile.html'
229 $view->assignMultiple($assigns);
230 $this->content = $view->render();
232 $this->moduleTemplate->setContent($this->content);