[BUGFIX] Only apply language constraints for "Show hidden" checkbox if neccessary
[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\Http\HtmlResponse;
32 use TYPO3\CMS\Core\Imaging\Icon;
33 use TYPO3\CMS\Core\Imaging\IconFactory;
34 use TYPO3\CMS\Core\Page\PageRenderer;
35 use TYPO3\CMS\Core\Type\Bitmask\Permission;
36 use TYPO3\CMS\Core\Utility\GeneralUtility;
37 use TYPO3\CMS\Core\Utility\MathUtility;
38 use TYPO3\CMS\Core\Versioning\VersionState;
39 use TYPO3\CMS\Fluid\View\StandaloneView;
40 use TYPO3\CMS\Fluid\ViewHelpers\Be\InfoboxViewHelper;
41 use TYPO3\CMS\Frontend\Page\PageRepository;
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 * "Pseudo" Description -table name
141 *
142 * @var string
143 */
144 public $descrTable;
145
146 /**
147 * List of column-integers to edit. Is set from TSconfig, default is "1,0,2,3"
148 *
149 * @var string
150 */
151 public $colPosList;
152
153 /**
154 * Flag: If content can be edited or not.
155 *
156 * @var bool
157 */
158 public $EDIT_CONTENT;
159
160 /**
161 * Users permissions integer for this page.
162 *
163 * @var int
164 */
165 public $CALC_PERMS;
166
167 /**
168 * Currently selected language for editing content elements
169 *
170 * @var int
171 */
172 public $current_sys_language;
173
174 /**
175 * Module configuration
176 *
177 * @var array
178 */
179 public $MCONF = [];
180
181 /**
182 * Menu configuration
183 *
184 * @var array
185 */
186 public $MOD_MENU = [];
187
188 /**
189 * Module settings (session variable)
190 *
191 * @var array
192 */
193 public $MOD_SETTINGS = [];
194
195 /**
196 * Module output accumulation
197 *
198 * @var string
199 */
200 public $content;
201
202 /**
203 * List of column-integers accessible to the current BE user.
204 * Is set from TSconfig, default is $colPosList
205 *
206 * @var string
207 */
208 public $activeColPosList;
209
210 /**
211 * @var string
212 */
213 protected $editSelect;
214
215 /**
216 * Caches the available languages in a colPos
217 *
218 * @var array
219 */
220 protected $languagesInColumnCache = [];
221
222 /**
223 * @var IconFactory
224 */
225 protected $iconFactory;
226
227 /**
228 * The name of the module
229 *
230 * @var string
231 */
232 protected $moduleName = 'web_layout';
233
234 /**
235 * @var ModuleTemplate
236 */
237 protected $moduleTemplate;
238
239 /**
240 * @var ButtonBar
241 */
242 protected $buttonBar;
243
244 /**
245 * @var string
246 */
247 protected $searchContent;
248
249 /**
250 * Initializing the module
251 */
252 public function init()
253 {
254 $this->moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class);
255 $this->iconFactory = $this->moduleTemplate->getIconFactory();
256 $this->buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
257 $this->getLanguageService()->includeLLFile('EXT:backend/Resources/Private/Language/locallang_layout.xlf');
258 // Setting module configuration / page select clause
259 $this->MCONF['name'] = $this->moduleName;
260 $this->perms_clause = $this->getBackendUser()->getPagePermsClause(Permission::PAGE_SHOW);
261 // Get session data
262 $sessionData = $this->getBackendUser()->getSessionData(__CLASS__);
263 $this->search_field = !empty($sessionData['search_field']) ? $sessionData['search_field'] : '';
264 // GPvars:
265 $this->id = (int)GeneralUtility::_GP('id');
266 $this->pointer = GeneralUtility::_GP('pointer');
267 $this->imagemode = GeneralUtility::_GP('imagemode');
268 $this->clear_cache = GeneralUtility::_GP('clear_cache');
269 $this->popView = GeneralUtility::_GP('popView');
270 $this->search_field = GeneralUtility::_GP('search_field');
271 $this->search_levels = GeneralUtility::_GP('search_levels');
272 $this->showLimit = GeneralUtility::_GP('showLimit');
273 $this->returnUrl = GeneralUtility::sanitizeLocalUrl(GeneralUtility::_GP('returnUrl'));
274 $sessionData['search_field'] = $this->search_field;
275 // Store session data
276 $this->getBackendUser()->setAndSaveSessionData(__CLASS__, $sessionData);
277 // Load page info array:
278 $this->pageinfo = BackendUtility::readPageAccess($this->id, $this->perms_clause);
279 // Initialize menu
280 $this->menuConfig();
281 // Setting sys language from session var:
282 $this->current_sys_language = (int)$this->MOD_SETTINGS['language'];
283 // CSH / Descriptions:
284 $this->descrTable = '_MOD_' . $this->moduleName;
285 }
286
287 /**
288 * Initialize menu array
289 */
290 public function menuConfig()
291 {
292 $lang = $this->getLanguageService();
293 // MENU-ITEMS:
294 $this->MOD_MENU = [
295 'tt_content_showHidden' => '',
296 'function' => [
297 1 => $lang->getLL('m_function_1'),
298 2 => $lang->getLL('m_function_2')
299 ],
300 'language' => [
301 0 => $lang->getLL('m_default')
302 ]
303 ];
304 // initialize page/be_user TSconfig settings
305 $this->modSharedTSconfig = BackendUtility::getModTSconfig($this->id, 'mod.SHARED');
306 $this->modTSconfig = BackendUtility::getModTSconfig($this->id, 'mod.' . $this->moduleName);
307
308 // 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.
309 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_language');
310 $queryBuilder->getRestrictions()->removeAll();
311 if ($this->id) {
312 $queryBuilder->select('sys_language.uid AS uid', 'sys_language.title AS title')
313 ->from('sys_language')
314 ->join(
315 'sys_language',
316 'pages',
317 'pages',
318 $queryBuilder->expr()->eq(
319 'sys_language.uid',
320 $queryBuilder->quoteIdentifier('pages.' . $GLOBALS['TCA']['pages']['ctrl']['languageField'])
321 )
322 )
323 ->where(
324 $queryBuilder->expr()->eq(
325 'pages.deleted',
326 $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
327 ),
328 $queryBuilder->expr()->eq(
329 'pages.' . $GLOBALS['TCA']['pages']['ctrl']['transOrigPointerField'],
330 $queryBuilder->createNamedParameter($this->id, \PDO::PARAM_INT)
331 ),
332 $queryBuilder->expr()->orX(
333 $queryBuilder->expr()->gte(
334 'pages.t3ver_state',
335 $queryBuilder->createNamedParameter(
336 (string)new VersionState(VersionState::DEFAULT_STATE),
337 \PDO::PARAM_INT
338 )
339 ),
340 $queryBuilder->expr()->eq(
341 'pages.t3ver_wsid',
342 $queryBuilder->createNamedParameter($this->getBackendUser()->workspace, \PDO::PARAM_INT)
343 )
344 )
345 )
346 ->groupBy(
347 'pages.' . $GLOBALS['TCA']['pages']['ctrl']['languageField'],
348 'sys_language.uid',
349 'sys_language.pid',
350 'sys_language.tstamp',
351 'sys_language.hidden',
352 'sys_language.title',
353 'sys_language.language_isocode',
354 'sys_language.static_lang_isocode',
355 'sys_language.flag',
356 'sys_language.sorting'
357 )
358 ->orderBy('sys_language.sorting');
359 if (!$this->getBackendUser()->isAdmin()) {
360 $queryBuilder->andWhere(
361 $queryBuilder->expr()->eq(
362 'sys_language.hidden',
363 $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
364 )
365 );
366 }
367 $statement = $queryBuilder->execute();
368 } else {
369 $queryBuilder->getRestrictions()->add(GeneralUtility::makeInstance(HiddenRestriction::class));
370 $statement = $queryBuilder->select('uid', 'title')
371 ->from('sys_language')
372 ->orderBy('sorting')
373 ->execute();
374 }
375 while ($lRow = $statement->fetch()) {
376 if ($this->getBackendUser()->checkLanguageAccess($lRow['uid'])) {
377 $this->MOD_MENU['language'][$lRow['uid']] = $lRow['title'];
378 }
379 }
380 // Setting alternative default label:
381 if ((!empty($this->modSharedTSconfig['properties']['defaultLanguageLabel']) || !empty($this->modTSconfig['properties']['defaultLanguageLabel'])) && isset($this->MOD_MENU['language'][0])) {
382 $this->MOD_MENU['language'][0] = $this->modTSconfig['properties']['defaultLanguageLabel'] ? $this->modTSconfig['properties']['defaultLanguageLabel'] : $this->modSharedTSconfig['properties']['defaultLanguageLabel'];
383 }
384 // Initialize the avaiable actions
385 $actions = $this->initActions();
386 // Clean up settings
387 $this->MOD_SETTINGS = BackendUtility::getModuleData($this->MOD_MENU, GeneralUtility::_GP('SET'), $this->moduleName);
388 // For all elements to be shown in draft workspaces & to also show hidden elements by default if user hasn't disabled the option
389 if ($this->getBackendUser()->workspace != 0
390 || !isset($this->MOD_SETTINGS['tt_content_showHidden'])
391 || $this->MOD_SETTINGS['tt_content_showHidden'] !== '0'
392 ) {
393 $this->MOD_SETTINGS['tt_content_showHidden'] = 1;
394 }
395 // Make action menu from available actions
396 $this->makeActionMenu($actions);
397 }
398
399 /**
400 * Initializes the available actions this module provides
401 *
402 * @return array the available actions
403 */
404 protected function initActions()
405 {
406 $actions = [
407 1 => $this->getLanguageService()->getLL('m_function_1'),
408 2 => $this->getLanguageService()->getLL('m_function_2')
409 ];
410 // Find if there are ANY languages at all (and if not, remove the language option from function menu).
411 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_language');
412 if ($this->getBackendUser()->isAdmin()) {
413 $queryBuilder->getRestrictions()->removeAll();
414 }
415
416 $count = $queryBuilder
417 ->count('uid')
418 ->from('sys_language')
419 ->execute()
420 ->fetchColumn(0);
421
422 if (!$count) {
423 unset($actions['2']);
424 }
425 // page/be_user TSconfig blinding of menu-items
426 $actions = BackendUtility::unsetMenuItems($this->modTSconfig['properties'], $actions, 'menu.function');
427
428 return $actions;
429 }
430
431 /**
432 * This creates the dropdown menu with the different actions this module is able to provide.
433 * For now they are Columns, Quick Edit and Languages.
434 *
435 * @param array $actions array with the available actions
436 */
437 protected function makeActionMenu(array $actions)
438 {
439 $actionMenu = $this->moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->makeMenu();
440 $actionMenu->setIdentifier('actionMenu');
441 $actionMenu->setLabel('');
442
443 /** @var \TYPO3\CMS\Backend\Routing\UriBuilder $uriBuilder */
444 $uriBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Routing\UriBuilder::class);
445
446 $defaultKey = null;
447 $foundDefaultKey = false;
448 foreach ($actions as $key => $action) {
449 $menuItem = $actionMenu
450 ->makeMenuItem()
451 ->setTitle($action)
452 ->setHref((string)$uriBuilder->buildUriFromRoute($this->moduleName) . '&id=' . $this->id . '&SET[function]=' . $key);
453
454 if (!$foundDefaultKey) {
455 $defaultKey = $key;
456 $foundDefaultKey = true;
457 }
458 if ((int)$this->MOD_SETTINGS['function'] === $key) {
459 $menuItem->setActive(true);
460 $defaultKey = null;
461 }
462 $actionMenu->addMenuItem($menuItem);
463 }
464 if (isset($defaultKey)) {
465 $this->MOD_SETTINGS['function'] = $defaultKey;
466 }
467 $this->moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->addMenu($actionMenu);
468 }
469
470 /**
471 * Clears page cache for the current id, $this->id
472 */
473 public function clearCache()
474 {
475 if ($this->clear_cache && !empty($this->pageinfo)) {
476 $dataHandler = GeneralUtility::makeInstance(DataHandler::class);
477 $dataHandler->start([], []);
478 $dataHandler->clear_cacheCmd($this->id);
479 }
480 }
481
482 /**
483 * Generate the flashmessages for current pid
484 *
485 * @return string HTML content with flashmessages
486 */
487 protected function getHeaderFlashMessagesForCurrentPid()
488 {
489 $content = '';
490 $lang = $this->getLanguageService();
491
492 $view = GeneralUtility::makeInstance(StandaloneView::class);
493 $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Templates/InfoBox.html'));
494
495 // If page is a folder
496 if ($this->pageinfo['doktype'] == PageRepository::DOKTYPE_SYSFOLDER) {
497 $moduleLoader = GeneralUtility::makeInstance(ModuleLoader::class);
498 $moduleLoader->load($GLOBALS['TBE_MODULES']);
499 $modules = $moduleLoader->modules;
500 if (is_array($modules['web']['sub']['list'])) {
501 $title = $lang->getLL('goToListModule');
502 $message = '<p>' . $lang->getLL('goToListModuleMessage') . '</p>';
503 $message .= '<a class="btn btn-info" href="javascript:top.goToModule(\'web_list\',1);">' . $lang->getLL('goToListModule') . '</a>';
504 $view->assignMultiple([
505 'title' => $title,
506 'message' => $message,
507 'state' => InfoboxViewHelper::STATE_INFO
508 ]);
509 $content .= $view->render();
510 }
511 } elseif ($this->pageinfo['doktype'] === PageRepository::DOKTYPE_SHORTCUT) {
512 $shortcutMode = (int)$this->pageinfo['shortcut_mode'];
513 $pageRepository = GeneralUtility::makeInstance(PageRepository::class);
514 $targetPage = [];
515
516 if ($this->pageinfo['shortcut'] || $shortcutMode) {
517 switch ($shortcutMode) {
518 case PageRepository::SHORTCUT_MODE_NONE:
519 $targetPage = $pageRepository->getPage($this->pageinfo['shortcut']);
520 break;
521 case PageRepository::SHORTCUT_MODE_FIRST_SUBPAGE:
522 $targetPage = reset($pageRepository->getMenu($this->pageinfo['shortcut'] ?: $this->pageinfo['uid']));
523 break;
524 case PageRepository::SHORTCUT_MODE_PARENT_PAGE:
525 $targetPage = $pageRepository->getPage($this->pageinfo['pid']);
526 break;
527 }
528
529 $message = '';
530 if ($shortcutMode === PageRepository::SHORTCUT_MODE_RANDOM_SUBPAGE) {
531 $message .= sprintf($lang->getLL('pageIsRandomInternalLinkMessage'));
532 } else {
533 $linkToPid = $this->local_linkThisScript(['id' => $targetPage['uid']]);
534 $path = BackendUtility::getRecordPath($targetPage['uid'], $this->getBackendUser()->getPagePermsClause(Permission::PAGE_SHOW), 1000);
535 $linkedPath = '<a href="' . htmlspecialchars($linkToPid) . '">' . htmlspecialchars($path) . '</a>';
536 $message .= sprintf($lang->getLL('pageIsInternalLinkMessage'), $linkedPath);
537 }
538
539 $message .= ' (' . htmlspecialchars($lang->sL(BackendUtility::getLabelFromItemlist('pages', 'shortcut_mode', $shortcutMode))) . ')';
540
541 $view->assignMultiple([
542 'title' => $this->pageinfo['title'],
543 'message' => $message,
544 'state' => InfoboxViewHelper::STATE_INFO
545 ]);
546 $content .= $view->render();
547 } else {
548 if (empty($targetPage) && $shortcutMode !== PageRepository::SHORTCUT_MODE_RANDOM_SUBPAGE) {
549 $view->assignMultiple([
550 'title' => $this->pageinfo['title'],
551 'message' => $lang->getLL('pageIsMisconfiguredInternalLinkMessage'),
552 'state' => InfoboxViewHelper::STATE_ERROR
553 ]);
554 $content .= $view->render();
555 }
556 }
557 } elseif ($this->pageinfo['doktype'] === PageRepository::DOKTYPE_LINK) {
558 if (empty($this->pageinfo['url'])) {
559 $view->assignMultiple([
560 'title' => $this->pageinfo['title'],
561 'message' => $lang->getLL('pageIsMisconfiguredExternalLinkMessage'),
562 'state' => InfoboxViewHelper::STATE_ERROR
563 ]);
564 $content .= $view->render();
565 } else {
566 $externalUrl = htmlspecialchars(GeneralUtility::makeInstance(PageRepository::class)->getExtURL($this->pageinfo));
567 if ($externalUrl !== false) {
568 $externalUrlHtml = '<a href="' . $externalUrl . '" target="_blank" rel="noopener">' . $externalUrl . '</a>';
569 $view->assignMultiple([
570 'title' => $this->pageinfo['title'],
571 'message' => sprintf($lang->getLL('pageIsExternalLinkMessage'), $externalUrlHtml),
572 'state' => InfoboxViewHelper::STATE_INFO
573 ]);
574 $content .= $view->render();
575 }
576 }
577 }
578 // If content from different pid is displayed
579 if ($this->pageinfo['content_from_pid']) {
580 $contentPage = BackendUtility::getRecord('pages', (int)$this->pageinfo['content_from_pid']);
581 $linkToPid = $this->local_linkThisScript(['id' => $this->pageinfo['content_from_pid']]);
582 $title = BackendUtility::getRecordTitle('pages', $contentPage);
583 $link = '<a href="' . htmlspecialchars($linkToPid) . '">' . htmlspecialchars($title) . ' (PID ' . (int)$this->pageinfo['content_from_pid'] . ')</a>';
584 $message = sprintf($lang->getLL('content_from_pid_title'), $link);
585 $view->assignMultiple([
586 'title' => $title,
587 'message' => $message,
588 'state' => InfoboxViewHelper::STATE_INFO
589 ]);
590 $content .= $view->render();
591 } else {
592 $links = $this->getPageLinksWhereContentIsAlsoShownOn($this->pageinfo['uid']);
593 if (!empty($links)) {
594 $message = sprintf($lang->getLL('content_on_pid_title'), $links);
595 $view->assignMultiple([
596 'title' => '',
597 'message' => $message,
598 'state' => InfoboxViewHelper::STATE_INFO
599 ]);
600 $content .= $view->render();
601 }
602 }
603 return $content;
604 }
605
606 /**
607 * Get all pages with links where the content of a page $pageId is also shown on
608 *
609 * @param int $pageId
610 * @return string
611 */
612 protected function getPageLinksWhereContentIsAlsoShownOn($pageId)
613 {
614 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages');
615 $queryBuilder->getRestrictions()->removeAll();
616 $queryBuilder->getRestrictions()->add(GeneralUtility::makeInstance(DeletedRestriction::class));
617 $queryBuilder
618 ->select('*')
619 ->from('pages')
620 ->where($queryBuilder->expr()->eq('content_from_pid', $queryBuilder->createNamedParameter($pageId, \PDO::PARAM_INT)));
621
622 $links = [];
623 $rows = $queryBuilder->execute()->fetchAll();
624 if (!empty($rows)) {
625 foreach ($rows as $row) {
626 $linkToPid = $this->local_linkThisScript(['id' => $row['uid']]);
627 $title = BackendUtility::getRecordTitle('pages', $row);
628 $link = '<a href="' . htmlspecialchars($linkToPid) . '">' . htmlspecialchars($title) . ' (PID ' . (int)$row['uid'] . ')</a>';
629 $links[] = $link;
630 }
631 }
632 return implode(', ', $links);
633 }
634
635 /**
636 * @return string $title
637 */
638 protected function getLocalizedPageTitle()
639 {
640 if ($this->current_sys_language > 0) {
641 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
642 ->getQueryBuilderForTable('pages');
643 $queryBuilder->getRestrictions()
644 ->removeAll()
645 ->add(GeneralUtility::makeInstance(DeletedRestriction::class))
646 ->add(GeneralUtility::makeInstance(BackendWorkspaceRestriction::class));
647 $localizedPage = $queryBuilder
648 ->select('*')
649 ->from('pages')
650 ->where(
651 $queryBuilder->expr()->eq(
652 $GLOBALS['TCA']['pages']['ctrl']['transOrigPointerField'],
653 $queryBuilder->createNamedParameter($this->id, \PDO::PARAM_INT)
654 ),
655 $queryBuilder->expr()->eq(
656 $GLOBALS['TCA']['pages']['ctrl']['languageField'],
657 $queryBuilder->createNamedParameter($this->current_sys_language, \PDO::PARAM_INT)
658 )
659 )
660 ->setMaxResults(1)
661 ->execute()
662 ->fetch();
663 BackendUtility::workspaceOL('pages', $localizedPage);
664 return $localizedPage['title'];
665 }
666 return $this->pageinfo['title'];
667 }
668
669 /**
670 * Injects the request object for the current request or subrequest
671 * As this controller goes only through the main() method, it is rather simple for now
672 *
673 * @param ServerRequestInterface $request the current request
674 * @return ResponseInterface the response with the content
675 */
676 public function mainAction(ServerRequestInterface $request): ResponseInterface
677 {
678 $GLOBALS['SOBE'] = $this;
679 $this->init();
680 $this->clearCache();
681 $this->main();
682 return new HtmlResponse($this->moduleTemplate->renderContent());
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>' . htmlspecialchars($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 // Boolean: Display up/down arrows and edit icons for tt_content records
848 $dbList->tt_contentConfig['showCommands'] = 1;
849 // Boolean: Display info-marks or not
850 $dbList->tt_contentConfig['showInfo'] = 1;
851 // Setting up the tt_content columns to show:
852 if (is_array($GLOBALS['TCA']['tt_content']['columns']['colPos']['config']['items'])) {
853 $colList = [];
854 $tcaItems = GeneralUtility::callUserFunction(BackendLayoutView::class . '->getColPosListItemsParsed', $this->id, $this);
855 foreach ($tcaItems as $temp) {
856 $colList[] = $temp[1];
857 }
858 } else {
859 // ... should be impossible that colPos has no array. But this is the fallback should it make any sense:
860 $colList = ['1', '0', '2', '3'];
861 }
862 if ($this->colPosList !== '') {
863 $colList = array_intersect(GeneralUtility::intExplode(',', $this->colPosList), $colList);
864 }
865 // The order of the rows: Default is left(1), Normal(0), right(2), margin(3)
866 $dbList->tt_contentConfig['cols'] = implode(',', $colList);
867 $dbList->tt_contentConfig['activeCols'] = $this->activeColPosList;
868 $dbList->tt_contentConfig['showHidden'] = $this->MOD_SETTINGS['tt_content_showHidden'];
869 $dbList->tt_contentConfig['sys_language_uid'] = (int)$this->current_sys_language;
870 // If the function menu is set to "Language":
871 if ($this->MOD_SETTINGS['function'] == 2) {
872 $dbList->tt_contentConfig['languageMode'] = 1;
873 $dbList->tt_contentConfig['languageCols'] = $this->MOD_MENU['language'];
874 $dbList->tt_contentConfig['languageColsPointer'] = $this->current_sys_language;
875 }
876 // Toggle hidden ContentElements
877 $numberOfHiddenElements = $this->getNumberOfHiddenElements($dbList->tt_contentConfig);
878 if ($numberOfHiddenElements > 0) {
879 $h_func_b = '
880 <div class="checkbox">
881 <label for="checkTt_content_showHidden">
882 <input type="checkbox" id="checkTt_content_showHidden" class="checkbox" name="SET[tt_content_showHidden]" value="1" ' . ($this->MOD_SETTINGS['tt_content_showHidden'] ? 'checked="checked"' : '') . ' />
883 ' . htmlspecialchars($this->getLanguageService()->getLL('hiddenCE')) . ' (<span class="t3js-hidden-counter">' . $numberOfHiddenElements . '</span>)
884 </label>
885 </div>';
886 }
887 } else {
888 if (isset($this->MOD_SETTINGS) && isset($this->MOD_MENU)) {
889 $h_func = BackendUtility::getFuncMenu($this->id, 'SET[' . $table . ']', $this->MOD_SETTINGS[$table], $this->MOD_MENU[$table], '', '');
890 }
891 }
892 // Start the dblist object:
893 $dbList->itemsLimitSingleTable = 1000;
894 $dbList->start($this->id, $table, $this->pointer, $this->search_field, $this->search_levels, $this->showLimit);
895 $dbList->counter = $CMcounter;
896 $dbList->ext_function = $this->MOD_SETTINGS['function'];
897 // Generate the list of elements here:
898 $dbList->generateList();
899 // Adding the list content to the tableOutput variable:
900 $tableOutput[$table] = $h_func . $dbList->HTMLcode . $h_func_b;
901 // ... and any accumulated JavaScript goes the same way!
902 $tableJSOutput[$table] = $dbList->JScode;
903 // Increase global counter:
904 $CMcounter += $dbList->counter;
905 // Reset variables after operation:
906 $dbList->HTMLcode = '';
907 $dbList->JScode = '';
908 }
909 // END: traverse tables
910 // For Context Sensitive Menus:
911 // Init the content
912 $content = '';
913 // Additional header content
914 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/db_layout.php']['drawHeaderHook'] ?? [] as $hook) {
915 $params = [];
916 $content .= GeneralUtility::callUserFunction($hook, $params, $this);
917 }
918 // Add the content for each table we have rendered (traversing $tableOutput variable)
919 foreach ($tableOutput as $table => $output) {
920 $content .= $output;
921 }
922 // Making search form:
923 if (!$this->modTSconfig['properties']['disableSearchBox'] && ($dbList->counter > 0 || $this->currentPageHasSubPages())) {
924 $this->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/ToggleSearchToolbox');
925 $toggleSearchFormButton = $this->buttonBar->makeLinkButton()
926 ->setClasses('t3js-toggle-search-toolbox')
927 ->setTitle($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.title.searchIcon'))
928 ->setIcon($this->iconFactory->getIcon('actions-search', Icon::SIZE_SMALL))
929 ->setHref('#');
930 $this->buttonBar->addButton($toggleSearchFormButton, ButtonBar::BUTTON_POSITION_LEFT, 4);
931 $this->searchContent = $dbList->getSearchBox();
932 }
933 // Additional footer content
934 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/db_layout.php']['drawFooterHook'] ?? [] as $hook) {
935 $params = [];
936 $content .= GeneralUtility::callUserFunction($hook, $params, $this);
937 }
938 return $content;
939 }
940
941 /**
942 * @return ModuleTemplate
943 */
944 public function getModuleTemplate()
945 {
946 return $this->moduleTemplate;
947 }
948
949 /***************************
950 *
951 * Sub-content functions, rendering specific parts of the module content.
952 *
953 ***************************/
954 /**
955 * This creates the buttons for the modules
956 */
957 protected function makeButtons()
958 {
959 if ($this->MOD_SETTINGS['function'] == 1 || $this->MOD_SETTINGS['function'] == 2) {
960 // Add CSH (Context Sensitive Help) icon to tool bar
961 $contextSensitiveHelpButton = $this->buttonBar->makeHelpButton()
962 ->setModuleName($this->descrTable)
963 ->setFieldName('columns_' . $this->MOD_SETTINGS['function']);
964 $this->buttonBar->addButton($contextSensitiveHelpButton);
965 }
966 $lang = $this->getLanguageService();
967 // View page
968 if (!VersionState::cast($this->pageinfo['t3ver_state'])->equals(VersionState::DELETE_PLACEHOLDER)) {
969 $viewButton = $this->buttonBar->makeLinkButton()
970 ->setOnClick(BackendUtility::viewOnClick($this->pageinfo['uid'], '', BackendUtility::BEgetRootLine($this->pageinfo['uid'])))
971 ->setTitle($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.showPage'))
972 ->setIcon($this->iconFactory->getIcon('actions-view-page', Icon::SIZE_SMALL))
973 ->setHref('#');
974
975 $this->buttonBar->addButton($viewButton, ButtonBar::BUTTON_POSITION_LEFT, 3);
976 }
977 // Shortcut
978 $shortcutButton = $this->buttonBar->makeShortcutButton()
979 ->setModuleName($this->moduleName)
980 ->setGetVariables([
981 'id',
982 'route',
983 'edit_record',
984 'pointer',
985 'new_unique_uid',
986 'search_field',
987 'search_levels',
988 'showLimit'
989 ])
990 ->setSetVariables(array_keys($this->MOD_MENU));
991 $this->buttonBar->addButton($shortcutButton);
992
993 /** @var \TYPO3\CMS\Backend\Routing\UriBuilder $uriBuilder */
994 $uriBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Routing\UriBuilder::class);
995 // Cache
996 if (empty($this->modTSconfig['properties']['disableAdvanced'])) {
997 $clearCacheButton = $this->buttonBar->makeLinkButton()
998 ->setHref((string)$uriBuilder->buildUriFromRoute($this->moduleName, ['id' => $this->pageinfo['uid'], 'clear_cache' => '1']))
999 ->setTitle($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.clear_cache'))
1000 ->setIcon($this->iconFactory->getIcon('actions-system-cache-clear', Icon::SIZE_SMALL));
1001 $this->buttonBar->addButton($clearCacheButton, ButtonBar::BUTTON_POSITION_RIGHT, 1);
1002 }
1003 if (empty($this->modTSconfig['properties']['disableIconToolbar'])) {
1004 // Edit page properties and page language overlay icons
1005 if ($this->pageIsNotLockedForEditors() && $this->getBackendUser()->checkLanguageAccess(0)) {
1006 // Edit localized pages only when one specific language is selected
1007 if ($this->MOD_SETTINGS['function'] == 1 && $this->current_sys_language > 0) {
1008 $localizationParentField = $GLOBALS['TCA']['pages']['ctrl']['transOrigPointerField'];
1009 $languageField = $GLOBALS['TCA']['pages']['ctrl']['languageField'];
1010 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
1011 ->getQueryBuilderForTable('pages');
1012 $queryBuilder->getRestrictions()
1013 ->removeAll()
1014 ->add(GeneralUtility::makeInstance(DeletedRestriction::class))
1015 ->add(GeneralUtility::makeInstance(BackendWorkspaceRestriction::class));
1016 $overlayRecord = $queryBuilder
1017 ->select('uid')
1018 ->from('pages')
1019 ->where(
1020 $queryBuilder->expr()->eq(
1021 $localizationParentField,
1022 $queryBuilder->createNamedParameter($this->id, \PDO::PARAM_INT)
1023 ),
1024 $queryBuilder->expr()->eq(
1025 $languageField,
1026 $queryBuilder->createNamedParameter($this->current_sys_language, \PDO::PARAM_INT)
1027 )
1028 )
1029 ->setMaxResults(1)
1030 ->execute()
1031 ->fetch();
1032 // Edit button
1033 $urlParameters = [
1034 'edit' => [
1035 'pages' => [
1036 $overlayRecord['uid'] => 'edit'
1037 ]
1038 ],
1039 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
1040 ];
1041
1042 $url = (string)$uriBuilder->buildUriFromRoute('record_edit', $urlParameters);
1043 $editLanguageButton = $this->buttonBar->makeLinkButton()
1044 ->setHref($url)
1045 ->setTitle($lang->getLL('editPageLanguageOverlayProperties'))
1046 ->setIcon($this->iconFactory->getIcon('mimetypes-x-content-page-language-overlay', Icon::SIZE_SMALL));
1047 $this->buttonBar->addButton($editLanguageButton, ButtonBar::BUTTON_POSITION_LEFT, 3);
1048 }
1049 $urlParameters = [
1050 'edit' => [
1051 'pages' => [
1052 $this->id => 'edit'
1053 ]
1054 ],
1055 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
1056 ];
1057 $url = (string)$uriBuilder->buildUriFromRoute('record_edit', $urlParameters);
1058 $editPageButton = $this->buttonBar->makeLinkButton()
1059 ->setHref($url)
1060 ->setTitle($lang->getLL('editPageProperties'))
1061 ->setIcon($this->iconFactory->getIcon('actions-page-open', Icon::SIZE_SMALL));
1062 $this->buttonBar->addButton($editPageButton, ButtonBar::BUTTON_POSITION_LEFT, 3);
1063 }
1064 }
1065 }
1066
1067 /*******************************
1068 *
1069 * Other functions
1070 *
1071 ******************************/
1072 /**
1073 * Returns the number of hidden elements (including those hidden by start/end times)
1074 * on the current page (for the current sys_language)
1075 *
1076 * @param array $contentConfig
1077 * @return int
1078 */
1079 public function getNumberOfHiddenElements(array $contentConfig = [])
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 );
1097
1098 if (!empty($contentConfig['languageCols']) && is_array($contentConfig['languageCols'])) {
1099 // Multi-language view is active
1100 if ($this->current_sys_language > 0) {
1101 $queryBuilder->andWhere(
1102 $queryBuilder->expr()->in(
1103 'sys_language_uid',
1104 [0, $queryBuilder->createNamedParameter($this->current_sys_language, \PDO::PARAM_INT)]
1105 )
1106 );
1107 }
1108 } else {
1109 $queryBuilder->andWhere(
1110 $queryBuilder->expr()->eq(
1111 'sys_language_uid',
1112 $queryBuilder->createNamedParameter($this->current_sys_language, \PDO::PARAM_INT)
1113 )
1114 );
1115 }
1116
1117 if (!empty($GLOBALS['TCA']['tt_content']['ctrl']['enablecolumns']['disabled'])) {
1118 $andWhere[] = $queryBuilder->expr()->neq(
1119 'hidden',
1120 $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
1121 );
1122 }
1123
1124 if (!empty($GLOBALS['TCA']['tt_content']['ctrl']['enablecolumns']['starttime'])) {
1125 $andWhere[] = $queryBuilder->expr()->andX(
1126 $queryBuilder->expr()->neq(
1127 'starttime',
1128 $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
1129 ),
1130 $queryBuilder->expr()->gt(
1131 'starttime',
1132 $queryBuilder->createNamedParameter($GLOBALS['SIM_ACCESS_TIME'], \PDO::PARAM_INT)
1133 )
1134 );
1135 }
1136
1137 if (!empty($GLOBALS['TCA']['tt_content']['ctrl']['enablecolumns']['endtime'])) {
1138 $andWhere[] = $queryBuilder->expr()->andX(
1139 $queryBuilder->expr()->neq(
1140 'endtime',
1141 $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
1142 ),
1143 $queryBuilder->expr()->lte(
1144 'endtime',
1145 $queryBuilder->createNamedParameter($GLOBALS['SIM_ACCESS_TIME'], \PDO::PARAM_INT)
1146 )
1147 );
1148 }
1149
1150 if (!empty($andWhere)) {
1151 $queryBuilder->andWhere(
1152 $queryBuilder->expr()->orX(...$andWhere)
1153 );
1154 }
1155
1156 $count = $queryBuilder
1157 ->execute()
1158 ->fetchColumn(0);
1159
1160 return (int)$count;
1161 }
1162
1163 /**
1164 * Returns URL to the current script.
1165 * In particular the "popView" and "new_unique_uid" Get vars are unset.
1166 *
1167 * @param array $params Parameters array, merged with global GET vars.
1168 * @return string URL
1169 */
1170 public function local_linkThisScript($params)
1171 {
1172 $params['popView'] = '';
1173 $params['new_unique_uid'] = '';
1174 return GeneralUtility::linkThisScript($params);
1175 }
1176
1177 /**
1178 * Check if page can be edited by current user
1179 *
1180 * @return bool
1181 */
1182 public function pageIsNotLockedForEditors()
1183 {
1184 return $this->getBackendUser()->isAdmin() || ($this->CALC_PERMS & Permission::PAGE_EDIT) === Permission::PAGE_EDIT && !$this->pageinfo['editlock'];
1185 }
1186
1187 /**
1188 * Check if content can be edited by current user
1189 *
1190 * @return bool
1191 */
1192 public function contentIsNotLockedForEditors()
1193 {
1194 return $this->getBackendUser()->isAdmin() || ($this->CALC_PERMS & Permission::CONTENT_EDIT) === Permission::CONTENT_EDIT && !$this->pageinfo['editlock'];
1195 }
1196
1197 /**
1198 * Returns LanguageService
1199 *
1200 * @return \TYPO3\CMS\Core\Localization\LanguageService
1201 */
1202 protected function getLanguageService()
1203 {
1204 return $GLOBALS['LANG'];
1205 }
1206
1207 /**
1208 * Returns the current BE user.
1209 *
1210 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
1211 */
1212 protected function getBackendUser()
1213 {
1214 return $GLOBALS['BE_USER'];
1215 }
1216
1217 /**
1218 * Returns current PageRenderer
1219 *
1220 * @return PageRenderer
1221 */
1222 protected function getPageRenderer()
1223 {
1224 return GeneralUtility::makeInstance(PageRenderer::class);
1225 }
1226
1227 /**
1228 * Make the LanguageMenu
1229 */
1230 protected function makeLanguageMenu()
1231 {
1232 if (count($this->MOD_MENU['language']) > 1) {
1233 /** @var \TYPO3\CMS\Backend\Routing\UriBuilder $uriBuilder */
1234 $uriBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Routing\UriBuilder::class);
1235 $lang = $this->getLanguageService();
1236 $languageMenu = $this->moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->makeMenu();
1237 $languageMenu->setIdentifier('languageMenu');
1238 foreach ($this->MOD_MENU['language'] as $key => $language) {
1239 $menuItem = $languageMenu
1240 ->makeMenuItem()
1241 ->setTitle($language)
1242 ->setHref((string)$uriBuilder->buildUriFromRoute($this->moduleName) . '&id=' . $this->id . '&SET[language]=' . $key);
1243 if ((int)$this->current_sys_language === $key) {
1244 $menuItem->setActive(true);
1245 }
1246 $languageMenu->addMenuItem($menuItem);
1247 }
1248 $this->moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->addMenu($languageMenu);
1249 }
1250 }
1251
1252 /**
1253 * Checks whether the current page has sub pages
1254 *
1255 * @return bool
1256 */
1257 protected function currentPageHasSubPages()
1258 {
1259 /** @var QueryBuilder $queryBuilder */
1260 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages');
1261 $queryBuilder->getRestrictions()
1262 ->removeAll()
1263 ->add(GeneralUtility::makeInstance(DeletedRestriction::class))
1264 ->add(GeneralUtility::makeInstance(BackendWorkspaceRestriction::class));
1265
1266 // get workspace id
1267 $workspaceId = (int)$this->getBackendUser()->workspace;
1268 $comparisonExpression = $workspaceId === 0 ? 'neq' : 'eq';
1269
1270 $count = $queryBuilder
1271 ->count('uid')
1272 ->from('pages')
1273 ->where(
1274 $queryBuilder->expr()->eq('pid', $queryBuilder->createNamedParameter($this->id, \PDO::PARAM_INT)),
1275 $queryBuilder->expr()->eq(
1276 't3ver_wsid',
1277 $queryBuilder->createNamedParameter($workspaceId, \PDO::PARAM_INT)
1278 ),
1279 $queryBuilder->expr()->{$comparisonExpression}(
1280 'pid',
1281 $queryBuilder->createNamedParameter(-1, \PDO::PARAM_INT)
1282 )
1283 )
1284 ->execute()
1285 ->fetchColumn(0);
1286
1287 return (bool)$count;
1288 }
1289 }