‪TYPO3CMS  11.5
ImportExportController.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;
26 use TYPO3\CMS\Backend\Utility\BackendUtility;
31 use TYPO3\CMS\Core\Page\PageRenderer;
36 
43 {
49  protected ‪$id;
50 
56  protected ‪$pageInfo;
57 
63  protected ‪$permsClause;
64 
68  protected ‪$routeName = '';
69 
73  protected ‪$moduleTemplate;
74 
80  protected ‪$returnUrl;
81 
85  protected ‪$lang;
86 
90  protected ‪$standaloneView;
91 
93  protected PageRenderer ‪$pageRenderer;
94  protected ‪UriBuilder ‪$uriBuilder;
96 
100  public function ‪__construct(
102  PageRenderer ‪$pageRenderer,
105  ) {
106  $this->iconFactory = ‪$iconFactory;
107  $this->pageRenderer = ‪$pageRenderer;
108  $this->uriBuilder = ‪$uriBuilder;
109  $this->moduleTemplateFactory = ‪$moduleTemplateFactory;
110 
111  $templatePath = ‪ExtensionManagementUtility::extPath('impexp') . 'Resources/Private/';
112 
113  $this->standaloneView = GeneralUtility::makeInstance(StandaloneView::class);
114  $this->standaloneView->setTemplateRootPaths([$templatePath . 'Templates/ImportExport/']);
115  $this->standaloneView->setLayoutRootPaths([$templatePath . 'Layouts/']);
116  $this->standaloneView->setPartialRootPaths([$templatePath . 'Partials/']);
117  $this->standaloneView->getRequest()->setControllerExtensionName('impexp');
118 
119  $this->permsClause = $this->‪getBackendUser()->‪getPagePermsClause(‪Permission::PAGE_SHOW);
120  $this->returnUrl = GeneralUtility::sanitizeLocalUrl(GeneralUtility::_GP('returnUrl'));
121  $this->lang = $this->‪getLanguageService();
122  $this->lang->includeLLFile('EXT:impexp/Resources/Private/Language/locallang.xlf');
123  }
124 
129  abstract public function ‪mainAction(ServerRequestInterface $request): ResponseInterface;
130 
135  protected function ‪main(ServerRequestInterface $request): void
136  {
137  $queryParams = $request->getQueryParams();
138  $parsedBody = $request->getParsedBody();
139 
140  $this->moduleTemplate = $this->moduleTemplateFactory->create($request);
141  $this->moduleTemplate->setModuleName('');
142 
143  // Checking page access
144  $this->id = (int)($parsedBody['id'] ?? $queryParams['id'] ?? 0);
145  $this->pageInfo = BackendUtility::readPageAccess($this->id, $this->permsClause) ?: [];
146 
147  if ($this->pageInfo === []) {
148  throw new \RuntimeException(
149  'You don\'t have access to this page.',
150  1604308205
151  );
152  }
153 
154  // Setting up the module meta data:
155  $this->moduleTemplate->getDocHeaderComponent()->setMetaInformation($this->pageInfo);
156 
157  // Setting up the context sensitive menu:
158  $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/ContextMenu');
159  $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Impexp/ImportExport');
160  $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/Element/ImmediateActionElement');
161 
162  $this->standaloneView->assign('moduleUrl', (string)$this->uriBuilder->buildUriFromRoute($this->routeName));
163  $this->standaloneView->assign('id', $this->id);
164  }
165 
169  protected function ‪registerDocHeaderButtons(): void
170  {
171  $buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
172  // back button
173  if ($this->returnUrl) {
174  $backButton = $buttonBar->makeLinkButton()
175  ->setHref($this->returnUrl)
176  ->setTitle($this->lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.goBack'))
177  ->setIcon($this->iconFactory->getIcon('actions-view-go-back', ‪Icon::SIZE_SMALL));
178  $buttonBar->addButton($backButton);
179  }
180  }
181 
186  {
187  return ‪$GLOBALS['BE_USER'];
188  }
189 
193  protected function ‪getLanguageService(): ‪LanguageService
194  {
195  return ‪$GLOBALS['LANG'];
196  }
197 }
‪TYPO3\CMS\Impexp\Controller\ImportExportController\mainAction
‪ResponseInterface mainAction(ServerRequestInterface $request)
‪TYPO3\CMS\Core\Imaging\Icon\SIZE_SMALL
‪const SIZE_SMALL
Definition: Icon.php:30
‪TYPO3\CMS\Impexp\Controller\ImportExportController\main
‪main(ServerRequestInterface $request)
Definition: ImportExportController.php:127
‪TYPO3\CMS\Impexp\Controller\ImportExportController\$id
‪int $id
Definition: ImportExportController.php:48
‪TYPO3\CMS\Impexp\Controller\ImportExportController\$uriBuilder
‪UriBuilder $uriBuilder
Definition: ImportExportController.php:86
‪TYPO3\CMS\Impexp\Controller
Definition: ExportController.php:18
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\getPagePermsClause
‪string getPagePermsClause($perms)
Definition: BackendUserAuthentication.php:460
‪TYPO3\CMS\Impexp\Controller\ImportExportController\$moduleTemplateFactory
‪ModuleTemplateFactory $moduleTemplateFactory
Definition: ImportExportController.php:87
‪TYPO3\CMS\Core\Imaging\Icon
Definition: Icon.php:26
‪TYPO3\CMS\Backend\Template\ModuleTemplateFactory
Definition: ModuleTemplateFactory.php:29
‪TYPO3\CMS\Impexp\Controller\ImportExportController\$permsClause
‪string $permsClause
Definition: ImportExportController.php:60
‪TYPO3\CMS\Impexp\Controller\ImportExportController\$routeName
‪string $routeName
Definition: ImportExportController.php:64
‪TYPO3\CMS\Core\Imaging\IconFactory
Definition: IconFactory.php:34
‪TYPO3\CMS\Backend\Template\ModuleTemplate
Definition: ModuleTemplate.php:46
‪TYPO3\CMS\Impexp\Controller\ImportExportController\__construct
‪__construct(IconFactory $iconFactory, PageRenderer $pageRenderer, UriBuilder $uriBuilder, ModuleTemplateFactory $moduleTemplateFactory)
Definition: ImportExportController.php:92
‪TYPO3\CMS\Core\Type\Bitmask\Permission
Definition: Permission.php:26
‪TYPO3\CMS\Core\Utility\ExtensionManagementUtility
Definition: ExtensionManagementUtility.php:43
‪TYPO3\CMS\Impexp\Controller\ImportExportController
Definition: ImportExportController.php:43
‪TYPO3\CMS\Backend\Routing\Exception\RouteNotFoundException
Definition: RouteNotFoundException.php:21
‪TYPO3\CMS\Impexp\Controller\ImportExportController\$standaloneView
‪StandaloneView $standaloneView
Definition: ImportExportController.php:82
‪TYPO3\CMS\Impexp\Controller\ImportExportController\$pageInfo
‪array $pageInfo
Definition: ImportExportController.php:54
‪TYPO3\CMS\Impexp\Controller\ImportExportController\$moduleTemplate
‪ModuleTemplate $moduleTemplate
Definition: ImportExportController.php:68
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:40
‪TYPO3\CMS\Impexp\Controller\ImportExportController\$lang
‪LanguageService $lang
Definition: ImportExportController.php:78
‪TYPO3\CMS\Impexp\Controller\ImportExportController\$returnUrl
‪string $returnUrl
Definition: ImportExportController.php:74
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Core\Type\Bitmask\Permission\PAGE_SHOW
‪const PAGE_SHOW
Definition: Permission.php:35
‪TYPO3\CMS\Impexp\Controller\ImportExportController\getLanguageService
‪LanguageService getLanguageService()
Definition: ImportExportController.php:185
‪TYPO3\CMS\Impexp\Controller\ImportExportController\registerDocHeaderButtons
‪registerDocHeaderButtons()
Definition: ImportExportController.php:161
‪TYPO3\CMS\Fluid\View\StandaloneView
Definition: StandaloneView.php:31
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Utility\ExtensionManagementUtility\extPath
‪static string extPath($key, $script='')
Definition: ExtensionManagementUtility.php:142
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:42
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Impexp\Controller\ImportExportController\getBackendUser
‪BackendUserAuthentication getBackendUser()
Definition: ImportExportController.php:177
‪TYPO3\CMS\Impexp\Controller\ImportExportController\$pageRenderer
‪PageRenderer $pageRenderer
Definition: ImportExportController.php:85
‪TYPO3\CMS\Impexp\Controller\ImportExportController\$iconFactory
‪IconFactory $iconFactory
Definition: ImportExportController.php:84