4e0599812c3fc4382f63c319142bffd1f60909ce
[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 pages_language_overlay 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_language_overlay',
318 'pages_language_overlay',
319 $queryBuilder->expr()->eq(
320 'sys_language.uid',
321 $queryBuilder->quoteIdentifier('pages_language_overlay.sys_language_uid')
322 )
323 )
324 ->where(
325 $queryBuilder->expr()->eq(
326 'pages_language_overlay.deleted',
327 $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
328 ),
329 $queryBuilder->expr()->eq(
330 'pages_language_overlay.pid',
331 $queryBuilder->createNamedParameter($this->id, \PDO::PARAM_INT)
332 ),
333 $queryBuilder->expr()->orX(
334 $queryBuilder->expr()->gte(
335 'pages_language_overlay.t3ver_state',
336 $queryBuilder->createNamedParameter(
337 (string)new VersionState(VersionState::DEFAULT_STATE),
338 \PDO::PARAM_INT
339 )
340 ),
341 $queryBuilder->expr()->eq(
342 'pages_language_overlay.t3ver_wsid',
343 $queryBuilder->createNamedParameter($this->getBackendUser()->workspace, \PDO::PARAM_INT)
344 )
345 )
346 )
347 ->groupBy(
348 'pages_language_overlay.sys_language_uid',
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 $defaultKey = null;
442 $foundDefaultKey = false;
443 foreach ($actions as $key => $action) {
444 $menuItem = $actionMenu
445 ->makeMenuItem()
446 ->setTitle($action)
447 ->setHref(BackendUtility::getModuleUrl($this->moduleName) . '&id=' . $this->id . '&SET[function]=' . $key);
448
449 if (!$foundDefaultKey) {
450 $defaultKey = $key;
451 $foundDefaultKey = true;
452 }
453 if ((int)$this->MOD_SETTINGS['function'] === $key) {
454 $menuItem->setActive(true);
455 $defaultKey = null;
456 }
457 $actionMenu->addMenuItem($menuItem);
458 }
459 if (isset($defaultKey)) {
460 $this->MOD_SETTINGS['function'] = $defaultKey;
461 }
462 $this->moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->addMenu($actionMenu);
463 }
464
465 /**
466 * Clears page cache for the current id, $this->id
467 */
468 public function clearCache()
469 {
470 if ($this->clear_cache && !empty($this->pageinfo)) {
471 $dataHandler = GeneralUtility::makeInstance(DataHandler::class);
472 $dataHandler->start([], []);
473 $dataHandler->clear_cacheCmd($this->id);
474 }
475 }
476
477 /**
478 * Generate the flashmessages for current pid
479 *
480 * @return string HTML content with flashmessages
481 */
482 protected function getHeaderFlashMessagesForCurrentPid()
483 {
484 $content = '';
485 $lang = $this->getLanguageService();
486
487 $view = GeneralUtility::makeInstance(StandaloneView::class);
488 $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Templates/InfoBox.html'));
489
490 // If page is a folder
491 if ($this->pageinfo['doktype'] == PageRepository::DOKTYPE_SYSFOLDER) {
492 $moduleLoader = GeneralUtility::makeInstance(ModuleLoader::class);
493 $moduleLoader->load($GLOBALS['TBE_MODULES']);
494 $modules = $moduleLoader->modules;
495 if (is_array($modules['web']['sub']['list'])) {
496 $title = $lang->getLL('goToListModule');
497 $message = '<p>' . $lang->getLL('goToListModuleMessage') . '</p>';
498 $message .= '<a class="btn btn-info" href="javascript:top.goToModule(\'web_list\',1);">' . $lang->getLL('goToListModule') . '</a>';
499 $view->assignMultiple([
500 'title' => $title,
501 'message' => $message,
502 'state' => InfoboxViewHelper::STATE_INFO
503 ]);
504 $content .= $view->render();
505 }
506 } elseif ($this->pageinfo['doktype'] === PageRepository::DOKTYPE_SHORTCUT) {
507 $shortcutMode = (int)$this->pageinfo['shortcut_mode'];
508 $pageRepository = GeneralUtility::makeInstance(PageRepository::class);
509 $targetPage = [];
510
511 if ($this->pageinfo['shortcut'] || $shortcutMode) {
512 switch ($shortcutMode) {
513 case PageRepository::SHORTCUT_MODE_NONE:
514 $targetPage = $pageRepository->getPage($this->pageinfo['shortcut']);
515 break;
516 case PageRepository::SHORTCUT_MODE_FIRST_SUBPAGE:
517 $targetPage = reset($pageRepository->getMenu($this->pageinfo['shortcut'] ?: $this->pageinfo['uid']));
518 break;
519 case PageRepository::SHORTCUT_MODE_PARENT_PAGE:
520 $targetPage = $pageRepository->getPage($this->pageinfo['pid']);
521 break;
522 }
523
524 $message = '';
525 if ($shortcutMode === PageRepository::SHORTCUT_MODE_RANDOM_SUBPAGE) {
526 $message .= sprintf($lang->getLL('pageIsRandomInternalLinkMessage'));
527 } else {
528 $linkToPid = $this->local_linkThisScript(['id' => $targetPage['uid']]);
529 $path = BackendUtility::getRecordPath($targetPage['uid'], $this->getBackendUser()->getPagePermsClause(Permission::PAGE_SHOW), 1000);
530 $linkedPath = '<a href="' . htmlspecialchars($linkToPid) . '">' . htmlspecialchars($path) . '</a>';
531 $message .= sprintf($lang->getLL('pageIsInternalLinkMessage'), $linkedPath);
532 }
533
534 $message .= ' (' . htmlspecialchars($lang->sL(BackendUtility::getLabelFromItemlist('pages', 'shortcut_mode', $shortcutMode))) . ')';
535
536 $view->assignMultiple([
537 'title' => $this->pageinfo['title'],
538 'message' => $message,
539 'state' => InfoboxViewHelper::STATE_INFO
540 ]);
541 $content .= $view->render();
542 } else {
543 if (empty($targetPage) && $shortcutMode !== PageRepository::SHORTCUT_MODE_RANDOM_SUBPAGE) {
544 $view->assignMultiple([
545 'title' => $this->pageinfo['title'],
546 'message' => $lang->getLL('pageIsMisconfiguredInternalLinkMessage'),
547 'state' => InfoboxViewHelper::STATE_ERROR
548 ]);
549 $content .= $view->render();
550 }
551 }
552 } elseif ($this->pageinfo['doktype'] === PageRepository::DOKTYPE_LINK) {
553 if (empty($this->pageinfo['url'])) {
554 $view->assignMultiple([
555 'title' => $this->pageinfo['title'],
556 'message' => $lang->getLL('pageIsMisconfiguredExternalLinkMessage'),
557 'state' => InfoboxViewHelper::STATE_ERROR
558 ]);
559 $content .= $view->render();
560 } else {
561 $externalUrl = htmlspecialchars(GeneralUtility::makeInstance(PageRepository::class)->getExtURL($this->pageinfo));
562 if ($externalUrl !== false) {
563 $externalUrlHtml = '<a href="' . $externalUrl . '" target="_blank" rel="noopener">' . $externalUrl . '</a>';
564 $view->assignMultiple([
565 'title' => $this->pageinfo['title'],
566 'message' => sprintf($lang->getLL('pageIsExternalLinkMessage'), $externalUrlHtml),
567 'state' => InfoboxViewHelper::STATE_INFO
568 ]);
569 $content .= $view->render();
570 }
571 }
572 }
573 // If content from different pid is displayed
574 if ($this->pageinfo['content_from_pid']) {
575 $contentPage = BackendUtility::getRecord('pages', (int)$this->pageinfo['content_from_pid']);
576 $linkToPid = $this->local_linkThisScript(['id' => $this->pageinfo['content_from_pid']]);
577 $title = BackendUtility::getRecordTitle('pages', $contentPage);
578 $link = '<a href="' . htmlspecialchars($linkToPid) . '">' . htmlspecialchars($title) . ' (PID ' . (int)$this->pageinfo['content_from_pid'] . ')</a>';
579 $message = sprintf($lang->getLL('content_from_pid_title'), $link);
580 $view->assignMultiple([
581 'title' => $title,
582 'message' => $message,
583 'state' => InfoboxViewHelper::STATE_INFO
584 ]);
585 $content .= $view->render();
586 } else {
587 $links = $this->getPageLinksWhereContentIsAlsoShownOn($this->pageinfo['uid']);
588 if (!empty($links)) {
589 $message = sprintf($lang->getLL('content_on_pid_title'), $links);
590 $view->assignMultiple([
591 'title' => '',
592 'message' => $message,
593 'state' => InfoboxViewHelper::STATE_INFO
594 ]);
595 $content .= $view->render();
596 }
597 }
598 return $content;
599 }
600
601 /**
602 * Get all pages with links where the content of a page $pageId is also shown on
603 *
604 * @param int $pageId
605 * @return string
606 */
607 protected function getPageLinksWhereContentIsAlsoShownOn($pageId)
608 {
609 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages');
610 $queryBuilder->getRestrictions()->removeAll();
611 $queryBuilder->getRestrictions()->add(GeneralUtility::makeInstance(DeletedRestriction::class));
612 $queryBuilder
613 ->select('*')
614 ->from('pages')
615 ->where($queryBuilder->expr()->eq('content_from_pid', $queryBuilder->createNamedParameter($pageId, \PDO::PARAM_INT)));
616
617 $links = [];
618 $rows = $queryBuilder->execute()->fetchAll();
619 if (!empty($rows)) {
620 foreach ($rows as $row) {
621 $linkToPid = $this->local_linkThisScript(['id' => $row['uid']]);
622 $title = BackendUtility::getRecordTitle('pages', $row);
623 $link = '<a href="' . htmlspecialchars($linkToPid) . '">' . htmlspecialchars($title) . ' (PID ' . (int)$row['uid'] . ')</a>';
624 $links[] = $link;
625 }
626 }
627 return implode(', ', $links);
628 }
629
630 /**
631 * @return string $title
632 */
633 protected function getLocalizedPageTitle()
634 {
635 if ($this->current_sys_language > 0) {
636 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
637 ->getQueryBuilderForTable('pages_language_overlay');
638 $queryBuilder->getRestrictions()
639 ->removeAll()
640 ->add(GeneralUtility::makeInstance(DeletedRestriction::class))
641 ->add(GeneralUtility::makeInstance(BackendWorkspaceRestriction::class));
642 $overlayRecord = $queryBuilder
643 ->select('title')
644 ->from('pages_language_overlay')
645 ->where(
646 $queryBuilder->expr()->eq('pid', $queryBuilder->createNamedParameter($this->id, \PDO::PARAM_INT)),
647 $queryBuilder->expr()->eq(
648 'sys_language_uid',
649 $queryBuilder->createNamedParameter($this->current_sys_language, \PDO::PARAM_INT)
650 )
651 )
652 ->setMaxResults(1)
653 ->execute()
654 ->fetch();
655 return $overlayRecord['title'];
656 } else {
657 return $this->pageinfo['title'];
658 }
659 }
660
661 /**
662 * Injects the request object for the current request or subrequest
663 * As this controller goes only through the main() method, it is rather simple for now
664 *
665 * @param ServerRequestInterface $request the current request
666 * @param ResponseInterface $response
667 * @return ResponseInterface the response with the content
668 */
669 public function mainAction(ServerRequestInterface $request, ResponseInterface $response)
670 {
671 $GLOBALS['SOBE'] = $this;
672 $this->init();
673 $this->clearCache();
674 $this->main();
675 $response->getBody()->write($this->moduleTemplate->renderContent());
676 return $response;
677 }
678
679 /**
680 * Main function.
681 * Creates some general objects and calls other functions for the main rendering of module content.
682 */
683 public function main()
684 {
685 $lang = $this->getLanguageService();
686 // Access check...
687 // The page will show only if there is a valid page and if this page may be viewed by the user
688 $access = is_array($this->pageinfo) ? 1 : 0;
689 // Content
690 $content = '';
691 if ($this->id && $access) {
692 // Initialize permission settings:
693 $this->CALC_PERMS = $this->getBackendUser()->calcPerms($this->pageinfo);
694 $this->EDIT_CONTENT = $this->contentIsNotLockedForEditors();
695
696 $this->moduleTemplate->getDocHeaderComponent()->setMetaInformation($this->pageinfo);
697
698 // override the default jumpToUrl
699 $this->moduleTemplate->addJavaScriptCode('jumpToUrl', '
700 function jumpToUrl(URL,formEl) {
701 if (document.editform && TBE_EDITOR.isFormChanged) { // Check if the function exists... (works in all browsers?)
702 if (!TBE_EDITOR.isFormChanged()) {
703 window.location.href = URL;
704 } else if (formEl) {
705 if (formEl.type=="checkbox") formEl.checked = formEl.checked ? 0 : 1;
706 }
707 } else {
708 window.location.href = URL;
709 }
710 }
711 ');
712 $this->moduleTemplate->addJavaScriptCode('mainJsFunctions', '
713 if (top.fsMod) {
714 top.fsMod.recentIds["web"] = ' . (int)$this->id . ';
715 top.fsMod.navFrameHighlightedID["web"] = "pages' . (int)$this->id . '_"+top.fsMod.currentBank; ' . (int)$this->id . ';
716 }
717 ' . ($this->popView ? BackendUtility::viewOnClick($this->id, '', BackendUtility::BEgetRootLine($this->id)) : '') . '
718 function deleteRecord(table,id,url) { //
719 window.location.href = ' . GeneralUtility::quoteJSvalue(BackendUtility::getModuleUrl('tce_db') . '&cmd[')
720 . ' + table + "][" + id + "][delete]=1&redirect=" + encodeURIComponent(url) + "&prErr=1&uPT=1";
721 return false;
722 }
723 ');
724
725 // Find backend layout / columns
726 $backendLayout = GeneralUtility::callUserFunction(BackendLayoutView::class . '->getSelectedBackendLayout', $this->id, $this);
727 if (!empty($backendLayout['__colPosList'])) {
728 $this->colPosList = implode(',', $backendLayout['__colPosList']);
729 }
730 // Removing duplicates, if any
731 $this->colPosList = array_unique(GeneralUtility::intExplode(',', $this->colPosList));
732 // Accessible columns
733 if (isset($this->modSharedTSconfig['properties']['colPos_list']) && trim($this->modSharedTSconfig['properties']['colPos_list']) !== '') {
734 $this->activeColPosList = array_unique(GeneralUtility::intExplode(',', trim($this->modSharedTSconfig['properties']['colPos_list'])));
735 // Match with the list which is present in the colPosList for the current page
736 if (!empty($this->colPosList) && !empty($this->activeColPosList)) {
737 $this->activeColPosList = array_unique(array_intersect(
738 $this->activeColPosList,
739 $this->colPosList
740 ));
741 }
742 } else {
743 $this->activeColPosList = $this->colPosList;
744 }
745 $this->activeColPosList = implode(',', $this->activeColPosList);
746 $this->colPosList = implode(',', $this->colPosList);
747
748 $content .= $this->getHeaderFlashMessagesForCurrentPid();
749
750 // Render the primary module content:
751 if ($this->MOD_SETTINGS['function'] == 1 || $this->MOD_SETTINGS['function'] == 2) {
752 $content .= '<form action="' . htmlspecialchars(BackendUtility::getModuleUrl($this->moduleName, ['id' => $this->id, 'imagemode' => $this->imagemode])) . '" id="PageLayoutController" method="post">';
753 // Page title
754 $content .= '<h1 class="t3js-title-inlineedit">' . htmlspecialchars($this->getLocalizedPageTitle()) . '</h1>';
755 // All other listings
756 $content .= $this->renderContent();
757 }
758 $content .= '</form>';
759 $content .= $this->searchContent;
760 // Setting up the buttons for the docheader
761 $this->makeButtons();
762 // @internal: This is an internal hook for compatibility7 only, this hook will be removed without further notice
763 if ($this->MOD_SETTINGS['function'] != 1 && $this->MOD_SETTINGS['function'] != 2) {
764 $renderActionHook = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][self::class]['renderActionHook'];
765 if (is_array($renderActionHook)) {
766 foreach ($renderActionHook as $hook) {
767 $params = [
768 'deleteButton' => $this->deleteButton,
769 ''
770 ];
771 $content .= GeneralUtility::callUserFunction($hook, $params, $this);
772 }
773 }
774 }
775 // Create LanguageMenu
776 $this->makeLanguageMenu();
777 } else {
778 $this->moduleTemplate->addJavaScriptCode(
779 'mainJsFunctions',
780 'if (top.fsMod) top.fsMod.recentIds["web"] = ' . (int)$this->id . ';'
781 );
782 $content .= '<h1>' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'] . '</h1>';
783 $view = GeneralUtility::makeInstance(StandaloneView::class);
784 $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Templates/InfoBox.html'));
785 $view->assignMultiple([
786 'title' => $lang->getLL('clickAPage_header'),
787 'message' => $lang->getLL('clickAPage_content'),
788 'state' => InfoboxViewHelper::STATE_INFO
789 ]);
790 $content .= $view->render();
791 }
792 // Set content
793 $this->moduleTemplate->setContent($content);
794 }
795
796 /**
797 * Rendering content
798 *
799 * @return string
800 */
801 public function renderContent()
802 {
803 $this->moduleTemplate->getPageRenderer()->loadJquery();
804 $this->moduleTemplate->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/ContextMenu');
805 /** @var $dbList \TYPO3\CMS\Backend\View\PageLayoutView */
806 $dbList = GeneralUtility::makeInstance(PageLayoutView::class);
807 $dbList->thumbs = $this->imagemode;
808 $dbList->no_noWrap = 1;
809 $dbList->descrTable = $this->descrTable;
810 $this->pointer = MathUtility::forceIntegerInRange($this->pointer, 0, 100000);
811 $dbList->script = BackendUtility::getModuleUrl($this->moduleName);
812 $dbList->showIcon = 0;
813 $dbList->setLMargin = 0;
814 $dbList->doEdit = $this->EDIT_CONTENT;
815 $dbList->ext_CALC_PERMS = $this->CALC_PERMS;
816 $dbList->agePrefixes = $this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.minutesHoursDaysYears');
817 $dbList->id = $this->id;
818 $dbList->nextThree = MathUtility::forceIntegerInRange($this->modTSconfig['properties']['editFieldsAtATime'], 0, 10);
819 $dbList->option_newWizard = $this->modTSconfig['properties']['disableNewContentElementWizard'] ? 0 : 1;
820 $dbList->defLangBinding = $this->modTSconfig['properties']['defLangBinding'] ? 1 : 0;
821 if (!$dbList->nextThree) {
822 $dbList->nextThree = 1;
823 }
824 // Create menu for selecting a table to jump to (this is, if more than just pages/tt_content elements are found on the page!)
825 // also fills $dbList->activeTables
826 $dbList->getTableMenu($this->id);
827 // Initialize other variables:
828 $tableOutput = [];
829 $tableJSOutput = [];
830 $CMcounter = 0;
831 // Traverse the list of table names which has records on this page (that array is populated
832 // by the $dblist object during the function getTableMenu()):
833 foreach ($dbList->activeTables as $table => $value) {
834 $h_func = '';
835 $h_func_b = '';
836 if (!isset($dbList->externalTables[$table])) {
837 // Toggle hidden ContentElements
838 $numberOfHiddenElements = $this->getNumberOfHiddenElements();
839 if ($numberOfHiddenElements > 0) {
840 $h_func_b = '
841 <div class="checkbox">
842 <label for="checkTt_content_showHidden">
843 <input type="checkbox" id="checkTt_content_showHidden" class="checkbox" name="SET[tt_content_showHidden]" value="1" ' . ($this->MOD_SETTINGS['tt_content_showHidden'] ? 'checked="checked"' : '') . ' />
844 ' . htmlspecialchars($this->getLanguageService()->getLL('hiddenCE')) . ' (<span class="t3js-hidden-counter">' . $numberOfHiddenElements . '</span>)
845 </label>
846 </div>';
847 }
848
849 // Boolean: Display up/down arrows and edit icons for tt_content records
850 $dbList->tt_contentConfig['showCommands'] = 1;
851 // Boolean: Display info-marks or not
852 $dbList->tt_contentConfig['showInfo'] = 1;
853 // Setting up the tt_content columns to show:
854 if (is_array($GLOBALS['TCA']['tt_content']['columns']['colPos']['config']['items'])) {
855 $colList = [];
856 $tcaItems = GeneralUtility::callUserFunction(BackendLayoutView::class . '->getColPosListItemsParsed', $this->id, $this);
857 foreach ($tcaItems as $temp) {
858 $colList[] = $temp[1];
859 }
860 } else {
861 // ... should be impossible that colPos has no array. But this is the fallback should it make any sense:
862 $colList = ['1', '0', '2', '3'];
863 }
864 if ($this->colPosList !== '') {
865 $colList = array_intersect(GeneralUtility::intExplode(',', $this->colPosList), $colList);
866 }
867 // The order of the rows: Default is left(1), Normal(0), right(2), margin(3)
868 $dbList->tt_contentConfig['cols'] = implode(',', $colList);
869 $dbList->tt_contentConfig['activeCols'] = $this->activeColPosList;
870 $dbList->tt_contentConfig['showHidden'] = $this->MOD_SETTINGS['tt_content_showHidden'];
871 $dbList->tt_contentConfig['sys_language_uid'] = (int)$this->current_sys_language;
872 // If the function menu is set to "Language":
873 if ($this->MOD_SETTINGS['function'] == 2) {
874 $dbList->tt_contentConfig['languageMode'] = 1;
875 $dbList->tt_contentConfig['languageCols'] = $this->MOD_MENU['language'];
876 $dbList->tt_contentConfig['languageColsPointer'] = $this->current_sys_language;
877 }
878 } else {
879 if (isset($this->MOD_SETTINGS) && isset($this->MOD_MENU)) {
880 $h_func = BackendUtility::getFuncMenu($this->id, 'SET[' . $table . ']', $this->MOD_SETTINGS[$table], $this->MOD_MENU[$table], '', '');
881 }
882 }
883 // Start the dblist object:
884 $dbList->itemsLimitSingleTable = 1000;
885 $dbList->start($this->id, $table, $this->pointer, $this->search_field, $this->search_levels, $this->showLimit);
886 $dbList->counter = $CMcounter;
887 $dbList->ext_function = $this->MOD_SETTINGS['function'];
888 // Generate the list of elements here:
889 $dbList->generateList();
890 // Adding the list content to the tableOutput variable:
891 $tableOutput[$table] = $h_func . $dbList->HTMLcode . $h_func_b;
892 // ... and any accumulated JavaScript goes the same way!
893 $tableJSOutput[$table] = $dbList->JScode;
894 // Increase global counter:
895 $CMcounter += $dbList->counter;
896 // Reset variables after operation:
897 $dbList->HTMLcode = '';
898 $dbList->JScode = '';
899 }
900 // END: traverse tables
901 // For Context Sensitive Menus:
902 // Init the content
903 $content = '';
904 // Additional header content
905 $headerContentHook = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/db_layout.php']['drawHeaderHook'];
906 if (is_array($headerContentHook)) {
907 foreach ($headerContentHook as $hook) {
908 $params = [];
909 $content .= GeneralUtility::callUserFunction($hook, $params, $this);
910 }
911 }
912 // Add the content for each table we have rendered (traversing $tableOutput variable)
913 foreach ($tableOutput as $table => $output) {
914 $content .= $output;
915 }
916 // Making search form:
917 if (!$this->modTSconfig['properties']['disableSearchBox'] && ($dbList->counter > 0 || $this->currentPageHasSubPages())) {
918 $this->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/ToggleSearchToolbox');
919 $toggleSearchFormButton = $this->buttonBar->makeLinkButton()
920 ->setClasses('t3js-toggle-search-toolbox')
921 ->setTitle($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.title.searchIcon'))
922 ->setIcon($this->iconFactory->getIcon('actions-search', Icon::SIZE_SMALL))
923 ->setHref('#');
924 $this->buttonBar->addButton($toggleSearchFormButton, ButtonBar::BUTTON_POSITION_LEFT, 4);
925 $this->searchContent = $dbList->getSearchBox();
926 }
927 // Additional footer content
928 $footerContentHook = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/db_layout.php']['drawFooterHook'];
929 if (is_array($footerContentHook)) {
930 foreach ($footerContentHook as $hook) {
931 $params = [];
932 $content .= GeneralUtility::callUserFunction($hook, $params, $this);
933 }
934 }
935 return $content;
936 }
937
938 /**
939 * @return ModuleTemplate
940 */
941 public function getModuleTemplate()
942 {
943 return $this->moduleTemplate;
944 }
945
946 /***************************
947 *
948 * Sub-content functions, rendering specific parts of the module content.
949 *
950 ***************************/
951 /**
952 * This creates the buttons for the modules
953 */
954 protected function makeButtons()
955 {
956 if ($this->MOD_SETTINGS['function'] == 1 || $this->MOD_SETTINGS['function'] == 2) {
957 // Add CSH (Context Sensitive Help) icon to tool bar
958 $contextSensitiveHelpButton = $this->buttonBar->makeHelpButton()
959 ->setModuleName($this->descrTable)
960 ->setFieldName('columns_' . $this->MOD_SETTINGS['function']);
961 $this->buttonBar->addButton($contextSensitiveHelpButton);
962 }
963 $lang = $this->getLanguageService();
964 // View page
965 if (!VersionState::cast($this->pageinfo['t3ver_state'])->equals(VersionState::DELETE_PLACEHOLDER)) {
966 $viewButton = $this->buttonBar->makeLinkButton()
967 ->setOnClick(BackendUtility::viewOnClick($this->pageinfo['uid'], '', BackendUtility::BEgetRootLine($this->pageinfo['uid'])))
968 ->setTitle($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.showPage'))
969 ->setIcon($this->iconFactory->getIcon('actions-view-page', Icon::SIZE_SMALL))
970 ->setHref('#');
971
972 $this->buttonBar->addButton($viewButton, ButtonBar::BUTTON_POSITION_LEFT, 3);
973 }
974 // Shortcut
975 $shortcutButton = $this->buttonBar->makeShortcutButton()
976 ->setModuleName($this->moduleName)
977 ->setGetVariables([
978 'id',
979 'M',
980 'edit_record',
981 'pointer',
982 'new_unique_uid',
983 'search_field',
984 'search_levels',
985 'showLimit'
986 ])
987 ->setSetVariables(array_keys($this->MOD_MENU));
988 $this->buttonBar->addButton($shortcutButton);
989
990 // Cache
991 if (!$this->modTSconfig['properties']['disableAdvanced']) {
992 $clearCacheButton = $this->buttonBar->makeLinkButton()
993 ->setHref(BackendUtility::getModuleUrl($this->moduleName, ['id' => $this->pageinfo['uid'], 'clear_cache' => '1']))
994 ->setTitle($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.clear_cache'))
995 ->setIcon($this->iconFactory->getIcon('actions-system-cache-clear', Icon::SIZE_SMALL));
996 $this->buttonBar->addButton($clearCacheButton, ButtonBar::BUTTON_POSITION_RIGHT, 1);
997 }
998 if (!$this->modTSconfig['properties']['disableIconToolbar']) {
999 // Edit page properties and page language overlay icons
1000 if ($this->pageIsNotLockedForEditors() && $this->getBackendUser()->checkLanguageAccess(0)) {
1001 // Edit localized page_language_overlay only when one specific language is selected
1002 if ($this->MOD_SETTINGS['function'] == 1 && $this->current_sys_language > 0) {
1003 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
1004 ->getQueryBuilderForTable('pages_language_overlay');
1005 $queryBuilder->getRestrictions()
1006 ->removeAll()
1007 ->add(GeneralUtility::makeInstance(DeletedRestriction::class))
1008 ->add(GeneralUtility::makeInstance(BackendWorkspaceRestriction::class));
1009 $overlayRecord = $queryBuilder
1010 ->select('uid')
1011 ->from('pages_language_overlay')
1012 ->where(
1013 $queryBuilder->expr()->eq(
1014 'pid',
1015 $queryBuilder->createNamedParameter($this->id, \PDO::PARAM_INT)
1016 ),
1017 $queryBuilder->expr()->eq(
1018 'sys_language_uid',
1019 $queryBuilder->createNamedParameter($this->current_sys_language, \PDO::PARAM_INT)
1020 )
1021 )
1022 ->setMaxResults(1)
1023 ->execute()
1024 ->fetch();
1025 // Edit button
1026 $urlParameters = [
1027 'edit' => [
1028 'pages_language_overlay' => [
1029 $overlayRecord['uid'] => 'edit'
1030 ]
1031 ],
1032 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
1033 ];
1034 $url = BackendUtility::getModuleUrl('record_edit', $urlParameters);
1035 $editLanguageButton = $this->buttonBar->makeLinkButton()
1036 ->setHref($url)
1037 ->setTitle($lang->getLL('editPageLanguageOverlayProperties'))
1038 ->setIcon($this->iconFactory->getIcon('mimetypes-x-content-page-language-overlay', Icon::SIZE_SMALL));
1039 $this->buttonBar->addButton($editLanguageButton, ButtonBar::BUTTON_POSITION_LEFT, 3);
1040 }
1041 $urlParameters = [
1042 'edit' => [
1043 'pages' => [
1044 $this->id => 'edit'
1045 ]
1046 ],
1047 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
1048 ];
1049 $url = BackendUtility::getModuleUrl('record_edit', $urlParameters);
1050 $editPageButton = $this->buttonBar->makeLinkButton()
1051 ->setHref($url)
1052 ->setTitle($lang->getLL('editPageProperties'))
1053 ->setIcon($this->iconFactory->getIcon('actions-page-open', Icon::SIZE_SMALL));
1054 $this->buttonBar->addButton($editPageButton, ButtonBar::BUTTON_POSITION_LEFT, 3);
1055 }
1056 }
1057 }
1058
1059 /*******************************
1060 *
1061 * Other functions
1062 *
1063 ******************************/
1064 /**
1065 * Returns the number of hidden elements (including those hidden by start/end times)
1066 * on the current page (for the current sys_language)
1067 *
1068 * @return int
1069 */
1070 public function getNumberOfHiddenElements()
1071 {
1072 /** @var QueryBuilder $queryBuilder */
1073 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tt_content');
1074 $queryBuilder->getRestrictions()
1075 ->removeAll()
1076 ->add(GeneralUtility::makeInstance(DeletedRestriction::class))
1077 ->add(GeneralUtility::makeInstance(BackendWorkspaceRestriction::class));
1078
1079 $queryBuilder
1080 ->count('uid')
1081 ->from('tt_content')
1082 ->where(
1083 $queryBuilder->expr()->eq(
1084 'pid',
1085 $queryBuilder->createNamedParameter($this->id, \PDO::PARAM_INT)
1086 ),
1087 $queryBuilder->expr()->eq(
1088 'sys_language_uid',
1089 $queryBuilder->createNamedParameter($this->current_sys_language, \PDO::PARAM_INT)
1090 )
1091 );
1092
1093 if (!empty($GLOBALS['TCA']['tt_content']['ctrl']['enablecolumns']['disabled'])) {
1094 $andWhere[] = $queryBuilder->expr()->neq(
1095 'hidden',
1096 $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
1097 );
1098 }
1099
1100 if (!empty($GLOBALS['TCA']['tt_content']['ctrl']['enablecolumns']['starttime'])) {
1101 $andWhere[] = $queryBuilder->expr()->andX(
1102 $queryBuilder->expr()->neq(
1103 'starttime',
1104 $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
1105 ),
1106 $queryBuilder->expr()->gt(
1107 'starttime',
1108 $queryBuilder->createNamedParameter($GLOBALS['SIM_ACCESS_TIME'], \PDO::PARAM_INT)
1109 )
1110 );
1111 }
1112
1113 if (!empty($GLOBALS['TCA']['tt_content']['ctrl']['enablecolumns']['endtime'])) {
1114 $andWhere[] = $queryBuilder->expr()->andX(
1115 $queryBuilder->expr()->neq(
1116 'endtime',
1117 $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
1118 ),
1119 $queryBuilder->expr()->lte(
1120 'endtime',
1121 $queryBuilder->createNamedParameter($GLOBALS['SIM_ACCESS_TIME'], \PDO::PARAM_INT)
1122 )
1123 );
1124 }
1125
1126 if (!empty($andWhere)) {
1127 $queryBuilder->andWhere(
1128 $queryBuilder->expr()->orX(...$andWhere)
1129 );
1130 }
1131
1132 $count = $queryBuilder
1133 ->execute()
1134 ->fetchColumn(0);
1135
1136 return (int)$count;
1137 }
1138
1139 /**
1140 * Returns URL to the current script.
1141 * In particular the "popView" and "new_unique_uid" Get vars are unset.
1142 *
1143 * @param array $params Parameters array, merged with global GET vars.
1144 * @return string URL
1145 */
1146 public function local_linkThisScript($params)
1147 {
1148 $params['popView'] = '';
1149 $params['new_unique_uid'] = '';
1150 return GeneralUtility::linkThisScript($params);
1151 }
1152
1153 /**
1154 * Check if page can be edited by current user
1155 *
1156 * @return bool
1157 */
1158 public function pageIsNotLockedForEditors()
1159 {
1160 return $this->getBackendUser()->isAdmin() || ($this->CALC_PERMS & Permission::PAGE_EDIT) === Permission::PAGE_EDIT && !$this->pageinfo['editlock'];
1161 }
1162
1163 /**
1164 * Check if content can be edited by current user
1165 *
1166 * @return bool
1167 */
1168 public function contentIsNotLockedForEditors()
1169 {
1170 return $this->getBackendUser()->isAdmin() || ($this->CALC_PERMS & Permission::CONTENT_EDIT) === Permission::CONTENT_EDIT && !$this->pageinfo['editlock'];
1171 }
1172
1173 /**
1174 * Returns LanguageService
1175 *
1176 * @return \TYPO3\CMS\Core\Localization\LanguageService
1177 */
1178 protected function getLanguageService()
1179 {
1180 return $GLOBALS['LANG'];
1181 }
1182
1183 /**
1184 * Returns the current BE user.
1185 *
1186 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
1187 */
1188 protected function getBackendUser()
1189 {
1190 return $GLOBALS['BE_USER'];
1191 }
1192
1193 /**
1194 * Returns current PageRenderer
1195 *
1196 * @return PageRenderer
1197 */
1198 protected function getPageRenderer()
1199 {
1200 return GeneralUtility::makeInstance(PageRenderer::class);
1201 }
1202
1203 /**
1204 * Make the LanguageMenu
1205 */
1206 protected function makeLanguageMenu()
1207 {
1208 if (count($this->MOD_MENU['language']) > 1) {
1209 $lang = $this->getLanguageService();
1210 $languageMenu = $this->moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->makeMenu();
1211 $languageMenu->setIdentifier('languageMenu');
1212 foreach ($this->MOD_MENU['language'] as $key => $language) {
1213 $menuItem = $languageMenu
1214 ->makeMenuItem()
1215 ->setTitle($language)
1216 ->setHref(BackendUtility::getModuleUrl($this->moduleName) . '&id=' . $this->id . '&SET[language]=' . $key);
1217 if ((int)$this->current_sys_language === $key) {
1218 $menuItem->setActive(true);
1219 }
1220 $languageMenu->addMenuItem($menuItem);
1221 }
1222 $this->moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->addMenu($languageMenu);
1223 }
1224 }
1225
1226 /**
1227 * Checks whether the current page has sub pages
1228 *
1229 * @return bool
1230 */
1231 protected function currentPageHasSubPages()
1232 {
1233 /** @var QueryBuilder $queryBuilder */
1234 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages');
1235 $queryBuilder->getRestrictions()
1236 ->removeAll()
1237 ->add(GeneralUtility::makeInstance(DeletedRestriction::class))
1238 ->add(GeneralUtility::makeInstance(BackendWorkspaceRestriction::class));
1239
1240 // get workspace id
1241 $workspaceId = (int)$this->getBackendUser()->workspace;
1242 $comparisonExpression = $workspaceId === 0 ? 'neq' : 'eq';
1243
1244 $count = $queryBuilder
1245 ->count('uid')
1246 ->from('pages')
1247 ->where(
1248 $queryBuilder->expr()->eq('pid', $queryBuilder->createNamedParameter($this->id, \PDO::PARAM_INT)),
1249 $queryBuilder->expr()->eq(
1250 't3ver_wsid',
1251 $queryBuilder->createNamedParameter($workspaceId, \PDO::PARAM_INT)
1252 ),
1253 $queryBuilder->expr()->{$comparisonExpression}(
1254 'pid',
1255 $queryBuilder->createNamedParameter(-1, \PDO::PARAM_INT)
1256 )
1257 )
1258 ->execute()
1259 ->fetchColumn(0);
1260
1261 return (bool)$count;
1262 }
1263 }