‪TYPO3CMS  ‪main
InfoModuleController.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\EventDispatcher\EventDispatcherInterface;
21 use Psr\Http\Message\ResponseInterface;
22 use Psr\Http\Message\ServerRequestInterface;
31 use TYPO3\CMS\Backend\Utility\BackendUtility;
35 use TYPO3\CMS\Core\Imaging\IconSize;
41 
47 #[AsController]
49 {
52  public array ‪$pageinfo = [];
53 
57  protected int ‪$id;
58 
59  public function ‪__construct(
60  protected readonly ‪IconFactory $iconFactory,
61  protected readonly ‪UriBuilder $uriBuilder,
62  protected readonly ‪ModuleProvider $moduleProvider,
63  protected readonly ‪PageRenderer $pageRenderer,
64  protected readonly ‪ModuleTemplateFactory $moduleTemplateFactory,
65  protected readonly EventDispatcherInterface $eventDispatcher,
66  ) {}
67 
71  protected function ‪init(ServerRequestInterface $request): void
72  {
73  $this->id = (int)($request->getQueryParams()['id'] ?? $request->getParsedBody()['id'] ?? 0);
74  $this->view = $this->moduleTemplateFactory->create($request);
75  $this->currentModule = $request->getAttribute('module');
76  $this->pageinfo = BackendUtility::readPageAccess($this->id, $this->‪getBackendUser()->getPagePermsClause(‪Permission::PAGE_SHOW)) ?: [];
77  $this->view->setTitle(
78  $this->‪getLanguageService()->sL($this->currentModule->getTitle()),
79  $this->id !== 0 && isset($this->pageinfo['title']) ? $this->pageinfo['title'] : ''
80  );
81  // The page will show only if there is a valid page and if this page
82  // may be viewed by the user
83  if ($this->pageinfo !== []) {
84  $this->view->getDocHeaderComponent()->setMetaInformation($this->pageinfo);
85  }
86  $accessContent = false;
87  $backendUser = $this->‪getBackendUser();
88  if (($this->id && $this->pageinfo !== []) || ($backendUser->isAdmin() && !$this->id)) {
89  $accessContent = true;
90  if (!$this->id && $backendUser->isAdmin()) {
91  $this->pageinfo = ['title' => '[root-level]', 'uid' => 0, 'pid' => 0];
92  }
93  $this->view->assign('id', $this->id);
94  $this->view->assign('formAction', (string)$this->uriBuilder->buildUriFromRoute($this->currentModule->getIdentifier()));
95  // Setting up the buttons and the module menu for the doc header
96  $this->‪getButtons();
97  $this->view->makeDocHeaderModuleMenu(['id' => $this->id]);
98  }
99  $event = $this->eventDispatcher->dispatch(
100  new ‪ModifyInfoModuleContentEvent($accessContent, $request, $this->currentModule, $this->view)
101  );
102  $this->view->assignMultiple([
103  'accessContent' => $accessContent,
104  'headerContent' => $event->getHeaderContent(),
105  'footerContent' => $event->getFooterContent(),
106  ]);
107  }
108 
112  public function ‪handleRequest(ServerRequestInterface $request): ResponseInterface
113  {
114  $this->‪init($request);
115  return $this->view->renderResponse('Main');
116  }
117 
121  protected function ‪getButtons(): void
122  {
123  $buttonBar = $this->view->getDocHeaderComponent()->getButtonBar();
124 
125  if ($this->id) {
126  // View
127  $pagesTSconfig = BackendUtility::getPagesTSconfig($this->pageinfo['uid']);
128  if (isset($pagesTSconfig['TCEMAIN.']['preview.']['disableButtonForDokType'])) {
129  $excludeDokTypes = ‪GeneralUtility::intExplode(
130  ',',
131  (string)$pagesTSconfig['TCEMAIN.']['preview.']['disableButtonForDokType'],
132  true
133  );
134  } else {
135  // exclude sysfolders and spacers by default
136  $excludeDokTypes = [
139  ];
140  }
141  if (!in_array((int)$this->pageinfo['doktype'], $excludeDokTypes, true)) {
142  // View page
143  $previewDataAttributes = ‪PreviewUriBuilder::create((int)$this->pageinfo['uid'])
144  ->withRootLine(BackendUtility::BEgetRootLine($this->pageinfo['uid']))
145  ->buildDispatcherDataAttributes();
146  $viewButton = $buttonBar->makeLinkButton()
147  ->setHref('#')
148  ->setDataAttributes($previewDataAttributes ?? [])
149  ->setDisabled(!$previewDataAttributes)
150  ->setTitle($this->‪getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.showPage'))
151  ->setIcon($this->iconFactory->getIcon('actions-view-page', IconSize::SMALL))
152  ->setShowLabelText(true);
153  $buttonBar->addButton($viewButton, ‪ButtonBar::BUTTON_POSITION_LEFT);
154  }
155  }
156 
157  // Shortcut
158  $shortcutButton = $buttonBar->makeShortcutButton()
159  ->setRouteIdentifier($this->currentModule->getIdentifier())
160  ->setDisplayName($this->currentModule->getTitle())
161  ->setArguments(['id' => $this->id]);
162  $buttonBar->addButton($shortcutButton, ‪ButtonBar::BUTTON_POSITION_RIGHT);
163  }
164 
166  {
167  return ‪$GLOBALS['LANG'];
168  }
169 
171  {
172  return ‪$GLOBALS['BE_USER'];
173  }
174 }
‪TYPO3\CMS\Info\Controller\InfoModuleController\getButtons
‪getButtons()
Definition: InfoModuleController.php:121
‪TYPO3\CMS\Info\Controller\InfoModuleController
Definition: InfoModuleController.php:49
‪TYPO3\CMS\Backend\Template\Components\ButtonBar\BUTTON_POSITION_LEFT
‪const BUTTON_POSITION_LEFT
Definition: ButtonBar.php:37
‪TYPO3\CMS\Backend\Template\Components\ButtonBar
Definition: ButtonBar.php:33
‪TYPO3\CMS\Info\Controller\InfoModuleController\__construct
‪__construct(protected readonly IconFactory $iconFactory, protected readonly UriBuilder $uriBuilder, protected readonly ModuleProvider $moduleProvider, protected readonly PageRenderer $pageRenderer, protected readonly ModuleTemplateFactory $moduleTemplateFactory, protected readonly EventDispatcherInterface $eventDispatcher,)
Definition: InfoModuleController.php:59
‪TYPO3\CMS\Backend\Template\ModuleTemplateFactory
Definition: ModuleTemplateFactory.php:33
‪TYPO3\CMS\Info\Controller\InfoModuleController\$view
‪ModuleTemplate $view
Definition: InfoModuleController.php:51
‪TYPO3\CMS\Info\Controller\InfoModuleController\getBackendUser
‪getBackendUser()
Definition: InfoModuleController.php:170
‪TYPO3\CMS\Info\Controller\InfoModuleController\handleRequest
‪handleRequest(ServerRequestInterface $request)
Definition: InfoModuleController.php:112
‪TYPO3\CMS\Core\Imaging\IconFactory
Definition: IconFactory.php:34
‪TYPO3\CMS\Info\Controller\InfoModuleController\getLanguageService
‪getLanguageService()
Definition: InfoModuleController.php:165
‪TYPO3\CMS\Backend\Module\ModuleProvider
Definition: ModuleProvider.php:29
‪TYPO3\CMS\Backend\Template\ModuleTemplate
Definition: ModuleTemplate.php:46
‪TYPO3\CMS\Core\Type\Bitmask\Permission
Definition: Permission.php:26
‪TYPO3\CMS\Info\Controller\InfoModuleController\init
‪init(ServerRequestInterface $request)
Definition: InfoModuleController.php:71
‪TYPO3\CMS\Info\Controller\Event\ModifyInfoModuleContentEvent
Definition: ModifyInfoModuleContentEvent.php:28
‪TYPO3\CMS\Core\Page\PageRenderer
Definition: PageRenderer.php:44
‪TYPO3\CMS\Info\Controller\InfoModuleController\$currentModule
‪ModuleInterface $currentModule
Definition: InfoModuleController.php:50
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:44
‪TYPO3\CMS\Backend\Routing\PreviewUriBuilder\create
‪static static create(int $pageId)
Definition: PreviewUriBuilder.php:65
‪TYPO3\CMS\Core\Domain\Repository\PageRepository\DOKTYPE_SPACER
‪const DOKTYPE_SPACER
Definition: PageRepository.php:103
‪TYPO3\CMS\Backend\Module\ModuleInterface
Definition: ModuleInterface.php:24
‪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\Core\Domain\Repository\PageRepository\DOKTYPE_SYSFOLDER
‪const DOKTYPE_SYSFOLDER
Definition: PageRepository.php:104
‪TYPO3\CMS\Info\Controller\InfoModuleController\$pageinfo
‪array $pageinfo
Definition: InfoModuleController.php:52
‪TYPO3\CMS\Info\Controller\InfoModuleController\$id
‪int $id
Definition: InfoModuleController.php:57
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Backend\Routing\PreviewUriBuilder
Definition: PreviewUriBuilder.php:44
‪TYPO3\CMS\Backend\Attribute\AsController
Definition: AsController.php:25
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:46
‪TYPO3\CMS\Core\Domain\Repository\PageRepository
Definition: PageRepository.php:69
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Backend\Template\Components\ButtonBar\BUTTON_POSITION_RIGHT
‪const BUTTON_POSITION_RIGHT
Definition: ButtonBar.php:42
‪TYPO3\CMS\Core\Utility\GeneralUtility\intExplode
‪static list< int > intExplode(string $delimiter, string $string, bool $removeEmptyValues=false)
Definition: GeneralUtility.php:756
‪TYPO3\CMS\Info\Controller