‪TYPO3CMS  11.5
InfoModuleController.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
18 use Psr\Container\ContainerInterface;
19 use Psr\Http\Message\ResponseInterface;
20 use Psr\Http\Message\ServerRequestInterface;
26 use TYPO3\CMS\Backend\Utility\BackendUtility;
34 use TYPO3\CMS\Core\Page\PageRenderer;
38 
45 {
49  public ‪$pageinfo = [];
50 
56  protected ‪$moduleName = 'web_info';
57 
63  protected ‪$moduleTemplate;
64 
68  protected ‪$view;
69 
73  protected ‪$id;
74 
80  protected ‪$perms_clause;
81 
88  public ‪$MOD_MENU = [
89  'function' => [],
90  ];
91 
98  public ‪$MOD_SETTINGS = [];
99 
105  protected ‪$modTSconfig;
106 
113  protected ‪$modMenu_type = '';
114 
121  protected ‪$modMenu_dontValidateList = '';
122 
129  protected ‪$modMenu_setDefaultList = '';
130 
134  protected ‪$extClassConf;
135 
141  protected ‪$content = '';
142 
148  protected ‪$extObj;
149 
151  protected PageRenderer ‪$pageRenderer;
152  protected ‪UriBuilder ‪$uriBuilder;
154  protected ContainerInterface ‪$container;
156 
157  public function ‪__construct(
159  PageRenderer ‪$pageRenderer,
162  ContainerInterface ‪$container,
164  ) {
165  $this->iconFactory = ‪$iconFactory;
166  $this->pageRenderer = ‪$pageRenderer;
167  $this->uriBuilder = ‪$uriBuilder;
168  $this->flashMessageService = ‪$flashMessageService;
169  $this->container = ‪$container;
170  $this->moduleTemplateFactory = ‪$moduleTemplateFactory;
171 
172  $this->‪getLanguageService()->‪includeLLFile('EXT:info/Resources/Private/Language/locallang_mod_web_info.xlf');
173  }
174 
178  protected function ‪init(ServerRequestInterface $request)
179  {
180  $this->id = (int)($request->getQueryParams()['id'] ?? $request->getParsedBody()['id'] ?? 0);
181  $this->perms_clause = $this->‪getBackendUser()->‪getPagePermsClause(‪Permission::PAGE_SHOW);
182  $this->‪menuConfig($request);
184  }
185 
191  protected function ‪main(ServerRequestInterface $request)
192  {
193  $backendUser = $this->‪getBackendUser();
194 
195  // The page will show only if there is a valid page and if this page
196  // may be viewed by the user
197  $this->pageinfo = BackendUtility::readPageAccess($this->id, $this->perms_clause) ?: [];
198  if ($this->pageinfo !== []) {
199  $this->moduleTemplate->getDocHeaderComponent()->setMetaInformation($this->pageinfo);
200  }
201  $access = $this->pageinfo !== [];
202  if ($this->id && $access || $backendUser->isAdmin() && !$this->id) {
203  if ($backendUser->isAdmin() && !$this->id) {
204  $this->pageinfo = ['title' => '[root-level]', 'uid' => 0, 'pid' => 0];
205  }
206  // Setting up the context sensitive menu:
207  $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/ContextMenu');
208  $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/Element/ImmediateActionElement');
209 
210  $this->view = $this->‪getFluidTemplateObject();
211  $this->view->assign('id', (int)$this->id);
212  $this->view->assign('moduleName', (string)$this->uriBuilder->buildUriFromRoute($this->moduleName));
213  $this->view->assign('functionMenuModuleContent', $this->‪extObjContent($request));
214  // Setting up the buttons and markers for doc header
215  $this->‪getButtons($request);
216  $this->‪generateMenu();
217  $this->content = $this->view->render();
218  } else {
219  // If no access or if ID == zero
220  $this->content = $this->moduleTemplate->header($this->‪getLanguageService()->getLL('title'), false);
221  }
222 
223  $this->moduleTemplate->setTitle(
224  $this->‪getLanguageService()->sL($this->extClassConf['title']),
225  $this->id !== 0 && isset($this->pageinfo['title']) ? $this->pageinfo['title'] : ''
226  );
227  }
228 
236  public function ‪mainAction(ServerRequestInterface $request): ResponseInterface
237  {
238  $this->moduleTemplate = $this->moduleTemplateFactory->create($request);
239 
240  $this->‪init($request);
241 
242  // Checking for first level external objects
243  $this->‪checkExtObj($request);
244 
245  $this->‪main($request);
246 
247  $this->moduleTemplate->setContent($this->content);
248  return new ‪HtmlResponse($this->moduleTemplate->renderContent());
249  }
250 
256  protected function ‪getButtons(ServerRequestInterface $request)
257  {
258  $languageService = $this->‪getLanguageService();
259  $buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
260  // View page
261  $previewDataAttributes = ‪PreviewUriBuilder::create((int)$this->pageinfo['uid'])
262  ->withRootLine(BackendUtility::BEgetRootLine($this->pageinfo['uid']))
263  ->buildDispatcherDataAttributes();
264  $viewButton = $buttonBar->makeLinkButton()
265  ->setHref('#')
266  ->setDataAttributes($previewDataAttributes ?? [])
267  ->setTitle($languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.showPage'))
268  ->setIcon($this->iconFactory->getIcon('actions-view-page', ‪Icon::SIZE_SMALL));
269  $buttonBar->addButton($viewButton, ‪ButtonBar::BUTTON_POSITION_LEFT, 1);
270 
271  // Shortcut
272  $shortcutArguments = [
273  'id' => $request->getQueryParams()['id'] ?? 0,
274  ];
275  foreach (array_keys($this->MOD_MENU) as $key) {
276  if (!empty($this->MOD_SETTINGS[$key])) {
277  if (!is_array($shortcutArguments['SET'] ?? null)) {
278  $shortcutArguments['SET'] = [];
279  }
280  $shortcutArguments['SET'][$key] = $this->MOD_SETTINGS[$key];
281  }
282  }
283  $shortCutButton = $buttonBar->makeShortcutButton()
284  ->setRouteIdentifier($this->moduleName)
285  ->setDisplayName($this->MOD_MENU['function'][$this->MOD_SETTINGS['function']])
286  ->setArguments($shortcutArguments);
287  $buttonBar->addButton($shortCutButton, ‪ButtonBar::BUTTON_POSITION_RIGHT);
288 
289  // CSH
290  $cshButton = $buttonBar->makeHelpButton()
291  ->setModuleName('xMOD_csh_corebe')
292  ->setFieldName('pagetree_overview');
293  $buttonBar->addButton($cshButton);
294  }
295 
299  protected function ‪generateMenu()
300  {
301  $menu = $this->moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->makeMenu();
302  $menu->setIdentifier('WebInfoJumpMenu');
303  foreach ($this->MOD_MENU['function'] as $controller => $title) {
304  $item = $menu
305  ->makeMenuItem()
306  ->setHref(
307  (string)$this->uriBuilder->buildUriFromRoute(
308  $this->moduleName,
309  [
310  'id' => $this->id,
311  'SET' => [
312  'function' => $controller,
313  ],
314  ]
315  )
316  )
317  ->setTitle($title);
318  if ($controller === $this->MOD_SETTINGS['function']) {
319  $item->setActive(true);
320  }
321  $menu->addMenuItem($item);
322  }
323  $this->moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->addMenu($menu);
324  }
325 
331  protected function ‪getFluidTemplateObject()
332  {
333  ‪$view = GeneralUtility::makeInstance(StandaloneView::class);
334  ‪$view->‪setLayoutRootPaths([GeneralUtility::getFileAbsFileName('EXT:info/Resources/Private/Layouts')]);
335  ‪$view->‪setPartialRootPaths([GeneralUtility::getFileAbsFileName('EXT:info/Resources/Private/Partials')]);
336  ‪$view->‪setTemplateRootPaths([GeneralUtility::getFileAbsFileName('EXT:info/Resources/Private/Templates')]);
337 
338  ‪$view->‪setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName('EXT:info/Resources/Private/Templates/Main.html'));
339 
341  return ‪$view;
342  }
343 
349  protected function ‪menuConfig(ServerRequestInterface $request)
350  {
351  // Page / user TSconfig settings and blinding of menu-items
352  $this->modTSconfig['properties'] = BackendUtility::getPagesTSconfig($this->id)['mod.']['web_info.'] ?? [];
353  $this->MOD_MENU['function'] = $this->‪mergeExternalItems('web_info', 'function', $this->MOD_MENU['function']);
354  $blindActions = $this->modTSconfig['properties']['menu.']['function.'] ?? [];
355  foreach ($blindActions as $key => $value) {
356  if (!$value && array_key_exists($key, $this->MOD_MENU['function'])) {
357  unset($this->MOD_MENU['function'][$key]);
358  }
359  }
360  $moduleSet = $request->getParsedBody()['SET'] ?? $request->getQueryParams()['SET'] ?? [];
361  $this->MOD_SETTINGS = BackendUtility::getModuleData($this->MOD_MENU, $moduleSet, 'web_info', $this->modMenu_type, $this->modMenu_dontValidateList, $this->modMenu_setDefaultList);
362  }
363 
373  protected function ‪mergeExternalItems($modName, $menuKey, $menuArr)
374  {
375  $mergeArray = ‪$GLOBALS['TBE_MODULES_EXT'][$modName]['MOD_MENU'][$menuKey];
376  if (is_array($mergeArray)) {
377  $backendUser = $this->‪getBackendUser();
378  foreach ($mergeArray as $k => $v) {
379  if (((string)$v['ws'] === '' || ($backendUser->workspace === 0 && GeneralUtility::inList($v['ws'], 'online')))
380  || ($backendUser->workspace > 0 && GeneralUtility::inList($v['ws'], 'custom'))
381  ) {
382  $menuArr[$k] = $this->‪getLanguageService()->‪sL($v['title']);
383  }
384  }
385  }
386  return $menuArr;
387  }
388 
395  protected function ‪handleExternalFunctionValue($MM_key = 'function', $MS_value = null)
396  {
397  if ($MS_value === null) {
398  $MS_value = $this->MOD_SETTINGS[$MM_key];
399  }
400  $this->extClassConf = $this->‪getExternalItemConfig('web_info', $MM_key, $MS_value);
401  }
402 
413  protected function ‪getExternalItemConfig($modName, $menuKey, $value = '')
414  {
415  if (isset(‪$GLOBALS['TBE_MODULES_EXT'][$modName])) {
416  return (string)$value !== ''
417  ? ‪$GLOBALS['TBE_MODULES_EXT'][$modName]['MOD_MENU'][$menuKey][$value]
418  : ‪$GLOBALS['TBE_MODULES_EXT'][$modName]['MOD_MENU'][$menuKey];
419  }
420  return null;
421  }
422 
429  protected function ‪checkExtObj(ServerRequestInterface $request)
430  {
431  if (is_array($this->extClassConf) && $this->extClassConf['name']) {
432  if ($this->container->has($this->extClassConf['name'])) {
433  $this->extObj = $this->container->get($this->extClassConf['name']);
434  } else {
435  $this->extObj = GeneralUtility::makeInstance($this->extClassConf['name']);
436  }
437  if (is_callable([$this->extObj, 'init'])) {
438  $this->extObj->init($this, $request);
439  }
440  // Re-write:
441  $moduleSet = $request->getParsedBody()['SET'] ?? $request->getQueryParams()['SET'] ?? [];
442  $this->MOD_SETTINGS = BackendUtility::getModuleData($this->MOD_MENU, $moduleSet, 'web_info', $this->modMenu_type, $this->modMenu_dontValidateList, $this->modMenu_setDefaultList);
443  }
444  }
445 
449  protected function ‪extObjContent(ServerRequestInterface $request)
450  {
451  if ($this->extObj === null) {
452  $languageService = $this->‪getLanguageService();
453  $flashMessage = GeneralUtility::makeInstance(
454  FlashMessage::class,
455  $languageService->sL('LLL:EXT:backend/Resources/Private/Language/locallang.xlf:no_modules_registered'),
456  $languageService->getLL('title'),
458  );
459  $defaultFlashMessageQueue = $this->flashMessageService->getMessageQueueByIdentifier();
460  $defaultFlashMessageQueue->enqueue($flashMessage);
461  } else {
462  if (is_callable([$this->extObj, 'main'])) {
463  $main = $this->extObj->main($request);
464  if ($main instanceof ResponseInterface) {
465  $stream = $main->getBody();
466  $stream->rewind();
467  $main = $stream->getContents();
468  }
469  return $main;
470  }
471  }
472  }
473 
477  protected function ‪getLanguageService(): LanguageService
478  {
479  return ‪$GLOBALS['LANG'];
480  }
481 
485  protected function ‪getBackendUser(): BackendUserAuthentication
486  {
487  return ‪$GLOBALS['BE_USER'];
488  }
489 }
‪TYPO3\CMS\Info\Controller\InfoModuleController\extObjContent
‪extObjContent(ServerRequestInterface $request)
Definition: InfoModuleController.php:435
‪TYPO3\CMS\Core\Imaging\Icon\SIZE_SMALL
‪const SIZE_SMALL
Definition: Icon.php:30
‪TYPO3\CMS\Info\Controller\InfoModuleController
Definition: InfoModuleController.php:45
‪TYPO3\CMS\Backend\Template\Components\ButtonBar\BUTTON_POSITION_LEFT
‪const BUTTON_POSITION_LEFT
Definition: ButtonBar.php:36
‪TYPO3\CMS\Backend\Template\Components\ButtonBar
Definition: ButtonBar.php:32
‪TYPO3\CMS\Info\Controller\InfoModuleController\$MOD_SETTINGS
‪array $MOD_SETTINGS
Definition: InfoModuleController.php:91
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\getPagePermsClause
‪string getPagePermsClause($perms)
Definition: BackendUserAuthentication.php:460
‪TYPO3\CMS\Backend\Routing\PreviewUriBuilder\create
‪static static create(int $pageId, string $alternativeUri=null)
Definition: PreviewUriBuilder.php:75
‪TYPO3\CMS\Core\Imaging\Icon
Definition: Icon.php:26
‪TYPO3\CMS\Backend\Template\ModuleTemplateFactory
Definition: ModuleTemplateFactory.php:29
‪TYPO3\CMS\Info\Controller\InfoModuleController\getBackendUser
‪BackendUserAuthentication getBackendUser()
Definition: InfoModuleController.php:471
‪TYPO3\CMS\Info\Controller\InfoModuleController\$modTSconfig
‪array $modTSconfig
Definition: InfoModuleController.php:97
‪TYPO3\CMS\Info\Controller\InfoModuleController\$pageRenderer
‪PageRenderer $pageRenderer
Definition: InfoModuleController.php:137
‪TYPO3\CMS\Info\Controller\InfoModuleController\$id
‪$id
Definition: InfoModuleController.php:69
‪TYPO3\CMS\Info\Controller\InfoModuleController\$moduleTemplateFactory
‪ModuleTemplateFactory $moduleTemplateFactory
Definition: InfoModuleController.php:141
‪TYPO3\CMS\Info\Controller\InfoModuleController\getButtons
‪getButtons(ServerRequestInterface $request)
Definition: InfoModuleController.php:242
‪TYPO3\CMS\Info\Controller\InfoModuleController\getExternalItemConfig
‪mixed getExternalItemConfig($modName, $menuKey, $value='')
Definition: InfoModuleController.php:399
‪TYPO3\CMS\Core\Imaging\IconFactory
Definition: IconFactory.php:34
‪TYPO3\CMS\Info\Controller\InfoModuleController\__construct
‪__construct(IconFactory $iconFactory, PageRenderer $pageRenderer, UriBuilder $uriBuilder, FlashMessageService $flashMessageService, ContainerInterface $container, ModuleTemplateFactory $moduleTemplateFactory)
Definition: InfoModuleController.php:143
‪TYPO3\CMS\Info\Controller\InfoModuleController\$uriBuilder
‪UriBuilder $uriBuilder
Definition: InfoModuleController.php:138
‪TYPO3\CMS\Core\Localization\LanguageService\sL
‪string sL($input)
Definition: LanguageService.php:161
‪TYPO3\CMS\Info\Controller\InfoModuleController\mainAction
‪ResponseInterface mainAction(ServerRequestInterface $request)
Definition: InfoModuleController.php:222
‪TYPO3\CMS\Info\Controller\InfoModuleController\$MOD_MENU
‪array $MOD_MENU
Definition: InfoModuleController.php:82
‪TYPO3\CMS\Info\Controller\InfoModuleController\$container
‪ContainerInterface $container
Definition: InfoModuleController.php:140
‪TYPO3\CMS\Info\Controller\InfoModuleController\main
‪main(ServerRequestInterface $request)
Definition: InfoModuleController.php:177
‪TYPO3\CMS\Info\Controller\InfoModuleController\$moduleName
‪string $moduleName
Definition: InfoModuleController.php:54
‪TYPO3\CMS\Backend\Template\ModuleTemplate
Definition: ModuleTemplate.php:46
‪TYPO3\CMS\Core\Type\Bitmask\Permission
Definition: Permission.php:26
‪TYPO3\CMS\Fluid\View\StandaloneView\getRequest
‪TYPO3 CMS Extbase Mvc Request getRequest()
Definition: StandaloneView.php:93
‪TYPO3\CMS\Info\Controller\InfoModuleController\init
‪init(ServerRequestInterface $request)
Definition: InfoModuleController.php:164
‪TYPO3\CMS\Info\Controller\InfoModuleController\$extObj
‪object $extObj
Definition: InfoModuleController.php:134
‪TYPO3\CMS\Info\Controller\InfoModuleController\menuConfig
‪menuConfig(ServerRequestInterface $request)
Definition: InfoModuleController.php:335
‪TYPO3\CMS\Info\Controller\InfoModuleController\$modMenu_type
‪string $modMenu_type
Definition: InfoModuleController.php:104
‪TYPO3\CMS\Info\Controller\InfoModuleController\getLanguageService
‪LanguageService getLanguageService()
Definition: InfoModuleController.php:463
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:40
‪TYPO3\CMS\Info\Controller\InfoModuleController\$moduleTemplate
‪ModuleTemplate $moduleTemplate
Definition: InfoModuleController.php:60
‪TYPO3\CMS\Extbase\Mvc\Request\setControllerExtensionName
‪setControllerExtensionName($controllerExtensionName)
Definition: Request.php:305
‪TYPO3\CMS\Fluid\View\AbstractTemplateView\setTemplatePathAndFilename
‪setTemplatePathAndFilename($templatePathAndFilename)
Definition: AbstractTemplateView.php:113
‪TYPO3\CMS\Info\Controller\InfoModuleController\$iconFactory
‪IconFactory $iconFactory
Definition: InfoModuleController.php:136
‪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\Info\Controller\InfoModuleController\mergeExternalItems
‪array mergeExternalItems($modName, $menuKey, $menuArr)
Definition: InfoModuleController.php:359
‪TYPO3\CMS\Info\Controller\InfoModuleController\getFluidTemplateObject
‪StandaloneView getFluidTemplateObject()
Definition: InfoModuleController.php:317
‪TYPO3\CMS\Info\Controller\InfoModuleController\$pageinfo
‪array $pageinfo
Definition: InfoModuleController.php:48
‪TYPO3\CMS\Info\Controller\InfoModuleController\handleExternalFunctionValue
‪handleExternalFunctionValue($MM_key='function', $MS_value=null)
Definition: InfoModuleController.php:381
‪TYPO3\CMS\Info\Controller\InfoModuleController\checkExtObj
‪checkExtObj(ServerRequestInterface $request)
Definition: InfoModuleController.php:415
‪TYPO3\CMS\Core\Messaging\FlashMessage
Definition: FlashMessage.php:26
‪TYPO3\CMS\Fluid\View\StandaloneView
Definition: StandaloneView.php:31
‪TYPO3\CMS\Info\Controller\InfoModuleController\$perms_clause
‪string $perms_clause
Definition: InfoModuleController.php:75
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Backend\Routing\PreviewUriBuilder
Definition: PreviewUriBuilder.php:32
‪TYPO3\CMS\Fluid\View\AbstractTemplateView\setLayoutRootPaths
‪setLayoutRootPaths(array $layoutRootPaths)
Definition: AbstractTemplateView.php:177
‪TYPO3\CMS\Core\Localization\LanguageService\includeLLFile
‪array includeLLFile($fileRef)
Definition: LanguageService.php:271
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:42
‪TYPO3\CMS\Fluid\View\AbstractTemplateView\setPartialRootPaths
‪setPartialRootPaths(array $partialRootPaths)
Definition: AbstractTemplateView.php:144
‪TYPO3\CMS\Info\Controller\InfoModuleController\$content
‪string $content
Definition: InfoModuleController.php:128
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Info\Controller\InfoModuleController\$modMenu_dontValidateList
‪string $modMenu_dontValidateList
Definition: InfoModuleController.php:111
‪TYPO3\CMS\Info\Controller\InfoModuleController\$extClassConf
‪array $extClassConf
Definition: InfoModuleController.php:122
‪TYPO3\CMS\Info\Controller\InfoModuleController\$flashMessageService
‪FlashMessageService $flashMessageService
Definition: InfoModuleController.php:139
‪TYPO3\CMS\Backend\Template\Components\ButtonBar\BUTTON_POSITION_RIGHT
‪const BUTTON_POSITION_RIGHT
Definition: ButtonBar.php:41
‪TYPO3\CMS\Info\Controller\InfoModuleController\$view
‪StandaloneView $view
Definition: InfoModuleController.php:64
‪TYPO3\CMS\Core\Messaging\FlashMessageService
Definition: FlashMessageService.php:27
‪TYPO3\CMS\Info\Controller
Definition: InfoModuleController.php:16
‪TYPO3\CMS\Core\Messaging\AbstractMessage\ERROR
‪const ERROR
Definition: AbstractMessage.php:31
‪TYPO3\CMS\Info\Controller\InfoModuleController\$modMenu_setDefaultList
‪string $modMenu_setDefaultList
Definition: InfoModuleController.php:118
‪TYPO3\CMS\Core\Http\HtmlResponse
Definition: HtmlResponse.php:26
‪TYPO3\CMS\Info\Controller\InfoModuleController\generateMenu
‪generateMenu()
Definition: InfoModuleController.php:285
‪TYPO3\CMS\Fluid\View\AbstractTemplateView\setTemplateRootPaths
‪setTemplateRootPaths(array $templateRootPaths)
Definition: AbstractTemplateView.php:124