2 declare(strict_types = 1);
18 use Psr\Http\Message\ResponseInterface;
19 use Psr\Http\Message\ServerRequestInterface;
54 'main' =>
'Using EditFileController::main() is deprecated and will not be possible anymore in TYPO3 v10.0.',
61 'origTarget' =>
'Using $origTarget of class EditFileController from outside is discouraged, as this variable is only used for internal storage.',
62 'target' =>
'Using $target of class EditFileController from outside is discouraged, as this variable is only used for internal storage.',
63 'returnUrl' =>
'Using $returnUrl of class EditFileController from outside is discouraged, as this variable is only used for internal storage.',
64 'content' =>
'Using $content of class EditFileController from outside is discouraged, as this variable is only used for internal storage.',
65 'title' =>
'Using $title of class EditFileController from outside is discouraged, as this variable is only used for internal storage.',
66 'doc' =>
'Using $doc of class EditFileController from outside is discouraged, as this variable is only used for internal storage.',
128 $this->moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class);
139 public function mainAction(ServerRequestInterface $request): ResponseInterface
141 if ($response = $this->
process()) {
145 return new HtmlResponse($this->moduleTemplate->renderContent());
151 protected function main()
167 protected function init(ServerRequestInterface $request): void
169 $parsedBody = $request->getParsedBody();
170 $queryParams = $request->getQueryParams();
173 $this->target = $this->origTarget = $parsedBody[
'target'] ?? $queryParams[
'target'] ??
'';
174 $this->returnUrl = GeneralUtility::sanitizeLocalUrl($parsedBody[
'returnUrl'] ?? $queryParams[
'returnUrl'] ??
'');
181 if (!$this->fileObject) {
183 $message = $this->
getLanguageService()->
sL(
'LLL:EXT:filelist/Resources/Private/Language/locallang_mod_file_list.xlf:targetNoDir');
184 throw new \RuntimeException(
$title .
': ' . $message, 1294586841);
186 if ($this->fileObject->getStorage()->getUid() === 0) {
187 throw new InsufficientFileAccessPermissionsException(
188 'You are not allowed to access files outside your storages',
194 $icon = $this->moduleTemplate->getIconFactory()->getIcon(
'apps-filetree-root',
Icon::SIZE_SMALL)->render();
197 $this->fileObject->getStorage()->getName()
198 ) .
': ' . htmlspecialchars(
199 $this->fileObject->getIdentifier()
203 $this->moduleTemplate->addJavaScriptCode(
204 'FileEditBackToList',
205 'function backToList() {
206 top.goToModule("file_FilelistList");
216 protected function process(): ?ResponseInterface
218 $dataColumnDefinition = [
219 'label' => htmlspecialchars($this->
getLanguageService()->sL(
'LLL:EXT:core/Resources/Private/Language/locallang_common.xlf:file'))
220 .
' ' . htmlspecialchars($this->target),
226 'defaultExtras' =>
'fixed-font: enable-tab'
231 foreach (
$GLOBALS[
'TYPO3_CONF_VARS'][
'SC_OPTIONS'][
'typo3/file_edit.php'][
'preOutputProcessingHook'] ?? [] as $hookFunction) {
235 'dataColumnDefinition' => &$dataColumnDefinition,
237 GeneralUtility::callUserFunction($hookFunction, $hookParameters, $this);
241 $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
242 $assigns[
'moduleUrlTceFile'] = (string)$uriBuilder->buildUriFromRoute(
'tce_file');
243 $assigns[
'fileName'] = $this->fileObject->getName();
245 $extList =
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'textfile_ext'];
247 if (!$extList || !GeneralUtility::inList($extList, $this->fileObject->getExtension())) {
249 throw new \Exception(
'Files with that extension are not editable. Allowed extensions are: ' . $extList, 1476050135);
253 $hValue = (string)$uriBuilder->buildUriFromRoute(
'file_edit', [
254 'target' => $this->origTarget,
255 'returnUrl' => $this->returnUrl
261 'data' => $this->fileObject->getContents(),
262 'target' => $this->fileObject->getUid(),
263 'redirect' => $hValue,
265 'tableName' =>
'editfile',
268 'data' => $dataColumnDefinition,
272 'renderType' =>
'hidden',
278 'renderType' =>
'hidden',
284 'showitem' =>
'data,target,redirect',
288 'recordTypeValue' => 1,
289 'inlineStructure' => [],
290 'renderType' =>
'fullRecordContainer',
293 $resultArray = GeneralUtility::makeInstance(NodeFactory::class)->create($formData)->render();
294 $formResultCompiler = GeneralUtility::makeInstance(FormResultCompiler::class);
295 $formResultCompiler->mergeResult($resultArray);
297 $form = $formResultCompiler->addCssFiles()
298 . $resultArray[
'html']
299 . $formResultCompiler->printNeededJSFunctions();
301 $assigns[
'form'] = $form;
302 }
catch (\Exception $e) {
304 $flashMessage = GeneralUtility::makeInstance(FlashMessage::class, $e->getMessage(),
'',
FlashMessage::ERROR,
true);
306 $flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class);
307 $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
308 $defaultFlashMessageQueue->enqueue($flashMessage);
310 return new RedirectResponse($this->returnUrl, 500);
314 $view = GeneralUtility::makeInstance(StandaloneView::class);
315 $view->setTemplateRootPaths([GeneralUtility::getFileAbsFileName(
'EXT:backend/Resources/Private/Templates')]);
316 $view->setPartialRootPaths([GeneralUtility::getFileAbsFileName(
'EXT:backend/Resources/Private/Partials')]);
317 $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName(
318 'EXT:backend/Resources/Private/Templates/File/EditFile.html'
320 $view->assignMultiple($assigns);
321 $pageContent = $view->render();
324 foreach (
$GLOBALS[
'TYPO3_CONF_VARS'][
'SC_OPTIONS'][
'typo3/file_edit.php'][
'postOutputProcessingHook'] ?? [] as $hookFunction) {
326 'pageContent' => &$pageContent,
329 GeneralUtility::callUserFunction($hookFunction, $hookParameters, $this);
332 $this->content .= $pageContent;
333 $this->moduleTemplate->setContent($this->content);
344 trigger_error(
'EditFileController->getButtons() will be replaced by protected method getButtonsInternal() in TYPO3 v10.0. Do not call from other extension.', E_USER_DEPRECATED);
353 $buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
357 $helpButton = $buttonBar->makeHelpButton()
358 ->setFieldName(
'file_edit')
359 ->setModuleName(
'xMOD_csh_corebe');
360 $buttonBar->addButton($helpButton);
363 $saveButton = $buttonBar->makeInputButton()
366 ->setForm(
'EditFileController')
367 ->setTitle($lang->sL(
'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:file_edit.php.submit'))
368 ->setIcon($this->moduleTemplate->getIconFactory()->getIcon(
'actions-document-save',
Icon::SIZE_SMALL));
371 $saveAndCloseButton = $buttonBar->makeInputButton()
372 ->setName(
'_saveandclosedok')
374 ->setForm(
'EditFileController')
376 'document.editform.elements.namedItem("data[editfile][0][redirect]").value='
377 . GeneralUtility::quoteJSvalue($this->returnUrl)
380 ->setTitle($lang->sL(
'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:file_edit.php.saveAndClose'))
381 ->setIcon($this->moduleTemplate->getIconFactory()->getIcon(
382 'actions-document-save-close',
386 $splitButton = $buttonBar->makeSplitButton()
387 ->addItem($saveButton)
388 ->addItem($saveAndCloseButton);
392 $closeButton = $buttonBar->makeLinkButton()
394 ->setOnClick(
'backToList(); return false;')
395 ->setTitle($lang->sL(
'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.cancel'))
396 ->setIcon($this->moduleTemplate->getIconFactory()->getIcon(
'actions-close',
Icon::SIZE_SMALL));
400 $shortButton = $buttonBar->makeShortcutButton()
401 ->setModuleName(
'file_edit')
402 ->setGetVariables([
'target']);
403 $buttonBar->addButton($shortButton);