‪TYPO3CMS  ‪main
FileUploadController.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use Psr\Http\Message\ResponseInterface;
21 use Psr\Http\Message\ServerRequestInterface;
27 use TYPO3\CMS\Core\Imaging\IconSize;
33 
39 #[AsController]
41 {
42  public function ‪__construct(
43  protected readonly ‪IconFactory $iconFactory,
44  protected readonly ‪UriBuilder $uriBuilder,
45  protected readonly ‪ResourceFactory $resourceFactory,
46  protected readonly ‪ModuleTemplateFactory $moduleTemplateFactory,
47  ) {}
48 
52  public function ‪mainAction(ServerRequestInterface $request): ResponseInterface
53  {
54  $parsedBody = $request->getParsedBody();
55  $queryParams = $request->getQueryParams();
56  $languageService = $this->‪getLanguageService();
57  $view = $this->moduleTemplateFactory->create($request);
58 
59  $targetFolderCombinedIdentifier = $parsedBody['target'] ?? $queryParams['target'] ?? '';
60  $folder = $this->resourceFactory->retrieveFileOrFolderObject($targetFolderCombinedIdentifier);
61 
62  if (!$folder instanceof ‪FolderInterface
63  || $folder->‪getStorage()->isFallbackStorage()
64  ) {
65  throw new ‪InsufficientFolderAccessPermissionsException('You are not allowed to access folders outside your storages, or the folder couldn\'t be resolved', 1375889834);
66  }
67 
68  $returnUrl = GeneralUtility::sanitizeLocalUrl(
69  $parsedBody['returnUrl']
70  ?? $queryParams['returnUrl']
71  ?? (string)$this->uriBuilder->buildUriFromRoute('file_list', [
72  'id' => rawurlencode($targetFolderCombinedIdentifier),
73  ])
74  );
75 
76  $view->getDocHeaderComponent()->setMetaInformationForResource($folder);
77  $this->‪addDocHeaderButtons($view, $returnUrl);
78  $view->setTitle($languageService->sL('LLL:EXT:filelist/Resources/Private/Language/locallang.xlf:file_upload.php.pagetitle'));
79 
80  $view->assignMultiple([
81  'returnUrl' => $returnUrl,
82  'folderCombinedIdentifier' => $targetFolderCombinedIdentifier,
83  ]);
84 
85  return $view->renderResponse('File/UploadFile');
86  }
87 
88  protected function ‪addDocHeaderButtons(‪ModuleTemplate $view, string $returnUrl)
89  {
90  $languageService = $this->‪getLanguageService();
91  $buttonBar = $view->‪getDocHeaderComponent()->getButtonBar();
92 
93  $backButton = $buttonBar->makeLinkButton()
94  ->setHref($returnUrl)
95  ->setTitle($languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.goBack'))
96  ->setShowLabelText(true)
97  ->setIcon($this->iconFactory->getIcon('actions-view-go-back', IconSize::SMALL));
98  $buttonBar->addButton($backButton);
99  }
100 
102  {
103  return ‪$GLOBALS['LANG'];
104  }
105 }
‪TYPO3\CMS\Core\Resource\Exception\InsufficientFolderAccessPermissionsException
Definition: InsufficientFolderAccessPermissionsException.php:23
‪TYPO3\CMS\Backend\Template\ModuleTemplateFactory
Definition: ModuleTemplateFactory.php:33
‪TYPO3\CMS\Core\Resource\ResourceInterface\getStorage
‪getStorage()
‪TYPO3\CMS\Filelist\Controller\File\FileUploadController\addDocHeaderButtons
‪addDocHeaderButtons(ModuleTemplate $view, string $returnUrl)
Definition: FileUploadController.php:88
‪TYPO3\CMS\Core\Imaging\IconFactory
Definition: IconFactory.php:34
‪TYPO3\CMS\Filelist\Controller\File\FileUploadController\__construct
‪__construct(protected readonly IconFactory $iconFactory, protected readonly UriBuilder $uriBuilder, protected readonly ResourceFactory $resourceFactory, protected readonly ModuleTemplateFactory $moduleTemplateFactory,)
Definition: FileUploadController.php:42
‪TYPO3\CMS\Filelist\Controller\File
Definition: CreateFileController.php:18
‪TYPO3\CMS\Backend\Template\ModuleTemplate
Definition: ModuleTemplate.php:46
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:44
‪TYPO3\CMS\Core\Resource\ResourceFactory
Definition: ResourceFactory.php:42
‪TYPO3\CMS\Filelist\Controller\File\FileUploadController
Definition: FileUploadController.php:41
‪TYPO3\CMS\Backend\Template\ModuleTemplate\getDocHeaderComponent
‪getDocHeaderComponent()
Definition: ModuleTemplate.php:181
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Filelist\Controller\File\FileUploadController\getLanguageService
‪getLanguageService()
Definition: FileUploadController.php:101
‪TYPO3\CMS\Core\Resource\FolderInterface
Definition: FolderInterface.php:24
‪TYPO3\CMS\Backend\Attribute\AsController
Definition: AsController.php:25
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:46
‪TYPO3\CMS\Filelist\Controller\File\FileUploadController\mainAction
‪mainAction(ServerRequestInterface $request)
Definition: FileUploadController.php:52
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52