‪TYPO3CMS  10.4
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;
34 
41 {
45  public ‪$pageinfo;
46 
52  protected ‪$moduleName = 'web_info';
53 
59  protected ‪$moduleTemplate;
60 
64  protected ‪$view;
65 
69  protected ‪$uriBuilder;
70 
74  protected ‪$flashMessageService;
75 
79  protected ‪$container;
80 
84  protected ‪$id;
85 
91  protected ‪$perms_clause;
92 
99  public ‪$MOD_MENU = [
100  'function' => []
101  ];
102 
109  public ‪$MOD_SETTINGS = [];
110 
116  protected ‪$modTSconfig;
117 
124  protected ‪$modMenu_type = '';
125 
132  protected ‪$modMenu_dontValidateList = '';
133 
140  protected ‪$modMenu_setDefaultList = '';
141 
145  protected ‪$extClassConf;
146 
152  protected ‪$content = '';
153 
159  protected ‪$extObj;
160 
164  public function ‪__construct(
168  ContainerInterface ‪$container
169  ) {
170  $this->moduleTemplate = ‪$moduleTemplate;
171  $this->uriBuilder = ‪$uriBuilder;
172  $this->flashMessageService = ‪$flashMessageService;
173  $this->container = ‪$container;
174 
175  $languageService = $this->‪getLanguageService();
176  $languageService->includeLLFile('EXT:info/Resources/Private/Language/locallang_mod_web_info.xlf');
177  }
178 
182  protected function ‪init()
183  {
184  $this->id = (int)GeneralUtility::_GP('id');
185  $this->perms_clause = $this->‪getBackendUser()->‪getPagePermsClause(‪Permission::PAGE_SHOW);
186  $this->‪menuConfig();
188  }
189 
193  protected function ‪main()
194  {
195  $languageService = $this->‪getLanguageService();
196  $backendUser = $this->‪getBackendUser();
197 
198  // The page will show only if there is a valid page and if this page
199  // may be viewed by the user
200  $this->pageinfo = ‪BackendUtility::readPageAccess($this->id, $this->perms_clause);
201  if ($this->pageinfo) {
202  $this->moduleTemplate->getDocHeaderComponent()->setMetaInformation($this->pageinfo);
203  }
204  $access = is_array($this->pageinfo);
205  if ($this->id && $access || $backendUser->isAdmin() && !$this->id) {
206  if ($backendUser->isAdmin() && !$this->id) {
207  $this->pageinfo = ['title' => '[root-level]', 'uid' => 0, 'pid' => 0];
208  }
209  // JavaScript
210  $this->moduleTemplate->addJavaScriptCode(
211  'WebFuncInLineJS',
212  'if (top.fsMod) top.fsMod.recentIds["web"] = ' . (int)$this->id . ';
213  '
214  );
215  // Setting up the context sensitive menu:
216  $this->moduleTemplate->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/ContextMenu');
217 
218  $this->view = $this->‪getFluidTemplateObject();
219  $this->view->assign('moduleName', (string)$this->uriBuilder->buildUriFromRoute($this->moduleName));
220  $this->view->assign('functionMenuModuleContent', $this->‪getExtObjContent());
221  // Setting up the buttons and markers for doc header
222  $this->‪getButtons();
223  $this->‪generateMenu();
224  $this->content .= $this->view->render();
225  } else {
226  // If no access or if ID == zero
227  $this->content = $this->moduleTemplate->header($languageService->getLL('title'));
228  }
229  }
230 
238  public function ‪mainAction(ServerRequestInterface $request): ResponseInterface
239  {
240  // @deprecated and will be removed in TYPO3 v10.0.
241  // @todo: PageLayoutView / $dblist used by PageInformationController still relies on this being set at the moment,
242  // @todo: otherwise the "pages_levels" / "depth" information gets lost rendering the Pagetree Overview.
243  ‪$GLOBALS['SOBE'] = $this;
244 
245  $this->‪init();
246 
247  // Checking for first level external objects
248  $this->‪checkExtObj();
249 
250  $this->‪main();
251 
252  $this->moduleTemplate->setContent($this->content);
253  return new ‪HtmlResponse($this->moduleTemplate->renderContent());
254  }
255 
259  protected function ‪getButtons()
260  {
261  $languageService = $this->‪getLanguageService();
262  $buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
263  // View page
264  $viewButton = $buttonBar->makeLinkButton()
265  ->setHref('#')
266  ->setOnClick(‪BackendUtility::viewOnClick(
267  $this->pageinfo['uid'],
268  '',
269  ‪BackendUtility::BEgetRootLine($this->pageinfo['uid'])
270  ))
271  ->setTitle($languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.showPage'))
272  ->setIcon($this->moduleTemplate->getIconFactory()->getIcon('actions-view-page', ‪Icon::SIZE_SMALL));
273  $buttonBar->addButton($viewButton, ‪ButtonBar::BUTTON_POSITION_LEFT, 1);
274  // Shortcut
275  $shortCutButton = $buttonBar->makeShortcutButton()
276  ->setModuleName($this->moduleName)
277  ->setDisplayName($this->MOD_MENU['function'][$this->MOD_SETTINGS['function']])
278  ->setGetVariables([
279  'route',
280  'id',
281  'edit_record',
282  'pointer',
283  'search_field',
284  'search_levels',
285  'showLimit'
286  ])
287  ->setSetVariables(array_keys($this->MOD_MENU));
288  $buttonBar->addButton($shortCutButton, ‪ButtonBar::BUTTON_POSITION_RIGHT);
289 
290  // CSH
291  $cshButton = $buttonBar->makeHelpButton()
292  ->setModuleName('xMOD_csh_corebe')
293  ->setFieldName('pagetree_overview');
294  $buttonBar->addButton($cshButton);
295  }
296 
300  protected function ‪generateMenu()
301  {
302  $menu = $this->moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->makeMenu();
303  $menu->setIdentifier('WebInfoJumpMenu');
304  foreach ($this->MOD_MENU['function'] as $controller => $title) {
305  $item = $menu
306  ->makeMenuItem()
307  ->setHref(
308  (string)$this->uriBuilder->buildUriFromRoute(
309  $this->moduleName,
310  [
311  'id' => $this->id,
312  'SET' => [
313  'function' => $controller
314  ]
315  ]
316  )
317  )
318  ->setTitle($title);
319  if ($controller === $this->MOD_SETTINGS['function']) {
320  $item->setActive(true);
321  }
322  $menu->addMenuItem($item);
323  }
324  $this->moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->addMenu($menu);
325  }
326 
332  protected function ‪getFluidTemplateObject()
333  {
334  ‪$view = GeneralUtility::makeInstance(StandaloneView::class);
335  ‪$view->‪setLayoutRootPaths([GeneralUtility::getFileAbsFileName('EXT:info/Resources/Private/Layouts')]);
336  ‪$view->‪setPartialRootPaths([GeneralUtility::getFileAbsFileName('EXT:info/Resources/Private/Partials')]);
337  ‪$view->‪setTemplateRootPaths([GeneralUtility::getFileAbsFileName('EXT:info/Resources/Private/Templates')]);
338 
339  ‪$view->‪setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName('EXT:info/Resources/Private/Templates/Main.html'));
340 
342  return ‪$view;
343  }
344 
350  protected function ‪menuConfig()
351  {
352  // Page / user TSconfig settings and blinding of menu-items
353  $this->modTSconfig['properties'] = ‪BackendUtility::getPagesTSconfig($this->id)['mod.']['web_info.'] ?? [];
354  $this->MOD_MENU['function'] = $this->‪mergeExternalItems('web_info', 'function', $this->MOD_MENU['function']);
355  $blindActions = $this->modTSconfig['properties']['menu.']['function.'] ?? [];
356  foreach ($blindActions as $key => $value) {
357  if (!$value && array_key_exists($key, $this->MOD_MENU['function'])) {
358  unset($this->MOD_MENU['function'][$key]);
359  }
360  }
361  $this->MOD_SETTINGS = ‪BackendUtility::getModuleData($this->MOD_MENU, GeneralUtility::_GP('SET'), '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 === -1 && GeneralUtility::inList($v['ws'], 'offline')
381  || $backendUser->workspace > 0 && GeneralUtility::inList($v['ws'], 'custom')
382  ) {
383  $menuArr[$k] = $this->‪getLanguageService()->‪sL($v['title']);
384  }
385  }
386  }
387  return $menuArr;
388  }
389 
396  protected function ‪handleExternalFunctionValue($MM_key = 'function', $MS_value = null)
397  {
398  if ($MS_value === null) {
399  $MS_value = $this->MOD_SETTINGS[$MM_key];
400  }
401  $this->extClassConf = $this->‪getExternalItemConfig('web_info', $MM_key, $MS_value);
402  }
403 
414  protected function ‪getExternalItemConfig($modName, $menuKey, $value = '')
415  {
416  if (isset(‪$GLOBALS['TBE_MODULES_EXT'][$modName])) {
417  return (string)$value !== ''
418  ? ‪$GLOBALS['TBE_MODULES_EXT'][$modName]['MOD_MENU'][$menuKey][$value]
419  : ‪$GLOBALS['TBE_MODULES_EXT'][$modName]['MOD_MENU'][$menuKey];
420  }
421  return null;
422  }
423 
430  protected function ‪checkExtObj()
431  {
432  if (is_array($this->extClassConf) && $this->extClassConf['name']) {
433  if ($this->container->has($this->extClassConf['name'])) {
434  $this->extObj = $this->container->get($this->extClassConf['name']);
435  } else {
436  $this->extObj = GeneralUtility::makeInstance($this->extClassConf['name']);
437  }
438  if (is_callable([$this->extObj, 'init'])) {
439  $this->extObj->init($this);
440  }
441  // Re-write:
442  $this->MOD_SETTINGS = ‪BackendUtility::getModuleData($this->MOD_MENU, GeneralUtility::_GP('SET'), 'web_info', $this->modMenu_type, $this->modMenu_dontValidateList, $this->modMenu_setDefaultList);
443  }
444  }
445 
449  protected function ‪extObjContent()
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  );
460  $defaultFlashMessageQueue = $this->flashMessageService->getMessageQueueByIdentifier();
461  $defaultFlashMessageQueue->enqueue($flashMessage);
462  } else {
463  if (is_callable([$this->extObj, 'main'])) {
464  $main = $this->extObj->main();
465  if ($main instanceof ResponseInterface) {
466  $stream = $main->getBody();
467  $stream->rewind();
468  $main = $stream->getContents();
469  }
470  $this->content .= $main;
471  }
472  }
473  }
474 
480  protected function ‪getExtObjContent()
481  {
482  $savedContent = ‪$this->content;
483  $this->content = '';
485  $newContent = ‪$this->content;
486  $this->content = $savedContent;
487  return $newContent;
488  }
489 
493  protected function ‪getLanguageService(): ‪LanguageService
494  {
495  return ‪$GLOBALS['LANG'];
496  }
497 
501  protected function ‪getBackendUser(): BackendUserAuthentication
502  {
503  return ‪$GLOBALS['BE_USER'];
504  }
505 }
‪TYPO3\CMS\Core\Imaging\Icon\SIZE_SMALL
‪const SIZE_SMALL
Definition: Icon.php:30
‪TYPO3\CMS\Info\Controller\InfoModuleController\getButtons
‪getButtons()
Definition: InfoModuleController.php:242
‪TYPO3\CMS\Info\Controller\InfoModuleController
Definition: InfoModuleController.php:41
‪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:99
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\getPagePermsClause
‪string getPagePermsClause($perms)
Definition: BackendUserAuthentication.php:499
‪TYPO3\CMS\Core\Imaging\Icon
Definition: Icon.php:26
‪TYPO3\CMS\Info\Controller\InfoModuleController\getExtObjContent
‪string getExtObjContent()
Definition: InfoModuleController.php:463
‪TYPO3\CMS\Info\Controller\InfoModuleController\getBackendUser
‪BackendUserAuthentication getBackendUser()
Definition: InfoModuleController.php:484
‪TYPO3\CMS\Info\Controller\InfoModuleController\$modTSconfig
‪array $modTSconfig
Definition: InfoModuleController.php:105
‪TYPO3\CMS\Info\Controller\InfoModuleController\$id
‪$id
Definition: InfoModuleController.php:77
‪TYPO3\CMS\Info\Controller\InfoModuleController\extObjContent
‪extObjContent()
Definition: InfoModuleController.php:432
‪TYPO3\CMS\Info\Controller\InfoModuleController\getExternalItemConfig
‪mixed getExternalItemConfig($modName, $menuKey, $value='')
Definition: InfoModuleController.php:397
‪TYPO3\CMS\Info\Controller\InfoModuleController\$uriBuilder
‪UriBuilder $uriBuilder
Definition: InfoModuleController.php:64
‪TYPO3\CMS\Info\Controller\InfoModuleController\init
‪init()
Definition: InfoModuleController.php:165
‪TYPO3\CMS\Core\Localization\LanguageService\sL
‪string sL($input)
Definition: LanguageService.php:194
‪TYPO3\CMS\Backend\Utility\BackendUtility\BEgetRootLine
‪static array BEgetRootLine($uid, $clause='', $workspaceOL=false, array $additionalFields=[])
Definition: BackendUtility.php:343
‪TYPO3\CMS\Info\Controller\InfoModuleController\mainAction
‪ResponseInterface mainAction(ServerRequestInterface $request)
Definition: InfoModuleController.php:221
‪TYPO3\CMS\Info\Controller\InfoModuleController\main
‪main()
Definition: InfoModuleController.php:176
‪TYPO3\CMS\Info\Controller\InfoModuleController\$MOD_MENU
‪array $MOD_MENU
Definition: InfoModuleController.php:90
‪TYPO3\CMS\Info\Controller\InfoModuleController\$container
‪ContainerInterface $container
Definition: InfoModuleController.php:72
‪TYPO3\CMS\Info\Controller\InfoModuleController\$moduleName
‪string $moduleName
Definition: InfoModuleController.php:50
‪TYPO3\CMS\Backend\Template\ModuleTemplate
Definition: ModuleTemplate.php:43
‪TYPO3\CMS\Info\Controller\InfoModuleController\__construct
‪__construct(ModuleTemplate $moduleTemplate, UriBuilder $uriBuilder, FlashMessageService $flashMessageService, ContainerInterface $container)
Definition: InfoModuleController.php:147
‪TYPO3\CMS\Core\Type\Bitmask\Permission
Definition: Permission.php:24
‪TYPO3\CMS\Fluid\View\StandaloneView\getRequest
‪TYPO3 CMS Extbase Mvc Request getRequest()
Definition: StandaloneView.php:116
‪TYPO3\CMS\Info\Controller\InfoModuleController\$extObj
‪object $extObj
Definition: InfoModuleController.php:142
‪TYPO3\CMS\Info\Controller\InfoModuleController\$modMenu_type
‪string $modMenu_type
Definition: InfoModuleController.php:112
‪TYPO3\CMS\Info\Controller\InfoModuleController\getLanguageService
‪LanguageService getLanguageService()
Definition: InfoModuleController.php:476
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:38
‪TYPO3\CMS\Info\Controller\InfoModuleController\$moduleTemplate
‪ModuleTemplate $moduleTemplate
Definition: InfoModuleController.php:56
‪TYPO3\CMS\Backend\Utility\BackendUtility\getPagesTSconfig
‪static array getPagesTSconfig($id)
Definition: BackendUtility.php:698
‪TYPO3\CMS\Backend\Utility\BackendUtility\getModuleData
‪static array getModuleData( $MOD_MENU, $CHANGED_SETTINGS, $modName, $type='', $dontValidateList='', $setDefaultList='')
Definition: BackendUtility.php:2893
‪TYPO3\CMS\Extbase\Mvc\Request\setControllerExtensionName
‪setControllerExtensionName($controllerExtensionName)
Definition: Request.php:193
‪TYPO3\CMS\Fluid\View\AbstractTemplateView\setTemplatePathAndFilename
‪setTemplatePathAndFilename($templatePathAndFilename)
Definition: AbstractTemplateView.php:103
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Core\Type\Bitmask\Permission\PAGE_SHOW
‪const PAGE_SHOW
Definition: Permission.php:33
‪TYPO3\CMS\Info\Controller\InfoModuleController\mergeExternalItems
‪array mergeExternalItems($modName, $menuKey, $menuArr)
Definition: InfoModuleController.php:356
‪TYPO3\CMS\Backend\Utility\BackendUtility
Definition: BackendUtility.php:75
‪TYPO3\CMS\Info\Controller\InfoModuleController\getFluidTemplateObject
‪StandaloneView getFluidTemplateObject()
Definition: InfoModuleController.php:315
‪TYPO3\CMS\Backend\Utility\BackendUtility\readPageAccess
‪static array false readPageAccess($id, $perms_clause)
Definition: BackendUtility.php:597
‪TYPO3\CMS\Info\Controller\InfoModuleController\$pageinfo
‪array $pageinfo
Definition: InfoModuleController.php:44
‪TYPO3\CMS\Info\Controller\InfoModuleController\handleExternalFunctionValue
‪handleExternalFunctionValue($MM_key='function', $MS_value=null)
Definition: InfoModuleController.php:379
‪TYPO3\CMS\Backend\Utility\BackendUtility\viewOnClick
‪static string viewOnClick( $pageUid, $backPath='', $rootLine=null, $anchorSection='', $alternativeUrl='', $additionalGetVars='', $switchFocus=true)
Definition: BackendUtility.php:2359
‪TYPO3\CMS\Core\Messaging\FlashMessage
Definition: FlashMessage.php:24
‪TYPO3\CMS\Fluid\View\StandaloneView
Definition: StandaloneView.php:34
‪TYPO3\CMS\Info\Controller\InfoModuleController\$perms_clause
‪string $perms_clause
Definition: InfoModuleController.php:83
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Fluid\View\AbstractTemplateView\setLayoutRootPaths
‪setLayoutRootPaths(array $layoutRootPaths)
Definition: AbstractTemplateView.php:167
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:42
‪TYPO3\CMS\Fluid\View\AbstractTemplateView\setPartialRootPaths
‪setPartialRootPaths(array $partialRootPaths)
Definition: AbstractTemplateView.php:134
‪TYPO3\CMS\Info\Controller\InfoModuleController\$content
‪string $content
Definition: InfoModuleController.php:136
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Info\Controller\InfoModuleController\$modMenu_dontValidateList
‪string $modMenu_dontValidateList
Definition: InfoModuleController.php:119
‪TYPO3\CMS\Info\Controller\InfoModuleController\$extClassConf
‪array $extClassConf
Definition: InfoModuleController.php:130
‪TYPO3\CMS\Info\Controller\InfoModuleController\$flashMessageService
‪FlashMessageService $flashMessageService
Definition: InfoModuleController.php:68
‪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:60
‪TYPO3\CMS\Info\Controller\InfoModuleController\checkExtObj
‪checkExtObj()
Definition: InfoModuleController.php:413
‪TYPO3\CMS\Core\Messaging\FlashMessageService
Definition: FlashMessageService.php:27
‪TYPO3\CMS\Info\Controller\InfoModuleController\menuConfig
‪menuConfig()
Definition: InfoModuleController.php:333
‪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:126
‪TYPO3\CMS\Core\Http\HtmlResponse
Definition: HtmlResponse.php:26
‪TYPO3\CMS\Info\Controller\InfoModuleController\generateMenu
‪generateMenu()
Definition: InfoModuleController.php:283
‪TYPO3\CMS\Fluid\View\AbstractTemplateView\setTemplateRootPaths
‪setTemplateRootPaths(array $templateRootPaths)
Definition: AbstractTemplateView.php:114