‪TYPO3CMS  ‪main
PageTsConfigRecordsOverviewController.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;
28 use TYPO3\CMS\Backend\Utility\BackendUtility;
35 use TYPO3\CMS\Core\Imaging\IconSize;
40 
46 #[AsController]
48 {
49  public function ‪__construct(
50  private readonly ‪IconFactory $iconFactory,
51  private readonly ‪UriBuilder $uriBuilder,
52  private readonly ‪ModuleTemplateFactory $moduleTemplateFactory,
53  ) {}
54 
55  public function ‪handleRequest(ServerRequestInterface $request): ResponseInterface
56  {
57  $backendUser = $this->‪getBackendUser();
58  $currentModule = $request->getAttribute('module');
59  $currentModuleIdentifier = $currentModule->getIdentifier();
60  $pageId = (int)($request->getQueryParams()['id'] ?? 0);
61  $pageRecord = BackendUtility::readPageAccess($pageId, $backendUser->getPagePermsClause(‪Permission::PAGE_SHOW)) ?: [];
62 
63  $moduleData = $request->getAttribute('moduleData');
64  if ($moduleData->cleanUp([])) {
65  $backendUser->pushModuleData($currentModuleIdentifier, $moduleData->toArray());
66  }
67 
68  $view = $this->moduleTemplateFactory->create($request);
69 
70  $view->setTitle(
71  $this->‪getLanguageService()->sL($currentModule->getTitle()),
72  $pageId !== 0 && isset($pageRecord['title']) ? $pageRecord['title'] : ''
73  );
74 
75  // The page will show only if there is a valid page and if this page may be viewed by the user.
76  if ($pageRecord !== []) {
77  $view->getDocHeaderComponent()->setMetaInformation($pageRecord);
78  }
79 
80  $accessContent = false;
81  if (($pageId && $pageRecord !== []) || ($backendUser->isAdmin() && !$pageId)) {
82  $accessContent = true;
83  if (!$pageId && $backendUser->isAdmin()) {
84  $pageRecord = ['title' => '[root-level]', 'uid' => 0, 'pid' => 0];
85  }
86  $view->assign('id', $pageId);
87  // Setting up the buttons and the module menu for the doc header
88  $this->‪getButtons($view, $currentModule, $pageId, $pageRecord);
89  }
90  $view->assign('accessContent', $accessContent);
91  $pagesUsingTSConfig = $this->‪getOverviewOfPagesUsingTSConfig($currentModule);
92  if (count($pagesUsingTSConfig) > 0) {
93  $view->assign('overviewOfPagesUsingTSConfig', $pagesUsingTSConfig);
94  }
95 
96  $view->makeDocHeaderModuleMenu(['id' => $pageId]);
97  return $view->renderResponse('PageTsConfig/RecordsOverview');
98  }
99 
103  private function ‪getOverviewOfPagesUsingTSConfig(‪ModuleInterface $currentModule): array
104  {
105  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages');
106  $queryBuilder->getRestrictions()
107  ->removeAll()
108  ->add(GeneralUtility::makeInstance(DeletedRestriction::class))
109  ->add(GeneralUtility::makeInstance(WorkspaceRestriction::class, 0));
110 
111  $res = $queryBuilder
112  ->select('uid', 'TSconfig')
113  ->from('pages')
114  ->where(
115  $queryBuilder->expr()->neq(
116  'TSconfig',
117  $queryBuilder->createNamedParameter('')
118  ),
119  $queryBuilder->expr()->eq(
120  'sys_language_uid',
121  $queryBuilder->createNamedParameter(0, ‪Connection::PARAM_INT)
122  )
123  )
124  ->executeQuery();
125 
126  $pageArray = [];
127 
128  while ($row = $res->fetchAssociative()) {
129  $this->‪setInPageArray($pageArray, BackendUtility::BEgetRootLine($row['uid'], 'AND 1=1'), $row);
130  }
131  return $this->‪getList($currentModule, $pageArray);
132  }
133 
137  private function ‪setInPageArray(array &$hierarchicArray, array $rootlineArray, array $row): void
138  {
139  ksort($rootlineArray);
140  if (!($rootlineArray[0]['uid'] ?? false)) {
141  array_shift($rootlineArray);
142  }
143  $currentElement = current($rootlineArray);
144  $hierarchicArray[$currentElement['uid']] = htmlspecialchars($currentElement['title']);
145  array_shift($rootlineArray);
146  if (!empty($rootlineArray)) {
147  if (!is_array($hierarchicArray[$currentElement['uid'] . '.'] ?? null)) {
148  $hierarchicArray[$currentElement['uid'] . '.'] = [];
149  }
150  $this->‪setInPageArray($hierarchicArray[$currentElement['uid'] . '.'], $rootlineArray, $row);
151  } else {
152  $hierarchicArray[$currentElement['uid'] . '_'] = $this->‪extractLinesFromTSConfig($row);
153  }
154  }
155 
159  private function ‪extractLinesFromTSConfig(array $row): array
160  {
161  $out = [];
162  $out['uid'] = $row['uid'];
163  $lines = ‪GeneralUtility::trimExplode("\r\n", $row['TSconfig']);
164  $out['writtenLines'] = count($lines);
165  return $out;
166  }
167 
171  private function ‪getList(‪ModuleInterface $currentModule, array $pageArray, array $lines = [], int $pageDepth = 0): array
172  {
173  if ($pageArray === []) {
174  return $lines;
175  }
176 
177  foreach ($pageArray as ‪$identifier => $title) {
179  continue;
180  }
181  $line = [];
182  $line['padding'] = ($pageDepth * 20);
183  $line['title'] = ‪$identifier;
184  if (isset($pageArray[‪$identifier . '_'])) {
185  $line['link'] = $this->uriBuilder->buildUriFromRoute($currentModule->‪getIdentifier(), ['id' => ‪$identifier]);
186  $line['icon'] = $this->iconFactory->getIconForRecord('pages', BackendUtility::getRecordWSOL('pages', ‪$identifier), IconSize::SMALL)->render();
187  $line['pageTitle'] = ‪GeneralUtility::fixed_lgd_cs($title, 30);
188  $line['lines'] = ($pageArray[‪$identifier . '_']['writtenLines'] === 0 ? '' : $pageArray[‪$identifier . '_']['writtenLines']);
189  } else {
190  $line['link'] = '';
191  $line['icon'] = $this->iconFactory->getIconForRecord('pages', BackendUtility::getRecordWSOL('pages', ‪$identifier), IconSize::SMALL)->render();
192  $line['pageTitle'] = ‪GeneralUtility::fixed_lgd_cs($title, 30);
193  $line['lines'] = '';
194  }
195  $lines[] = $line;
196  $lines = $this->‪getList($currentModule, $pageArray[‪$identifier . '.'] ?? [], $lines, $pageDepth + 1);
197  }
198  return $lines;
199  }
200 
201  private function ‪getButtons(‪ModuleTemplate $view, ‪ModuleInterface $currentModule, ?int $pageId, ?array $pageRecord): void
202  {
203  $buttonBar = $view->‪getDocHeaderComponent()->getButtonBar();
204  $shortcutButton = $buttonBar->makeShortcutButton()
205  ->setRouteIdentifier($currentModule->‪getIdentifier())
206  ->setDisplayName($currentModule->‪getTitle())
207  ->setArguments(['id' => $pageId]);
208  $buttonBar->addButton($shortcutButton, ‪ButtonBar::BUTTON_POSITION_RIGHT);
209  }
210 
212  {
213  return ‪$GLOBALS['LANG'];
214  }
215 
217  {
218  return ‪$GLOBALS['BE_USER'];
219  }
220 }
‪TYPO3\CMS\Backend\Controller\PageTsConfig\PageTsConfigRecordsOverviewController\__construct
‪__construct(private readonly IconFactory $iconFactory, private readonly UriBuilder $uriBuilder, private readonly ModuleTemplateFactory $moduleTemplateFactory,)
Definition: PageTsConfigRecordsOverviewController.php:49
‪TYPO3\CMS\Core\Database\Connection\PARAM_INT
‪const PARAM_INT
Definition: Connection.php:52
‪TYPO3\CMS\Backend\Template\Components\ButtonBar
Definition: ButtonBar.php:33
‪TYPO3\CMS\Core\Utility\GeneralUtility\fixed_lgd_cs
‪static string fixed_lgd_cs(string $string, int $chars, string $appendString='...')
Definition: GeneralUtility.php:92
‪TYPO3\CMS\Backend\Controller\PageTsConfig
Definition: PageTsConfigActiveController.php:18
‪TYPO3\CMS\Backend\Template\ModuleTemplateFactory
Definition: ModuleTemplateFactory.php:33
‪TYPO3\CMS\Backend\Controller\PageTsConfig\PageTsConfigRecordsOverviewController\getOverviewOfPagesUsingTSConfig
‪getOverviewOfPagesUsingTSConfig(ModuleInterface $currentModule)
Definition: PageTsConfigRecordsOverviewController.php:103
‪TYPO3\CMS\Backend\Controller\PageTsConfig\PageTsConfigRecordsOverviewController\handleRequest
‪handleRequest(ServerRequestInterface $request)
Definition: PageTsConfigRecordsOverviewController.php:55
‪TYPO3\CMS\Backend\Controller\PageTsConfig\PageTsConfigRecordsOverviewController
Definition: PageTsConfigRecordsOverviewController.php:48
‪TYPO3\CMS\Core\Imaging\IconFactory
Definition: IconFactory.php:34
‪TYPO3\CMS\Backend\Template\ModuleTemplate
Definition: ModuleTemplate.php:46
‪TYPO3\CMS\Core\Type\Bitmask\Permission
Definition: Permission.php:26
‪TYPO3\CMS\Backend\Module\ModuleInterface\getTitle
‪getTitle()
‪TYPO3\CMS\Backend\Controller\PageTsConfig\PageTsConfigRecordsOverviewController\getLanguageService
‪getLanguageService()
Definition: PageTsConfigRecordsOverviewController.php:211
‪TYPO3\CMS\Core\Utility\MathUtility\canBeInterpretedAsInteger
‪static bool canBeInterpretedAsInteger(mixed $var)
Definition: MathUtility.php:69
‪TYPO3\CMS\Backend\Module\ModuleInterface\getIdentifier
‪getIdentifier()
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:44
‪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\Backend\Controller\PageTsConfig\PageTsConfigRecordsOverviewController\getList
‪getList(ModuleInterface $currentModule, array $pageArray, array $lines=[], int $pageDepth=0)
Definition: PageTsConfigRecordsOverviewController.php:171
‪TYPO3\CMS\Backend\Controller\PageTsConfig\PageTsConfigRecordsOverviewController\getButtons
‪getButtons(ModuleTemplate $view, ModuleInterface $currentModule, ?int $pageId, ?array $pageRecord)
Definition: PageTsConfigRecordsOverviewController.php:201
‪TYPO3\CMS\Core\Database\Connection
Definition: Connection.php:41
‪TYPO3\CMS\Backend\Template\ModuleTemplate\getDocHeaderComponent
‪getDocHeaderComponent()
Definition: ModuleTemplate.php:181
‪TYPO3\CMS\Backend\Controller\PageTsConfig\PageTsConfigRecordsOverviewController\extractLinesFromTSConfig
‪extractLinesFromTSConfig(array $row)
Definition: PageTsConfigRecordsOverviewController.php:159
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction
Definition: DeletedRestriction.php:28
‪TYPO3\CMS\Core\Utility\MathUtility
Definition: MathUtility.php:24
‪TYPO3\CMS\Backend\Attribute\AsController
Definition: AsController.php:25
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:46
‪TYPO3\CMS\Backend\Controller\PageTsConfig\PageTsConfigRecordsOverviewController\setInPageArray
‪setInPageArray(array &$hierarchicArray, array $rootlineArray, array $row)
Definition: PageTsConfigRecordsOverviewController.php:137
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:46
‪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\trimExplode
‪static list< string > trimExplode(string $delim, string $string, bool $removeEmptyValues=false, int $limit=0)
Definition: GeneralUtility.php:822
‪TYPO3\CMS\Webhooks\Message\$identifier
‪identifier readonly string $identifier
Definition: FileAddedMessage.php:37
‪TYPO3\CMS\Backend\Controller\PageTsConfig\PageTsConfigRecordsOverviewController\getBackendUser
‪getBackendUser()
Definition: PageTsConfigRecordsOverviewController.php:216
‪TYPO3\CMS\Core\Database\Query\Restriction\WorkspaceRestriction
Definition: WorkspaceRestriction.php:39