'', 'config' => [ 'type' => 'text', 'cols' => 48, 'wrap' => 'off', 'enableTabulator' => true, 'fixedFont' => true, ], ]; protected array $formEngineData = [ 'databaseRow' => [ 'uid' => 0, 'data' => '', 'target' => 0, 'redirect' => '', ], 'tableName' => 'editfile', 'processedTca' => [ 'columns' => [ 'data' => [], 'target' => [ 'config' => [ 'type' => 'input', 'renderType' => 'hidden', ], ], 'redirect' => [ 'config' => [ 'type' => 'input', 'renderType' => 'hidden', ], ], ], 'types' => [ 1 => [ 'showitem' => 'data,target,redirect', ], ], ], 'recordTypeValue' => 1, 'inlineStructure' => [], 'renderType' => 'fullRecordContainer', ]; public function __construct( protected readonly IconFactory $iconFactory, protected readonly UriBuilder $uriBuilder, protected readonly ResourceFactory $resourceFactory, protected readonly ModuleTemplateFactory $moduleTemplateFactory, protected readonly ResponseFactory $responseFactory, protected readonly StreamFactoryInterface $streamFactory, protected readonly EventDispatcherInterface $eventDispatcher, protected readonly NodeFactory $nodeFactory, protected readonly ComponentFactory $componentFactory, protected readonly FormResultFactory $formResultFactory, protected readonly FormResultHandler $formResultHandler, ) {} /** * Render the edit file content form using FormEngine. */ public function mainAction(ServerRequestInterface $request): ResponseInterface { $languageService = $this->getLanguageService(); $view = $this->moduleTemplateFactory->create($request); $parsedBody = $request->getParsedBody(); $queryParams = $request->getQueryParams(); $combinedIdentifier = $parsedBody['target'] ?? $queryParams['target'] ?? ''; $file = $this->resourceFactory->retrieveFileOrFolderObject($combinedIdentifier); if (!$file instanceof FileInterface) { throw new InvalidFileException('Referenced target "' . $combinedIdentifier . '" could not be resolved to a valid file', 1294586841); } if ($file->getStorage()->isFallbackStorage()) { throw new InsufficientFileAccessPermissionsException('You are not allowed to access files outside your storages', 1375889832); } /** @var Folder $parentFolder */ $parentFolder = $file->getParentFolder(); $returnUrl = GeneralUtility::sanitizeLocalUrl( $parsedBody['returnUrl'] ?? $queryParams['returnUrl'] ?? (string)$this->uriBuilder->buildUriFromRoute('media_management', [ 'id' => $parentFolder->getCombinedIdentifier(), ]), $request ); if (!$file->isTextFile()) { $extList = $GLOBALS['TYPO3_CONF_VARS']['SYS']['textfile_ext']; $view->addFlashMessage('Files with that extension are not editable. Allowed extensions are: ' . $extList, '', ContextualFeedbackSeverity::ERROR, true); return $this->responseFactory->createResponse(400)->withHeader('location', $returnUrl); } $this->addDocHeaderButtons($view, $returnUrl); $dataColumnDefinition = $this->dataColumnTca; $dataColumnDefinition['label'] = htmlspecialchars($languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_common.xlf:file')) . ' ' . htmlspecialchars($combinedIdentifier); $formData = $this->formEngineData; $formData['databaseRow']['data'] = $file->getContents(); $formData['databaseRow']['target'] = $file->getUid(); $formData['databaseRow']['redirect'] = (string)$this->uriBuilder->buildUriFromRoute('file_edit', ['target' => $combinedIdentifier, 'returnUrl' => $returnUrl]); $formData['processedTca']['columns']['data'] = $dataColumnDefinition; $formData = $this->eventDispatcher->dispatch( new ModifyEditFileFormDataEvent($formData, $file, $request) )->getFormData(); $resultArray = $this->nodeFactory->create($formData)->render(); $formResult = $this->formResultFactory->create($resultArray); $this->formResultHandler->addAssets($formResult); // Rendering of the output via fluid and PageRenderer $view->assignMultiple([ 'moduleUrlTceFile' => (string)$this->uriBuilder->buildUriFromRoute('tce_file'), 'fileName' => $file->getName(), 'form' => $formResult->html, ]); $content = $view->render('File/EditFile'); return $this->responseFactory->createResponse() ->withHeader('Content-Type', 'text/html; charset=utf-8') ->withBody($this->streamFactory->createStream($content)); } protected function addDocHeaderButtons(ModuleTemplate $view, string $returnUrl): void { $languageService = $this->getLanguageService(); $view->addButtonToButtonBar( $this->componentFactory->createSaveButton('EditFileController') ->setTitle($languageService->sL('LLL:EXT:filelist/Resources/Private/Language/locallang.xlf:file_edit.php.submit')), ButtonBar::BUTTON_POSITION_LEFT, 20 ); $view->addButtonToButtonBar($this->componentFactory->createCloseButton($returnUrl), ButtonBar::BUTTON_POSITION_LEFT, 10); } protected function getLanguageService(): LanguageService { return $GLOBALS['LANG']; } }