[TASK] Use BE Routing / PSR-7 instead of BackendUtility::getModuleUrl
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Controller / PageLayoutController.php
1 <?php
2 namespace TYPO3\CMS\Backend\Controller;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use Psr\Http\Message\ResponseInterface;
18 use Psr\Http\Message\ServerRequestInterface;
19 use TYPO3\CMS\Backend\Module\ModuleLoader;
20 use TYPO3\CMS\Backend\Template\Components\ButtonBar;
21 use TYPO3\CMS\Backend\Template\ModuleTemplate;
22 use TYPO3\CMS\Backend\Utility\BackendUtility;
23 use TYPO3\CMS\Backend\View\BackendLayoutView;
24 use TYPO3\CMS\Backend\View\PageLayoutView;
25 use TYPO3\CMS\Core\Database\ConnectionPool;
26 use TYPO3\CMS\Core\Database\Query\QueryBuilder;
27 use TYPO3\CMS\Core\Database\Query\Restriction\BackendWorkspaceRestriction;
28 use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
29 use TYPO3\CMS\Core\Database\Query\Restriction\HiddenRestriction;
30 use TYPO3\CMS\Core\DataHandling\DataHandler;
31 use TYPO3\CMS\Core\Imaging\Icon;
32 use TYPO3\CMS\Core\Imaging\IconFactory;
33 use TYPO3\CMS\Core\Page\PageRenderer;
34 use TYPO3\CMS\Core\Type\Bitmask\Permission;
35 use TYPO3\CMS\Core\Utility\GeneralUtility;
36 use TYPO3\CMS\Core\Utility\MathUtility;
37 use TYPO3\CMS\Core\Versioning\VersionState;
38 use TYPO3\CMS\Fluid\View\StandaloneView;
39 use TYPO3\CMS\Fluid\ViewHelpers\Be\InfoboxViewHelper;
40 use TYPO3\CMS\Frontend\Page\PageRepository;
41 use TYPO3\CMS\Recordlist\RecordList;
42
43 /**
44 * Script Class for Web > Layout module
45 */
46 class PageLayoutController
47 {
48 /**
49 * Page Id for which to make the listing
50 *
51 * @var int
52 */
53 public $id;
54
55 /**
56 * Pointer - for browsing list of records.
57 *
58 * @var int
59 */
60 public $pointer;
61
62 /**
63 * Thumbnails or not
64 *
65 * @var string
66 */
67 public $imagemode;
68
69 /**
70 * Search-fields
71 *
72 * @var string
73 */
74 public $search_field;
75
76 /**
77 * Search-levels
78 *
79 * @var int
80 */
81 public $search_levels;
82
83 /**
84 * Show-limit
85 *
86 * @var int
87 */
88 public $showLimit;
89
90 /**
91 * Return URL
92 *
93 * @var string
94 */
95 public $returnUrl;
96
97 /**
98 * Clear-cache flag - if set, clears page cache for current id.
99 *
100 * @var bool
101 */
102 public $clear_cache;
103
104 /**
105 * PopView id - for opening a window with the page
106 *
107 * @var bool
108 */
109 public $popView;
110
111 /**
112 * Page select perms clause
113 *
114 * @var string
115 */
116 public $perms_clause;
117
118 /**
119 * Module TSconfig
120 *
121 * @var array
122 */
123 public $modTSconfig;
124
125 /**
126 * Module shared TSconfig
127 *
128 * @var array
129 */
130 public $modSharedTSconfig;
131
132 /**
133 * Current ids page record
134 *
135 * @var array
136 */
137 public $pageinfo;
138
139 /**
140
141 * "Pseudo" Description -table name
142 *
143 * @var string
144 */
145 public $descrTable;
146
147 /**
148 * List of column-integers to edit. Is set from TSconfig, default is "1,0,2,3"
149 *
150 * @var string
151 */
152 public $colPosList;
153
154 /**
155 * Flag: If content can be edited or not.
156 *
157 * @var bool
158 */
159 public $EDIT_CONTENT;
160
161 /**
162 * Users permissions integer for this page.
163 *
164 * @var int
165 */
166 public $CALC_PERMS;
167
168 /**
169 * Currently selected language for editing content elements
170 *
171 * @var int
172 */
173 public $current_sys_language;
174
175 /**
176 * Module configuration
177 *
178 * @var array
179 */
180 public $MCONF = [];
181
182 /**
183 * Menu configuration
184 *
185 * @var array
186 */
187 public $MOD_MENU = [];
188
189 /**
190 * Module settings (session variable)
191 *
192 * @var array
193 */
194 public $MOD_SETTINGS = [];
195
196 /**
197 * Module output accumulation
198 *
199 * @var string
200 */
201 public $content;
202
203 /**
204 * List of column-integers accessible to the current BE user.
205 * Is set from TSconfig, default is $colPosList
206 *
207 * @var string
208 */
209 public $activeColPosList;
210
211 /**
212 * @var string
213 */
214 protected $editSelect;
215
216 /**
217 * Caches the available languages in a colPos
218 *
219 * @var array
220 */
221 protected $languagesInColumnCache = [];
222
223 /**
224 * @var IconFactory
225 */
226 protected $iconFactory;
227
228 /**
229 * The name of the module
230 *
231 * @var string
232 */
233 protected $moduleName = 'web_layout';
234
235 /**
236 * @var ModuleTemplate
237 */
238 protected $moduleTemplate;
239
240 /**
241 * @var ButtonBar
242 */
243 protected $buttonBar;
244
245 /**
246 * @var string
247 */
248 protected $searchContent;
249
250 /**
251 * Initializing the module
252 */
253 public function init()
254 {
255 $this->moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class);
256 $this->iconFactory = $this->moduleTemplate->getIconFactory();
257 $this->buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
258 $this->getLanguageService()->includeLLFile('EXT:backend/Resources/Private/Language/locallang_layout.xlf');
259 // Setting module configuration / page select clause
260 $this->MCONF['name'] = $this->moduleName;
261 $this->perms_clause = $this->getBackendUser()->getPagePermsClause(1);
262 // Get session data
263 $sessionData = $this->getBackendUser()->getSessionData(RecordList::class);
264 $this->search_field = !empty($sessionData['search_field']) ? $sessionData['search_field'] : '';
265 // GPvars:
266 $this->id = (int)GeneralUtility::_GP('id');
267 $this->pointer = GeneralUtility::_GP('pointer');
268 $this->imagemode = GeneralUtility::_GP('imagemode');
269 $this->clear_cache = GeneralUtility::_GP('clear_cache');
270 $this->popView = GeneralUtility::_GP('popView');
271 $this->search_field = GeneralUtility::_GP('search_field');
272 $this->search_levels = GeneralUtility::_GP('search_levels');
273 $this->showLimit = GeneralUtility::_GP('showLimit');
274 $this->returnUrl = GeneralUtility::sanitizeLocalUrl(GeneralUtility::_GP('returnUrl'));
275 $sessionData['search_field'] = $this->search_field;
276 // Store session data
277 $this->getBackendUser()->setAndSaveSessionData(RecordList::class, $sessionData);
278 // Load page info array:
279 $this->pageinfo = BackendUtility::readPageAccess($this->id, $this->perms_clause);
280 // Initialize menu
281 $this->menuConfig();
282 // Setting sys language from session var:
283 $this->current_sys_language = (int)$this->MOD_SETTINGS['language'];
284 // CSH / Descriptions:
285 $this->descrTable = '_MOD_' . $this->moduleName;
286 }
287
288 /**
289 * Initialize menu array
290 */
291 public function menuConfig()
292 {
293 $lang = $this->getLanguageService();
294 // MENU-ITEMS:
295 $this->MOD_MENU = [
296 'tt_content_showHidden' => '',
297 'function' => [
298 1 => $lang->getLL('m_function_1'),
299 2 => $lang->getLL('m_function_2')
300 ],
301 'language' => [
302 0 => $lang->getLL('m_default')
303 ]
304 ];
305 // initialize page/be_user TSconfig settings
306 $this->modSharedTSconfig = BackendUtility::getModTSconfig($this->id, 'mod.SHARED');
307 $this->modTSconfig = BackendUtility::getModTSconfig($this->id, 'mod.' . $this->moduleName);
308
309 // First, select all localized page records on the current page. Each represents a possibility for a language on the page. Add these to language selector.
310 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_language');
311 $queryBuilder->getRestrictions()->removeAll();
312 if ($this->id) {
313 $queryBuilder->select('sys_language.uid AS uid', 'sys_language.title AS title')
314 ->from('sys_language')
315 ->join(
316 'sys_language',
317 'pages',
318 'pages',
319 $queryBuilder->expr()->eq(
320 'sys_language.uid',
321 $queryBuilder->quoteIdentifier('pages.' . $GLOBALS['TCA']['pages']['ctrl']['languageField'])
322 )
323 )
324 ->where(
325 $queryBuilder->expr()->eq(
326 'pages.deleted',
327 $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
328 ),
329 $queryBuilder->expr()->eq(
330 'pages.' . $GLOBALS['TCA']['pages']['ctrl']['transOrigPointerField'],
331 $queryBuilder->createNamedParameter($this->id, \PDO::PARAM_INT)
332 ),
333 $queryBuilder->expr()->orX(
334 $queryBuilder->expr()->gte(
335 'pages.t3ver_state',
336 $queryBuilder->createNamedParameter(
337 (string)new VersionState(VersionState::DEFAULT_STATE),
338 \PDO::PARAM_INT
339 )
340 ),
341 $queryBuilder->expr()->eq(
342 'pages.t3ver_wsid',
343 $queryBuilder->createNamedParameter($this->getBackendUser()->workspace, \PDO::PARAM_INT)
344 )
345 )
346 )
347 ->groupBy(
348 'pages.' . $GLOBALS['TCA']['pages']['ctrl']['languageField'],
349 'sys_language.uid',
350 'sys_language.pid',
351 'sys_language.tstamp',
352 'sys_language.hidden',
353 'sys_language.title',
354 'sys_language.language_isocode',
355 'sys_language.static_lang_isocode',
356 'sys_language.flag',
357 'sys_language.sorting'
358 )
359 ->orderBy('sys_language.sorting');
360 if (!$this->getBackendUser()->isAdmin()) {
361 $queryBuilder->andWhere(
362 $queryBuilder->expr()->eq(
363 'sys_language.hidden',
364 $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
365 )
366 );
367 }
368 $statement = $queryBuilder->execute();
369 } else {
370 $queryBuilder->getRestrictions()->add(GeneralUtility::makeInstance(HiddenRestriction::class));
371 $statement = $queryBuilder->select('uid', 'title')
372 ->from('sys_language')
373 ->orderBy('sorting')
374 ->execute();
375 }
376 while ($lRow = $statement->fetch()) {
377 if ($this->getBackendUser()->checkLanguageAccess($lRow['uid'])) {
378 $this->MOD_MENU['language'][$lRow['uid']] = $lRow['title'];
379 }
380 }
381 // Setting alternative default label:
382 if (($this->modSharedTSconfig['properties']['defaultLanguageLabel'] || $this->modTSconfig['properties']['defaultLanguageLabel']) && isset($this->MOD_MENU['language'][0])) {
383 $this->MOD_MENU['language'][0] = $this->modTSconfig['properties']['defaultLanguageLabel'] ? $this->modTSconfig['properties']['defaultLanguageLabel'] : $this->modSharedTSconfig['properties']['defaultLanguageLabel'];
384 }
385 // Initialize the avaiable actions
386 $actions = $this->initActions();
387 // Clean up settings
388 $this->MOD_SETTINGS = BackendUtility::getModuleData($this->MOD_MENU, GeneralUtility::_GP('SET'), $this->moduleName);
389 // For all elements to be shown in draft workspaces & to also show hidden elements by default if user hasn't disabled the option
390 if ($this->getBackendUser()->workspace != 0 || $this->MOD_SETTINGS['tt_content_showHidden'] !== '0') {
391 $this->MOD_SETTINGS['tt_content_showHidden'] = 1;
392 }
393 // Make action menu from available actions
394 $this->makeActionMenu($actions);
395 }
396
397 /**
398 * Initializes the available actions this module provides
399 *
400 * @return array the available actions
401 */
402 protected function initActions()
403 {
404 $actions = [
405 1 => $this->getLanguageService()->getLL('m_function_1'),
406 2 => $this->getLanguageService()->getLL('m_function_2')
407 ];
408 // Find if there are ANY languages at all (and if not, remove the language option from function menu).
409 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_language');
410 if ($this->getBackendUser()->isAdmin()) {
411 $queryBuilder->getRestrictions()->removeAll();
412 }
413
414 $count = $queryBuilder
415 ->count('uid')
416 ->from('sys_language')
417 ->execute()
418 ->fetchColumn(0);
419
420 if (!$count) {
421 unset($actions['2']);
422 }
423 // page/be_user TSconfig blinding of menu-items
424 $actions = BackendUtility::unsetMenuItems($this->modTSconfig['properties'], $actions, 'menu.function');
425
426 return $actions;
427 }
428
429 /**
430 * This creates the dropdown menu with the different actions this module is able to provide.
431 * For now they are Columns, Quick Edit and Languages.
432 *
433 * @param array $actions array with the available actions
434 */
435 protected function makeActionMenu(array $actions)
436 {
437 $actionMenu = $this->moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->makeMenu();
438 $actionMenu->setIdentifier('actionMenu');
439 $actionMenu->setLabel('');
440
441 /** @var \TYPO3\CMS\Backend\Routing\UriBuilder $uriBuilder */
442 $uriBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Routing\UriBuilder::class);
443
444 $defaultKey = null;
445 $foundDefaultKey = false;
446 foreach ($actions as $key => $action) {
447 $menuItem = $actionMenu
448 ->makeMenuItem()
449 ->setTitle($action)
450 ->setHref((string)$uriBuilder->buildUriFromRoute($this->moduleName) . '&id=' . $this->id . '&SET[function]=' . $key);
451
452 if (!$foundDefaultKey) {
453 $defaultKey = $key;
454 $foundDefaultKey = true;
455 }
456 if ((int)$this->MOD_SETTINGS['function'] === $key) {
457 $menuItem->setActive(true);
458 $defaultKey = null;
459 }
460 $actionMenu->addMenuItem($menuItem);
461 }
462 if (isset($defaultKey)) {
463 $this->MOD_SETTINGS['function'] = $defaultKey;
464 }
465 $this->moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->addMenu($actionMenu);
466 }
467
468 /**
469 * Clears page cache for the current id, $this->id
470 */
471 public function clearCache()
472 {
473 if ($this->clear_cache && !empty($this->pageinfo)) {
474 $dataHandler = GeneralUtility::makeInstance(DataHandler::class);
475 $dataHandler->start([], []);
476 $dataHandler->clear_cacheCmd($this->id);
477 }
478 }
479
480 /**
481 * Generate the flashmessages for current pid
482 *
483 * @return string HTML content with flashmessages
484 */
485 protected function getHeaderFlashMessagesForCurrentPid()
486 {
487 $content = '';
488 $lang = $this->getLanguageService();
489
490 $view = GeneralUtility::makeInstance(StandaloneView::class);
491 $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Templates/InfoBox.html'));
492
493 // If page is a folder
494 if ($this->pageinfo['doktype'] == PageRepository::DOKTYPE_SYSFOLDER) {
495 $moduleLoader = GeneralUtility::makeInstance(ModuleLoader::class);
496 $moduleLoader->load($GLOBALS['TBE_MODULES']);
497 $modules = $moduleLoader->modules;
498 if (is_array($modules['web']['sub']['list'])) {
499 $title = $lang->getLL('goToListModule');
500 $message = '<p>' . $lang->getLL('goToListModuleMessage') . '</p>';
501 $message .= '<a class="btn btn-info" href="javascript:top.goToModule(\'web_list\',1);">' . $lang->getLL('goToListModule') . '</a>';
502 $view->assignMultiple([
503 'title' => $title,
504 'message' => $message,
505 'state' => InfoboxViewHelper::STATE_INFO
506 ]);
507 $content .= $view->render();
508 }
509 } elseif ($this->pageinfo['doktype'] === PageRepository::DOKTYPE_SHORTCUT) {
510 $shortcutMode = (int)$this->pageinfo['shortcut_mode'];
511 $pageRepository = GeneralUtility::makeInstance(PageRepository::class);
512 $targetPage = [];
513
514 if ($this->pageinfo['shortcut'] || $shortcutMode) {
515 switch ($shortcutMode) {
516 case PageRepository::SHORTCUT_MODE_NONE:
517 $targetPage = $pageRepository->getPage($this->pageinfo['shortcut']);
518 break;
519 case PageRepository::SHORTCUT_MODE_FIRST_SUBPAGE:
520 $targetPage = reset($pageRepository->getMenu($this->pageinfo['shortcut'] ?: $this->pageinfo['uid']));
521 break;
522 case PageRepository::SHORTCUT_MODE_PARENT_PAGE:
523 $targetPage = $pageRepository->getPage($this->pageinfo['pid']);
524 break;
525 }
526
527 $message = '';
528 if ($shortcutMode === PageRepository::SHORTCUT_MODE_RANDOM_SUBPAGE) {
529 $message .= sprintf($lang->getLL('pageIsRandomInternalLinkMessage'));
530 } else {
531 $linkToPid = $this->local_linkThisScript(['id' => $targetPage['uid']]);
532 $path = BackendUtility::getRecordPath($targetPage['uid'], $this->getBackendUser()->getPagePermsClause(Permission::PAGE_SHOW), 1000);
533 $linkedPath = '<a href="' . htmlspecialchars($linkToPid) . '">' . htmlspecialchars($path) . '</a>';
534 $message .= sprintf($lang->getLL('pageIsInternalLinkMessage'), $linkedPath);
535 }
536
537 $message .= ' (' . htmlspecialchars($lang->sL(BackendUtility::getLabelFromItemlist('pages', 'shortcut_mode', $shortcutMode))) . ')';
538
539 $view->assignMultiple([
540 'title' => $this->pageinfo['title'],
541 'message' => $message,
542 'state' => InfoboxViewHelper::STATE_INFO
543 ]);
544 $content .= $view->render();
545 } else {
546 if (empty($targetPage) && $shortcutMode !== PageRepository::SHORTCUT_MODE_RANDOM_SUBPAGE) {
547 $view->assignMultiple([
548 'title' => $this->pageinfo['title'],
549 'message' => $lang->getLL('pageIsMisconfiguredInternalLinkMessage'),
550 'state' => InfoboxViewHelper::STATE_ERROR
551 ]);
552 $content .= $view->render();
553 }
554 }
555 } elseif ($this->pageinfo['doktype'] === PageRepository::DOKTYPE_LINK) {
556 if (empty($this->pageinfo['url'])) {
557 $view->assignMultiple([
558 'title' => $this->pageinfo['title'],
559 'message' => $lang->getLL('pageIsMisconfiguredExternalLinkMessage'),
560 'state' => InfoboxViewHelper::STATE_ERROR
561 ]);
562 $content .= $view->render();
563 } else {
564 $externalUrl = htmlspecialchars(GeneralUtility::makeInstance(PageRepository::class)->getExtURL($this->pageinfo));
565 if ($externalUrl !== false) {
566 $externalUrlHtml = '<a href="' . $externalUrl . '" target="_blank" rel="noopener">' . $externalUrl . '</a>';
567 $view->assignMultiple([
568 'title' => $this->pageinfo['title'],
569 'message' => sprintf($lang->getLL('pageIsExternalLinkMessage'), $externalUrlHtml),
570 'state' => InfoboxViewHelper::STATE_INFO
571 ]);
572 $content .= $view->render();
573 }
574 }
575 }
576 // If content from different pid is displayed
577 if ($this->pageinfo['content_from_pid']) {
578 $contentPage = BackendUtility::getRecord('pages', (int)$this->pageinfo['content_from_pid']);
579 $linkToPid = $this->local_linkThisScript(['id' => $this->pageinfo['content_from_pid']]);
580 $title = BackendUtility::getRecordTitle('pages', $contentPage);
581 $link = '<a href="' . htmlspecialchars($linkToPid) . '">' . htmlspecialchars($title) . ' (PID ' . (int)$this->pageinfo['content_from_pid'] . ')</a>';
582 $message = sprintf($lang->getLL('content_from_pid_title'), $link);
583 $view->assignMultiple([
584 'title' => $title,
585 'message' => $message,
586 'state' => InfoboxViewHelper::STATE_INFO
587 ]);
588 $content .= $view->render();
589 } else {
590 $links = $this->getPageLinksWhereContentIsAlsoShownOn($this->pageinfo['uid']);
591 if (!empty($links)) {
592 $message = sprintf($lang->getLL('content_on_pid_title'), $links);
593 $view->assignMultiple([
594 'title' => '',
595 'message' => $message,
596 'state' => InfoboxViewHelper::STATE_INFO
597 ]);
598 $content .= $view->render();
599 }
600 }
601 return $content;
602 }
603
604 /**
605 * Get all pages with links where the content of a page $pageId is also shown on
606 *
607 * @param int $pageId
608 * @return string
609 */
610 protected function getPageLinksWhereContentIsAlsoShownOn($pageId)
611 {
612 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages');
613 $queryBuilder->getRestrictions()->removeAll();
614 $queryBuilder->getRestrictions()->add(GeneralUtility::makeInstance(DeletedRestriction::class));
615 $queryBuilder
616 ->select('*')
617 ->from('pages')
618 ->where($queryBuilder->expr()->eq('content_from_pid', $queryBuilder->createNamedParameter($pageId, \PDO::PARAM_INT)));
619
620 $links = [];
621 $rows = $queryBuilder->execute()->fetchAll();
622 if (!empty($rows)) {
623 foreach ($rows as $row) {
624 $linkToPid = $this->local_linkThisScript(['id' => $row['uid']]);
625 $title = BackendUtility::getRecordTitle('pages', $row);
626 $link = '<a href="' . htmlspecialchars($linkToPid) . '">' . htmlspecialchars($title) . ' (PID ' . (int)$row['uid'] . ')</a>';
627 $links[] = $link;
628 }
629 }
630 return implode(', ', $links);
631 }
632
633 /**
634 * @return string $title
635 */
636 protected function getLocalizedPageTitle()
637 {
638 if ($this->current_sys_language > 0) {
639 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
640 ->getQueryBuilderForTable('pages');
641 $queryBuilder->getRestrictions()
642 ->removeAll()
643 ->add(GeneralUtility::makeInstance(DeletedRestriction::class))
644 ->add(GeneralUtility::makeInstance(BackendWorkspaceRestriction::class));
645 $localizedPage = $queryBuilder
646 ->select('*')
647 ->from('pages')
648 ->where(
649 $queryBuilder->expr()->eq(
650 $GLOBALS['TCA']['pages']['ctrl']['transOrigPointerField'],
651 $queryBuilder->createNamedParameter($this->id, \PDO::PARAM_INT)
652 ),
653 $queryBuilder->expr()->eq(
654 $GLOBALS['TCA']['pages']['ctrl']['languageField'],
655 $queryBuilder->createNamedParameter($this->current_sys_language, \PDO::PARAM_INT)
656 )
657 )
658 ->setMaxResults(1)
659 ->execute()
660 ->fetch();
661 BackendUtility::workspaceOL('pages', $localizedPage);
662 return $localizedPage['title'];
663 }
664 return $this->pageinfo['title'];
665 }
666
667 /**
668 * Injects the request object for the current request or subrequest
669 * As this controller goes only through the main() method, it is rather simple for now
670 *
671 * @param ServerRequestInterface $request the current request
672 * @param ResponseInterface $response
673 * @return ResponseInterface the response with the content
674 */
675 public function mainAction(ServerRequestInterface $request, ResponseInterface $response)
676 {
677 $GLOBALS['SOBE'] = $this;
678 $this->init();
679 $this->clearCache();
680 $this->main();
681 $response->getBody()->write($this->moduleTemplate->renderContent());
682 return $response;
683 }
684
685 /**
686 * Main function.
687 * Creates some general objects and calls other functions for the main rendering of module content.
688 */
689 public function main()
690 {
691 $lang = $this->getLanguageService();
692 // Access check...
693 // The page will show only if there is a valid page and if this page may be viewed by the user
694 $access = is_array($this->pageinfo);
695 // Content
696 $content = '';
697 if ($this->id && $access) {
698 // Initialize permission settings:
699 $this->CALC_PERMS = $this->getBackendUser()->calcPerms($this->pageinfo);
700 $this->EDIT_CONTENT = $this->contentIsNotLockedForEditors();
701
702 $this->moduleTemplate->getDocHeaderComponent()->setMetaInformation($this->pageinfo);
703
704 // override the default jumpToUrl
705 $this->moduleTemplate->addJavaScriptCode('jumpToUrl', '
706 function jumpToUrl(URL,formEl) {
707 if (document.editform && TBE_EDITOR.isFormChanged) { // Check if the function exists... (works in all browsers?)
708 if (!TBE_EDITOR.isFormChanged()) {
709 window.location.href = URL;
710 } else if (formEl) {
711 if (formEl.type=="checkbox") formEl.checked = formEl.checked ? 0 : 1;
712 }
713 } else {
714 window.location.href = URL;
715 }
716 }
717 ');
718
719 /** @var \TYPO3\CMS\Backend\Routing\UriBuilder $uriBuilder */
720 $uriBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Routing\UriBuilder::class);
721
722 $this->moduleTemplate->addJavaScriptCode('mainJsFunctions', '
723 if (top.fsMod) {
724 top.fsMod.recentIds["web"] = ' . (int)$this->id . ';
725 top.fsMod.navFrameHighlightedID["web"] = "pages' . (int)$this->id . '_"+top.fsMod.currentBank; ' . (int)$this->id . ';
726 }
727 ' . ($this->popView ? BackendUtility::viewOnClick($this->id, '', BackendUtility::BEgetRootLine($this->id)) : '') . '
728 function deleteRecord(table,id,url) { //
729 window.location.href = ' . GeneralUtility::quoteJSvalue((string)$uriBuilder->buildUriFromRoute('tce_db') . '&cmd[')
730 . ' + table + "][" + id + "][delete]=1&redirect=" + encodeURIComponent(url);
731 return false;
732 }
733 ');
734
735 // Find backend layout / columns
736 $backendLayout = GeneralUtility::callUserFunction(BackendLayoutView::class . '->getSelectedBackendLayout', $this->id, $this);
737 if (!empty($backendLayout['__colPosList'])) {
738 $this->colPosList = implode(',', $backendLayout['__colPosList']);
739 }
740 // Removing duplicates, if any
741 $this->colPosList = array_unique(GeneralUtility::intExplode(',', $this->colPosList));
742 // Accessible columns
743 if (isset($this->modSharedTSconfig['properties']['colPos_list']) && trim($this->modSharedTSconfig['properties']['colPos_list']) !== '') {
744 $this->activeColPosList = array_unique(GeneralUtility::intExplode(',', trim($this->modSharedTSconfig['properties']['colPos_list'])));
745 // Match with the list which is present in the colPosList for the current page
746 if (!empty($this->colPosList) && !empty($this->activeColPosList)) {
747 $this->activeColPosList = array_unique(array_intersect(
748 $this->activeColPosList,
749 $this->colPosList
750 ));
751 }
752 } else {
753 $this->activeColPosList = $this->colPosList;
754 }
755 $this->activeColPosList = implode(',', $this->activeColPosList);
756 $this->colPosList = implode(',', $this->colPosList);
757
758 $content .= $this->getHeaderFlashMessagesForCurrentPid();
759
760 // Render the primary module content:
761 if ($this->MOD_SETTINGS['function'] == 1 || $this->MOD_SETTINGS['function'] == 2) {
762 $content .= '<form action="' . htmlspecialchars((string)$uriBuilder->buildUriFromRoute($this->moduleName, ['id' => $this->id, 'imagemode' => $this->imagemode])) . '" id="PageLayoutController" method="post">';
763 // Page title
764 $content .= '<h1 class="t3js-title-inlineedit">' . htmlspecialchars($this->getLocalizedPageTitle()) . '</h1>';
765 // All other listings
766 $content .= $this->renderContent();
767 }
768 $content .= '</form>';
769 $content .= $this->searchContent;
770 // Setting up the buttons for the docheader
771 $this->makeButtons();
772 // @internal: This is an internal hook for compatibility7 only, this hook will be removed without further notice
773 if ($this->MOD_SETTINGS['function'] != 1 && $this->MOD_SETTINGS['function'] != 2) {
774 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][self::class]['renderActionHook'] ?? [] as $hook) {
775 $params = [
776 'deleteButton' => $this->deleteButton,
777 ''
778 ];
779 $content .= GeneralUtility::callUserFunction($hook, $params, $this);
780 }
781 }
782 // Create LanguageMenu
783 $this->makeLanguageMenu();
784 } else {
785 $this->moduleTemplate->addJavaScriptCode(
786 'mainJsFunctions',
787 'if (top.fsMod) top.fsMod.recentIds["web"] = ' . (int)$this->id . ';'
788 );
789 $content .= '<h1>' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'] . '</h1>';
790 $view = GeneralUtility::makeInstance(StandaloneView::class);
791 $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Templates/InfoBox.html'));
792 $view->assignMultiple([
793 'title' => $lang->getLL('clickAPage_header'),
794 'message' => $lang->getLL('clickAPage_content'),
795 'state' => InfoboxViewHelper::STATE_INFO
796 ]);
797 $content .= $view->render();
798 }
799 // Set content
800 $this->moduleTemplate->setContent($content);
801 }
802
803 /**
804 * Rendering content
805 *
806 * @return string
807 */
808 public function renderContent()
809 {
810 /** @var \TYPO3\CMS\Backend\Routing\UriBuilder $uriBuilder */
811 $uriBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Routing\UriBuilder::class);
812
813 $this->moduleTemplate->getPageRenderer()->loadJquery();
814 $this->moduleTemplate->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/ContextMenu');
815 /** @var $dbList \TYPO3\CMS\Backend\View\PageLayoutView */
816 $dbList = GeneralUtility::makeInstance(PageLayoutView::class);
817 $dbList->thumbs = $this->imagemode;
818 $dbList->no_noWrap = 1;
819 $dbList->descrTable = $this->descrTable;
820 $this->pointer = MathUtility::forceIntegerInRange($this->pointer, 0, 100000);
821 $dbList->script = (string)$uriBuilder->buildUriFromRoute($this->moduleName);
822 $dbList->showIcon = 0;
823 $dbList->setLMargin = 0;
824 $dbList->doEdit = $this->EDIT_CONTENT;
825 $dbList->ext_CALC_PERMS = $this->CALC_PERMS;
826 $dbList->agePrefixes = $this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.minutesHoursDaysYears');
827 $dbList->id = $this->id;
828 $dbList->nextThree = MathUtility::forceIntegerInRange($this->modTSconfig['properties']['editFieldsAtATime'], 0, 10);
829 $dbList->option_newWizard = empty($this->modTSconfig['properties']['disableNewContentElementWizard']);
830 $dbList->defLangBinding = !empty($this->modTSconfig['properties']['defLangBinding']);
831 if (!$dbList->nextThree) {
832 $dbList->nextThree = 1;
833 }
834 // Create menu for selecting a table to jump to (this is, if more than just pages/tt_content elements are found on the page!)
835 // also fills $dbList->activeTables
836 $dbList->getTableMenu($this->id);
837 // Initialize other variables:
838 $tableOutput = [];
839 $tableJSOutput = [];
840 $CMcounter = 0;
841 // Traverse the list of table names which has records on this page (that array is populated
842 // by the $dblist object during the function getTableMenu()):
843 foreach ($dbList->activeTables as $table => $value) {
844 $h_func = '';
845 $h_func_b = '';
846 if (!isset($dbList->externalTables[$table])) {
847 // Toggle hidden ContentElements
848 $numberOfHiddenElements = $this->getNumberOfHiddenElements();
849 if ($numberOfHiddenElements > 0) {
850 $h_func_b = '
851 <div class="checkbox">
852 <label for="checkTt_content_showHidden">
853 <input type="checkbox" id="checkTt_content_showHidden" class="checkbox" name="SET[tt_content_showHidden]" value="1" ' . ($this->MOD_SETTINGS['tt_content_showHidden'] ? 'checked="checked"' : '') . ' />
854 ' . htmlspecialchars($this->getLanguageService()->getLL('hiddenCE')) . ' (<span class="t3js-hidden-counter">' . $numberOfHiddenElements . '</span>)
855 </label>
856 </div>';
857 }
858
859 // Boolean: Display up/down arrows and edit icons for tt_content records
860 $dbList->tt_contentConfig['showCommands'] = 1;
861 // Boolean: Display info-marks or not
862 $dbList->tt_contentConfig['showInfo'] = 1;
863 // Setting up the tt_content columns to show:
864 if (is_array($GLOBALS['TCA']['tt_content']['columns']['colPos']['config']['items'])) {
865 $colList = [];
866 $tcaItems = GeneralUtility::callUserFunction(BackendLayoutView::class . '->getColPosListItemsParsed', $this->id, $this);
867 foreach ($tcaItems as $temp) {
868 $colList[] = $temp[1];
869 }
870 } else {
871 // ... should be impossible that colPos has no array. But this is the fallback should it make any sense:
872 $colList = ['1', '0', '2', '3'];
873 }
874 if ($this->colPosList !== '') {
875 $colList = array_intersect(GeneralUtility::intExplode(',', $this->colPosList), $colList);
876 }
877 // The order of the rows: Default is left(1), Normal(0), right(2), margin(3)
878 $dbList->tt_contentConfig['cols'] = implode(',', $colList);
879 $dbList->tt_contentConfig['activeCols'] = $this->activeColPosList;
880 $dbList->tt_contentConfig['showHidden'] = $this->MOD_SETTINGS['tt_content_showHidden'];
881 $dbList->tt_contentConfig['sys_language_uid'] = (int)$this->current_sys_language;
882 // If the function menu is set to "Language":
883 if ($this->MOD_SETTINGS['function'] == 2) {
884 $dbList->tt_contentConfig['languageMode'] = 1;
885 $dbList->tt_contentConfig['languageCols'] = $this->MOD_MENU['language'];
886 $dbList->tt_contentConfig['languageColsPointer'] = $this->current_sys_language;
887 }
888 } else {
889 if (isset($this->MOD_SETTINGS) && isset($this->MOD_MENU)) {
890 $h_func = BackendUtility::getFuncMenu($this->id, 'SET[' . $table . ']', $this->MOD_SETTINGS[$table], $this->MOD_MENU[$table], '', '');
891 }
892 }
893 // Start the dblist object:
894 $dbList->itemsLimitSingleTable = 1000;
895 $dbList->start($this->id, $table, $this->pointer, $this->search_field, $this->search_levels, $this->showLimit);
896 $dbList->counter = $CMcounter;
897 $dbList->ext_function = $this->MOD_SETTINGS['function'];
898 // Generate the list of elements here:
899 $dbList->generateList();
900 // Adding the list content to the tableOutput variable:
901 $tableOutput[$table] = $h_func . $dbList->HTMLcode . $h_func_b;
902 // ... and any accumulated JavaScript goes the same way!
903 $tableJSOutput[$table] = $dbList->JScode;
904 // Increase global counter:
905 $CMcounter += $dbList->counter;
906 // Reset variables after operation:
907 $dbList->HTMLcode = '';
908 $dbList->JScode = '';
909 }
910 // END: traverse tables
911 // For Context Sensitive Menus:
912 // Init the content
913 $content = '';
914 // Additional header content
915 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/db_layout.php']['drawHeaderHook'] ?? [] as $hook) {
916 $params = [];
917 $content .= GeneralUtility::callUserFunction($hook, $params, $this);
918 }
919 // Add the content for each table we have rendered (traversing $tableOutput variable)
920 foreach ($tableOutput as $table => $output) {
921 $content .= $output;
922 }
923 // Making search form:
924 if (!$this->modTSconfig['properties']['disableSearchBox'] && ($dbList->counter > 0 || $this->currentPageHasSubPages())) {
925 $this->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/ToggleSearchToolbox');
926 $toggleSearchFormButton = $this->buttonBar->makeLinkButton()
927 ->setClasses('t3js-toggle-search-toolbox')
928 ->setTitle($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.title.searchIcon'))
929 ->setIcon($this->iconFactory->getIcon('actions-search', Icon::SIZE_SMALL))
930 ->setHref('#');
931 $this->buttonBar->addButton($toggleSearchFormButton, ButtonBar::BUTTON_POSITION_LEFT, 4);
932 $this->searchContent = $dbList->getSearchBox();
933 }
934 // Additional footer content
935 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/db_layout.php']['drawFooterHook'] ?? [] as $hook) {
936 $params = [];
937 $content .= GeneralUtility::callUserFunction($hook, $params, $this);
938 }
939 return $content;
940 }
941
942 /**
943 * @return ModuleTemplate
944 */
945 public function getModuleTemplate()
946 {
947 return $this->moduleTemplate;
948 }
949
950 /***************************
951 *
952 * Sub-content functions, rendering specific parts of the module content.
953 *
954 ***************************/
955 /**
956 * This creates the buttons for the modules
957 */
958 protected function makeButtons()
959 {
960 if ($this->MOD_SETTINGS['function'] == 1 || $this->MOD_SETTINGS['function'] == 2) {
961 // Add CSH (Context Sensitive Help) icon to tool bar
962 $contextSensitiveHelpButton = $this->buttonBar->makeHelpButton()
963 ->setModuleName($this->descrTable)
964 ->setFieldName('columns_' . $this->MOD_SETTINGS['function']);
965 $this->buttonBar->addButton($contextSensitiveHelpButton);
966 }
967 $lang = $this->getLanguageService();
968 // View page
969 if (!VersionState::cast($this->pageinfo['t3ver_state'])->equals(VersionState::DELETE_PLACEHOLDER)) {
970 $viewButton = $this->buttonBar->makeLinkButton()
971 ->setOnClick(BackendUtility::viewOnClick($this->pageinfo['uid'], '', BackendUtility::BEgetRootLine($this->pageinfo['uid'])))
972 ->setTitle($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.showPage'))
973 ->setIcon($this->iconFactory->getIcon('actions-view-page', Icon::SIZE_SMALL))
974 ->setHref('#');
975
976 $this->buttonBar->addButton($viewButton, ButtonBar::BUTTON_POSITION_LEFT, 3);
977 }
978 // Shortcut
979 $shortcutButton = $this->buttonBar->makeShortcutButton()
980 ->setModuleName($this->moduleName)
981 ->setGetVariables([
982 'id',
983 'route',
984 'edit_record',
985 'pointer',
986 'new_unique_uid',
987 'search_field',
988 'search_levels',
989 'showLimit'
990 ])
991 ->setSetVariables(array_keys($this->MOD_MENU));
992 $this->buttonBar->addButton($shortcutButton);
993
994 /** @var \TYPO3\CMS\Backend\Routing\UriBuilder $uriBuilder */
995 $uriBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Routing\UriBuilder::class);
996 // Cache
997 if (empty($this->modTSconfig['properties']['disableAdvanced'])) {
998 $clearCacheButton = $this->buttonBar->makeLinkButton()
999 ->setHref((string)$uriBuilder->buildUriFromRoute($this->moduleName, ['id' => $this->pageinfo['uid'], 'clear_cache' => '1']))
1000 ->setTitle($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.clear_cache'))
1001 ->setIcon($this->iconFactory->getIcon('actions-system-cache-clear', Icon::SIZE_SMALL));
1002 $this->buttonBar->addButton($clearCacheButton, ButtonBar::BUTTON_POSITION_RIGHT, 1);
1003 }
1004 if (empty($this->modTSconfig['properties']['disableIconToolbar'])) {
1005 // Edit page properties and page language overlay icons
1006 if ($this->pageIsNotLockedForEditors() && $this->getBackendUser()->checkLanguageAccess(0)) {
1007 // Edit localized pages only when one specific language is selected
1008 if ($this->MOD_SETTINGS['function'] == 1 && $this->current_sys_language > 0) {
1009 $localizationParentField = $GLOBALS['TCA']['pages']['ctrl']['transOrigPointerField'];
1010 $languageField = $GLOBALS['TCA']['pages']['ctrl']['languageField'];
1011 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
1012 ->getQueryBuilderForTable('pages');
1013 $queryBuilder->getRestrictions()
1014 ->removeAll()
1015 ->add(GeneralUtility::makeInstance(DeletedRestriction::class))
1016 ->add(GeneralUtility::makeInstance(BackendWorkspaceRestriction::class));
1017 $overlayRecord = $queryBuilder
1018 ->select('uid')
1019 ->from('pages')
1020 ->where(
1021 $queryBuilder->expr()->eq(
1022 $localizationParentField,
1023 $queryBuilder->createNamedParameter($this->id, \PDO::PARAM_INT)
1024 ),
1025 $queryBuilder->expr()->eq(
1026 $languageField,
1027 $queryBuilder->createNamedParameter($this->current_sys_language, \PDO::PARAM_INT)
1028 )
1029 )
1030 ->setMaxResults(1)
1031 ->execute()
1032 ->fetch();
1033 // Edit button
1034 $urlParameters = [
1035 'edit' => [
1036 'pages' => [
1037 $overlayRecord['uid'] => 'edit'
1038 ]
1039 ],
1040 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
1041 ];
1042
1043 $url = (string)$uriBuilder->buildUriFromRoute('record_edit', $urlParameters);
1044 $editLanguageButton = $this->buttonBar->makeLinkButton()
1045 ->setHref($url)
1046 ->setTitle($lang->getLL('editPageLanguageOverlayProperties'))
1047 ->setIcon($this->iconFactory->getIcon('mimetypes-x-content-page-language-overlay', Icon::SIZE_SMALL));
1048 $this->buttonBar->addButton($editLanguageButton, ButtonBar::BUTTON_POSITION_LEFT, 3);
1049 }
1050 $urlParameters = [
1051 'edit' => [
1052 'pages' => [
1053 $this->id => 'edit'
1054 ]
1055 ],
1056 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
1057 ];
1058 $url = (string)$uriBuilder->buildUriFromRoute('record_edit', $urlParameters);
1059 $editPageButton = $this->buttonBar->makeLinkButton()
1060 ->setHref($url)
1061 ->setTitle($lang->getLL('editPageProperties'))
1062 ->setIcon($this->iconFactory->getIcon('actions-page-open', Icon::SIZE_SMALL));
1063 $this->buttonBar->addButton($editPageButton, ButtonBar::BUTTON_POSITION_LEFT, 3);
1064 }
1065 }
1066 }
1067
1068 /*******************************
1069 *
1070 * Other functions
1071 *
1072 ******************************/
1073 /**
1074 * Returns the number of hidden elements (including those hidden by start/end times)
1075 * on the current page (for the current sys_language)
1076 *
1077 * @return int
1078 */
1079 public function getNumberOfHiddenElements()
1080 {
1081 /** @var QueryBuilder $queryBuilder */
1082 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tt_content');
1083 $queryBuilder->getRestrictions()
1084 ->removeAll()
1085 ->add(GeneralUtility::makeInstance(DeletedRestriction::class))
1086 ->add(GeneralUtility::makeInstance(BackendWorkspaceRestriction::class));
1087
1088 $queryBuilder
1089 ->count('uid')
1090 ->from('tt_content')
1091 ->where(
1092 $queryBuilder->expr()->eq(
1093 'pid',
1094 $queryBuilder->createNamedParameter($this->id, \PDO::PARAM_INT)
1095 ),
1096 $queryBuilder->expr()->eq(
1097 'sys_language_uid',
1098 $queryBuilder->createNamedParameter($this->current_sys_language, \PDO::PARAM_INT)
1099 )
1100 );
1101
1102 if (!empty($GLOBALS['TCA']['tt_content']['ctrl']['enablecolumns']['disabled'])) {
1103 $andWhere[] = $queryBuilder->expr()->neq(
1104 'hidden',
1105 $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
1106 );
1107 }
1108
1109 if (!empty($GLOBALS['TCA']['tt_content']['ctrl']['enablecolumns']['starttime'])) {
1110 $andWhere[] = $queryBuilder->expr()->andX(
1111 $queryBuilder->expr()->neq(
1112 'starttime',
1113 $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
1114 ),
1115 $queryBuilder->expr()->gt(
1116 'starttime',
1117 $queryBuilder->createNamedParameter($GLOBALS['SIM_ACCESS_TIME'], \PDO::PARAM_INT)
1118 )
1119 );
1120 }
1121
1122 if (!empty($GLOBALS['TCA']['tt_content']['ctrl']['enablecolumns']['endtime'])) {
1123 $andWhere[] = $queryBuilder->expr()->andX(
1124 $queryBuilder->expr()->neq(
1125 'endtime',
1126 $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
1127 ),
1128 $queryBuilder->expr()->lte(
1129 'endtime',
1130 $queryBuilder->createNamedParameter($GLOBALS['SIM_ACCESS_TIME'], \PDO::PARAM_INT)
1131 )
1132 );
1133 }
1134
1135 if (!empty($andWhere)) {
1136 $queryBuilder->andWhere(
1137 $queryBuilder->expr()->orX(...$andWhere)
1138 );
1139 }
1140
1141 $count = $queryBuilder
1142 ->execute()
1143 ->fetchColumn(0);
1144
1145 return (int)$count;
1146 }
1147
1148 /**
1149 * Returns URL to the current script.
1150 * In particular the "popView" and "new_unique_uid" Get vars are unset.
1151 *
1152 * @param array $params Parameters array, merged with global GET vars.
1153 * @return string URL
1154 */
1155 public function local_linkThisScript($params)
1156 {
1157 $params['popView'] = '';
1158 $params['new_unique_uid'] = '';
1159 return GeneralUtility::linkThisScript($params);
1160 }
1161
1162 /**
1163 * Check if page can be edited by current user
1164 *
1165 * @return bool
1166 */
1167 public function pageIsNotLockedForEditors()
1168 {
1169 return $this->getBackendUser()->isAdmin() || ($this->CALC_PERMS & Permission::PAGE_EDIT) === Permission::PAGE_EDIT && !$this->pageinfo['editlock'];
1170 }
1171
1172 /**
1173 * Check if content can be edited by current user
1174 *
1175 * @return bool
1176 */
1177 public function contentIsNotLockedForEditors()
1178 {
1179 return $this->getBackendUser()->isAdmin() || ($this->CALC_PERMS & Permission::CONTENT_EDIT) === Permission::CONTENT_EDIT && !$this->pageinfo['editlock'];
1180 }
1181
1182 /**
1183 * Returns LanguageService
1184 *
1185 * @return \TYPO3\CMS\Core\Localization\LanguageService
1186 */
1187 protected function getLanguageService()
1188 {
1189 return $GLOBALS['LANG'];
1190 }
1191
1192 /**
1193 * Returns the current BE user.
1194 *
1195 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
1196 */
1197 protected function getBackendUser()
1198 {
1199 return $GLOBALS['BE_USER'];
1200 }
1201
1202 /**
1203 * Returns current PageRenderer
1204 *
1205 * @return PageRenderer
1206 */
1207 protected function getPageRenderer()
1208 {
1209 return GeneralUtility::makeInstance(PageRenderer::class);
1210 }
1211
1212 /**
1213 * Make the LanguageMenu
1214 */
1215 protected function makeLanguageMenu()
1216 {
1217 if (count($this->MOD_MENU['language']) > 1) {
1218 /** @var \TYPO3\CMS\Backend\Routing\UriBuilder $uriBuilder */
1219 $uriBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Routing\UriBuilder::class);
1220 $lang = $this->getLanguageService();
1221 $languageMenu = $this->moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->makeMenu();
1222 $languageMenu->setIdentifier('languageMenu');
1223 foreach ($this->MOD_MENU['language'] as $key => $language) {
1224 $menuItem = $languageMenu
1225 ->makeMenuItem()
1226 ->setTitle($language)
1227 ->setHref((string)$uriBuilder->buildUriFromRoute($this->moduleName) . '&id=' . $this->id . '&SET[language]=' . $key);
1228 if ((int)$this->current_sys_language === $key) {
1229 $menuItem->setActive(true);
1230 }
1231 $languageMenu->addMenuItem($menuItem);
1232 }
1233 $this->moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->addMenu($languageMenu);
1234 }
1235 }
1236
1237 /**
1238 * Checks whether the current page has sub pages
1239 *
1240 * @return bool
1241 */
1242 protected function currentPageHasSubPages()
1243 {
1244 /** @var QueryBuilder $queryBuilder */
1245 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages');
1246 $queryBuilder->getRestrictions()
1247 ->removeAll()
1248 ->add(GeneralUtility::makeInstance(DeletedRestriction::class))
1249 ->add(GeneralUtility::makeInstance(BackendWorkspaceRestriction::class));
1250
1251 // get workspace id
1252 $workspaceId = (int)$this->getBackendUser()->workspace;
1253 $comparisonExpression = $workspaceId === 0 ? 'neq' : 'eq';
1254
1255 $count = $queryBuilder
1256 ->count('uid')
1257 ->from('pages')
1258 ->where(
1259 $queryBuilder->expr()->eq('pid', $queryBuilder->createNamedParameter($this->id, \PDO::PARAM_INT)),
1260 $queryBuilder->expr()->eq(
1261 't3ver_wsid',
1262 $queryBuilder->createNamedParameter($workspaceId, \PDO::PARAM_INT)
1263 ),
1264 $queryBuilder->expr()->{$comparisonExpression}(
1265 'pid',
1266 $queryBuilder->createNamedParameter(-1, \PDO::PARAM_INT)
1267 )
1268 )
1269 ->execute()
1270 ->fetchColumn(0);
1271
1272 return (bool)$count;
1273 }
1274 }