Passed
Push — master ( ace65e...3a77b9 )
by
unknown
15:18
created

getHeaderFlashMessagesForCurrentPid()   D

Complexity

Conditions 22
Paths 75

Size

Total Lines 123
Code Lines 99

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 22
eloc 99
nc 75
nop 0
dl 0
loc 123
rs 4.1666
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the TYPO3 CMS project.
7
 *
8
 * It is free software; you can redistribute it and/or modify it under
9
 * the terms of the GNU General Public License, either version 2
10
 * of the License, or any later version.
11
 *
12
 * For the full copyright and license information, please read the
13
 * LICENSE.txt file that was distributed with this source code.
14
 *
15
 * The TYPO3 project - inspiring people to share!
16
 */
17
18
namespace TYPO3\CMS\Backend\Controller;
19
20
use Psr\Http\Message\ResponseInterface;
21
use Psr\Http\Message\ServerRequestInterface;
22
use TYPO3\CMS\Backend\Module\ModuleLoader;
23
use TYPO3\CMS\Backend\Routing\PreviewUriBuilder;
24
use TYPO3\CMS\Backend\Routing\UriBuilder;
25
use TYPO3\CMS\Backend\Template\Components\ButtonBar;
26
use TYPO3\CMS\Backend\Template\ModuleTemplate;
27
use TYPO3\CMS\Backend\Template\ModuleTemplateFactory;
28
use TYPO3\CMS\Backend\Utility\BackendUtility;
29
use TYPO3\CMS\Backend\View\BackendLayoutView;
30
use TYPO3\CMS\Backend\View\PageLayoutContext;
31
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
32
use TYPO3\CMS\Core\Database\ConnectionPool;
33
use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
34
use TYPO3\CMS\Core\Database\Query\Restriction\WorkspaceRestriction;
35
use TYPO3\CMS\Core\Domain\Repository\PageRepository;
36
use TYPO3\CMS\Core\Http\HtmlResponse;
37
use TYPO3\CMS\Core\Imaging\Icon;
38
use TYPO3\CMS\Core\Imaging\IconFactory;
39
use TYPO3\CMS\Core\Localization\LanguageService;
40
use TYPO3\CMS\Core\Page\PageRenderer;
41
use TYPO3\CMS\Core\Site\Entity\SiteInterface;
42
use TYPO3\CMS\Core\Site\Entity\SiteLanguage;
43
use TYPO3\CMS\Core\Type\Bitmask\Permission;
44
use TYPO3\CMS\Core\Utility\GeneralUtility;
45
use TYPO3\CMS\Core\Versioning\VersionState;
46
use TYPO3\CMS\Fluid\View\StandaloneView;
47
use TYPO3\CMS\Fluid\ViewHelpers\Be\InfoboxViewHelper;
48
49
/**
50
 * Script Class for Web > Layout module
51
 */
52
class PageLayoutController
53
{
54
    /**
55
     * Page Id for which to make the listing
56
     *
57
     * @var int
58
     * @internal
59
     */
60
    public $id;
61
62
    /**
63
     * Module TSconfig
64
     *
65
     * @var array
66
     */
67
    protected $modTSconfig = [];
68
69
    /**
70
     * Module shared TSconfig
71
     *
72
     * @var array
73
     */
74
    protected $modSharedTSconfig = [];
75
76
    /**
77
     * Current ids page record
78
     *
79
     * @var array|bool
80
     * @internal
81
     */
82
    public $pageinfo;
83
84
    /**
85
     * List of column-integers to edit. Is set from TSconfig, default is "1,0,2,3"
86
     *
87
     * @var string
88
     */
89
    protected $colPosList;
90
91
    /**
92
     * Currently selected language for editing content elements
93
     *
94
     * @var int
95
     */
96
    protected $current_sys_language;
97
98
    /**
99
     * Menu configuration
100
     *
101
     * @var array
102
     */
103
    protected $MOD_MENU = [];
104
105
    /**
106
     * Module settings (session variable)
107
     *
108
     * @var array
109
     * @internal
110
     */
111
    public $MOD_SETTINGS = [];
112
113
    /**
114
     * List of column-integers accessible to the current BE user.
115
     * Is set from TSconfig, default is $colPosList
116
     *
117
     * @var string
118
     */
119
    protected $activeColPosList;
120
121
    /**
122
     * The name of the module
123
     *
124
     * @var string
125
     */
126
    protected $moduleName = 'web_layout';
127
128
    /**
129
     * @var ModuleTemplate
130
     */
131
    protected $moduleTemplate;
132
133
    /**
134
     * @var ButtonBar
135
     */
136
    protected $buttonBar;
137
138
    /**
139
     * @var string
140
     */
141
    protected $searchContent;
142
143
    /**
144
     * @var SiteLanguage[]
145
     */
146
    protected $availableLanguages;
147
148
    /**
149
     * @var PageLayoutContext|null
150
     */
151
    protected $context;
152
153
    protected IconFactory $iconFactory;
154
    protected PageRenderer $pageRenderer;
155
    protected UriBuilder $uriBuilder;
156
    protected PageRepository $pageRepository;
157
    protected ModuleTemplateFactory $moduleTemplateFactory;
158
159
    public function __construct(
160
        IconFactory $iconFactory,
161
        PageRenderer $pageRenderer,
162
        UriBuilder $uriBuilder,
163
        PageRepository $pageRepository,
164
        ModuleTemplateFactory $moduleTemplateFactory
165
    ) {
166
        $this->iconFactory = $iconFactory;
167
        $this->pageRenderer = $pageRenderer;
168
        $this->uriBuilder = $uriBuilder;
169
        $this->pageRepository = $pageRepository;
170
        $this->moduleTemplateFactory = $moduleTemplateFactory;
171
    }
172
    /**
173
     * Injects the request object for the current request or subrequest
174
     * As this controller goes only through the main() method, it is rather simple for now
175
     *
176
     * @param ServerRequestInterface $request the current request
177
     * @return ResponseInterface the response with the content
178
     */
179
    public function mainAction(ServerRequestInterface $request): ResponseInterface
180
    {
181
        $this->moduleTemplate = $this->moduleTemplateFactory->create($request);
182
        $this->buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
183
        $this->getLanguageService()->includeLLFile('EXT:backend/Resources/Private/Language/locallang_layout.xlf');
184
        // Setting module configuration / page select clause
185
        $this->id = (int)($request->getParsedBody()['id'] ?? $request->getQueryParams()['id'] ?? 0);
186
187
        // Load page info array
188
        $this->pageinfo = BackendUtility::readPageAccess($this->id, $this->getBackendUser()->getPagePermsClause(Permission::PAGE_SHOW));
189
        if ($this->pageinfo !== false) {
190
            // If page info is not resolved, user has no access or the ID parameter was malformed.
191
            $this->context = GeneralUtility::makeInstance(
192
                PageLayoutContext::class,
193
                $this->pageinfo,
194
                GeneralUtility::makeInstance(BackendLayoutView::class)->getBackendLayoutForPage($this->id)
195
            );
196
        }
197
198
        /** @var SiteInterface $currentSite */
199
        $currentSite = $request->getAttribute('site');
200
        $this->availableLanguages = $currentSite->getAvailableLanguages($this->getBackendUser(), false, $this->id);
201
        // initialize page/be_user TSconfig settings
202
        $pageTsConfig = BackendUtility::getPagesTSconfig($this->id);
203
        $this->modSharedTSconfig['properties'] = $pageTsConfig['mod.']['SHARED.'] ?? [];
204
        $this->modTSconfig['properties'] = $pageTsConfig['mod.']['web_layout.'] ?? [];
205
206
        // Initialize menu
207
        $this->menuConfig($request);
208
        // Setting sys language from session var
209
        $this->current_sys_language = (int)$this->MOD_SETTINGS['language'];
210
211
        $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Recordlist/ClearCache');
212
213
        $this->main($request);
214
        return new HtmlResponse($this->moduleTemplate->renderContent());
215
    }
216
217
    /**
218
     * Initialize menu array
219
     * @param ServerRequestInterface $request
220
     */
221
    protected function menuConfig(ServerRequestInterface $request): void
222
    {
223
        // MENU-ITEMS:
224
        $this->MOD_MENU = [
225
            'tt_content_showHidden' => '',
226
            'function' => [
227
                1 => $this->getLanguageService()->getLL('m_function_1'),
228
                2 => $this->getLanguageService()->getLL('m_function_2')
229
            ],
230
            'language' => [
231
                0 => $this->getLanguageService()->getLL('m_default')
232
            ]
233
        ];
234
235
        // First, select all localized page records on the current page.
236
        // Each represents a possibility for a language on the page. Add these to language selector.
237
        if ($this->id) {
238
            // Compile language data for pid != 0 only. The language drop-down is not shown on pid 0
239
            // since pid 0 can't be localized.
240
            $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages');
241
            $queryBuilder->getRestrictions()->removeAll()
242
                ->add(GeneralUtility::makeInstance(DeletedRestriction::class))
243
                ->add(GeneralUtility::makeInstance(WorkspaceRestriction::class, (int)$this->getBackendUser()->workspace));
244
            $statement = $queryBuilder->select('uid', $GLOBALS['TCA']['pages']['ctrl']['languageField'])
245
                ->from('pages')
246
                ->where(
247
                    $queryBuilder->expr()->eq(
248
                        $GLOBALS['TCA']['pages']['ctrl']['transOrigPointerField'],
249
                        $queryBuilder->createNamedParameter($this->id, \PDO::PARAM_INT)
250
                    )
251
                )->execute();
252
            while ($pageTranslation = $statement->fetch()) {
253
                $languageId = $pageTranslation[$GLOBALS['TCA']['pages']['ctrl']['languageField']];
254
                if (isset($this->availableLanguages[$languageId])) {
255
                    $this->MOD_MENU['language'][$languageId] = $this->availableLanguages[$languageId]->getTitle();
256
                }
257
            }
258
            // Override the label
259
            if (isset($this->availableLanguages[0])) {
260
                $this->MOD_MENU['language'][0] = $this->availableLanguages[0]->getTitle();
261
            }
262
        }
263
        // Initialize the available actions
264
        $actions = $this->initActions();
265
        // Clean up settings
266
        $this->MOD_SETTINGS = BackendUtility::getModuleData($this->MOD_MENU, $request->getParsedBody()['SET'] ?? $request->getQueryParams()['SET'] ?? [], $this->moduleName);
267
        // For all elements to be shown in draft workspaces & to also show hidden elements by default if user hasn't disabled the option
268
        if ($this->getBackendUser()->workspace != 0
269
            || !isset($this->MOD_SETTINGS['tt_content_showHidden'])
270
            || $this->MOD_SETTINGS['tt_content_showHidden'] !== '0'
271
        ) {
272
            $this->MOD_SETTINGS['tt_content_showHidden'] = 1;
273
        }
274
        // Make action menu from available actions
275
        $this->makeActionMenu($actions);
276
    }
277
278
    /**
279
     * Initializes the available actions this module provides
280
     *
281
     * @return array the available actions
282
     */
283
    protected function initActions(): array
284
    {
285
        $actions = [
286
            1 => $this->getLanguageService()->getLL('m_function_1')
287
        ];
288
        // Find if there are ANY languages at all (and if not, do not show the language option from function menu).
289
        if (count($this->availableLanguages) > 1) {
290
            $actions[2] = $this->getLanguageService()->getLL('m_function_2');
291
        }
292
        $this->makeLanguageMenu();
293
        // Page / user TSconfig blinding of menu-items
294
        $blindActions = $this->modTSconfig['properties']['menu.']['functions.'] ?? [];
295
        foreach ($blindActions as $key => $value) {
296
            if (!$value && array_key_exists($key, $actions)) {
297
                unset($actions[$key]);
298
            }
299
        }
300
301
        return $actions;
302
    }
303
304
    /**
305
     * This creates the dropdown menu with the different actions this module is able to provide.
306
     * For now they are Columns and Languages.
307
     *
308
     * @param array $actions array with the available actions
309
     */
310
    protected function makeActionMenu(array $actions): void
311
    {
312
        $actionMenu = $this->moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->makeMenu();
313
        $actionMenu->setIdentifier('actionMenu');
314
        $actionMenu->setLabel('');
315
316
        $defaultKey = null;
317
        $foundDefaultKey = false;
318
        foreach ($actions as $key => $action) {
319
            $menuItem = $actionMenu
320
                ->makeMenuItem()
321
                ->setTitle($action)
322
                ->setHref((string)$this->uriBuilder->buildUriFromRoute($this->moduleName) . '&id=' . $this->id . '&SET[function]=' . $key);
323
324
            if (!$foundDefaultKey) {
325
                $defaultKey = $key;
326
                $foundDefaultKey = true;
327
            }
328
            if ((int)$this->MOD_SETTINGS['function'] === $key) {
329
                $menuItem->setActive(true);
330
                $defaultKey = null;
331
            }
332
            $actionMenu->addMenuItem($menuItem);
333
        }
334
        if (isset($defaultKey)) {
335
            $this->MOD_SETTINGS['function'] = $defaultKey;
336
        }
337
        $this->moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->addMenu($actionMenu);
338
    }
339
340
    /**
341
     * Generate the flashmessages for current pid
342
     *
343
     * @return string HTML content with flashmessages
344
     */
345
    protected function getHeaderFlashMessagesForCurrentPid(): string
346
    {
347
        $content = '';
348
        $lang = $this->getLanguageService();
349
350
        $view = GeneralUtility::makeInstance(StandaloneView::class);
351
        $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Templates/InfoBox.html'));
352
353
        // If page is a folder
354
        if ($this->pageinfo['doktype'] == PageRepository::DOKTYPE_SYSFOLDER) {
355
            $moduleLoader = GeneralUtility::makeInstance(ModuleLoader::class);
356
            $moduleLoader->load($GLOBALS['TBE_MODULES']);
357
            $modules = $moduleLoader->modules;
358
            if (is_array($modules['web']['sub']['list'])) {
359
                $title = $lang->getLL('goToListModule');
360
                $message = '<p>' . $lang->getLL('goToListModuleMessage') . '</p>';
361
                $message .= '<a class="btn btn-info" href="javascript:top.goToModule(\'web_list\');">' . $lang->getLL('goToListModule') . '</a>';
362
                $view->assignMultiple([
363
                    'title' => $title,
364
                    'message' => $message,
365
                    'state' => InfoboxViewHelper::STATE_INFO
366
                ]);
367
                $content .= $view->render();
368
            }
369
        } elseif ($this->pageinfo['doktype'] === PageRepository::DOKTYPE_SHORTCUT) {
370
            $shortcutMode = (int)$this->pageinfo['shortcut_mode'];
371
            $targetPage = [];
372
            $message = '';
373
            $state = InfoboxViewHelper::STATE_ERROR;
374
375
            if ($shortcutMode || $this->pageinfo['shortcut']) {
376
                switch ($shortcutMode) {
377
                    case PageRepository::SHORTCUT_MODE_NONE:
378
                        $targetPage = $this->getTargetPageIfVisible($this->pageRepository->getPage($this->pageinfo['shortcut']));
379
                        $message .= $targetPage === [] ? $lang->getLL('pageIsMisconfiguredOrNotAccessibleInternalLinkMessage') : '';
380
                        break;
381
                    case PageRepository::SHORTCUT_MODE_FIRST_SUBPAGE:
382
                        $menuOfPages = $this->pageRepository->getMenu($this->pageinfo['uid'], '*', 'sorting', 'AND hidden = 0');
383
                        $targetPage = reset($menuOfPages) ?: [];
384
                        $message .= $targetPage === [] ? $lang->getLL('pageIsMisconfiguredFirstSubpageMessage') : '';
385
                        break;
386
                    case PageRepository::SHORTCUT_MODE_PARENT_PAGE:
387
                        $targetPage = $this->getTargetPageIfVisible($this->pageRepository->getPage($this->pageinfo['pid']));
388
                        $message .= $targetPage === [] ? $lang->getLL('pageIsMisconfiguredParentPageMessage') : '';
389
                        break;
390
                    case PageRepository::SHORTCUT_MODE_RANDOM_SUBPAGE:
391
                        $possibleTargetPages = $this->pageRepository->getMenu($this->pageinfo['uid'], '*', 'sorting', 'AND hidden = 0');
392
                        if ($possibleTargetPages === []) {
393
                            $message .= $lang->getLL('pageIsMisconfiguredOrNotAccessibleRandomInternalLinkMessage');
394
                            break;
395
                        }
396
                        $message = $lang->getLL('pageIsRandomInternalLinkMessage');
397
                        $state = InfoboxViewHelper::STATE_INFO;
398
                        break;
399
                }
400
                $message = htmlspecialchars($message);
401
                if ($targetPage !== [] && $shortcutMode !== PageRepository::SHORTCUT_MODE_RANDOM_SUBPAGE) {
402
                    $linkToPid = GeneralUtility::linkThisScript(['id' => $targetPage['uid']]);
403
                    $path = BackendUtility::getRecordPath($targetPage['uid'], $this->getBackendUser()->getPagePermsClause(Permission::PAGE_SHOW), 1000);
404
                    $linkedPath = '<a href="' . htmlspecialchars($linkToPid) . '">' . htmlspecialchars($path) . '</a>';
0 ignored issues
show
Bug introduced by
It seems like $path can also be of type array<integer,string>; however, parameter $string of htmlspecialchars() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

404
                    $linkedPath = '<a href="' . htmlspecialchars($linkToPid) . '">' . htmlspecialchars(/** @scrutinizer ignore-type */ $path) . '</a>';
Loading history...
405
                    $message .= sprintf(htmlspecialchars($lang->getLL('pageIsInternalLinkMessage')), $linkedPath);
406
                    $message .= ' (' . htmlspecialchars($lang->sL(BackendUtility::getLabelFromItemlist('pages', 'shortcut_mode', (string)$shortcutMode))) . ')';
407
                    $state = InfoboxViewHelper::STATE_INFO;
408
                }
409
            } else {
410
                $message = htmlspecialchars($lang->getLL('pageIsMisconfiguredInternalLinkMessage'));
411
                $state = InfoboxViewHelper::STATE_ERROR;
412
            }
413
414
            $view->assignMultiple([
415
                'title' => $this->pageinfo['title'],
416
                'message' => $message,
417
                'state' => $state
418
            ]);
419
            $content .= $view->render();
420
        } elseif ($this->pageinfo['doktype'] === PageRepository::DOKTYPE_LINK) {
421
            if (empty($this->pageinfo['url'])) {
422
                $view->assignMultiple([
423
                    'title' => $this->pageinfo['title'],
424
                    'message' => $lang->getLL('pageIsMisconfiguredExternalLinkMessage'),
425
                    'state' => InfoboxViewHelper::STATE_ERROR
426
                ]);
427
                $content .= $view->render();
428
            } else {
429
                $externalUrl = $this->pageRepository->getExtURL($this->pageinfo);
0 ignored issues
show
Bug introduced by
It seems like $this->pageinfo can also be of type boolean; however, parameter $pagerow of TYPO3\CMS\Core\Domain\Re...Repository::getExtURL() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

429
                $externalUrl = $this->pageRepository->getExtURL(/** @scrutinizer ignore-type */ $this->pageinfo);
Loading history...
430
                if (is_string($externalUrl)) {
431
                    $externalUrl = htmlspecialchars($externalUrl);
432
                    $externalUrlHtml = '<a href="' . $externalUrl . '" target="_blank" rel="noreferrer">' . $externalUrl . '</a>';
433
                    $view->assignMultiple([
434
                        'title' => $this->pageinfo['title'],
435
                        'message' => sprintf($lang->getLL('pageIsExternalLinkMessage'), $externalUrlHtml),
436
                        'state' => InfoboxViewHelper::STATE_INFO
437
                    ]);
438
                    $content .= $view->render();
439
                }
440
            }
441
        }
442
        // If content from different pid is displayed
443
        if ($this->pageinfo['content_from_pid']) {
444
            $contentPage = (array)BackendUtility::getRecord('pages', (int)$this->pageinfo['content_from_pid']);
445
            $linkToPid = GeneralUtility::linkThisScript(['id' => $this->pageinfo['content_from_pid']]);
446
            $title = BackendUtility::getRecordTitle('pages', $contentPage);
447
            $link = '<a href="' . htmlspecialchars($linkToPid) . '">' . htmlspecialchars($title) . ' (PID ' . (int)$this->pageinfo['content_from_pid'] . ')</a>';
448
            $message = sprintf($lang->getLL('content_from_pid_title'), $link);
449
            $view->assignMultiple([
450
                'title' => $title,
451
                'message' => $message,
452
                'state' => InfoboxViewHelper::STATE_INFO
453
            ]);
454
            $content .= $view->render();
455
        } else {
456
            $links = $this->getPageLinksWhereContentIsAlsoShownOn($this->pageinfo['uid']);
457
            if (!empty($links)) {
458
                $message = sprintf($lang->getLL('content_on_pid_title'), $links);
459
                $view->assignMultiple([
460
                    'title' => '',
461
                    'message' => $message,
462
                    'state' => InfoboxViewHelper::STATE_INFO
463
                ]);
464
                $content .= $view->render();
465
            }
466
        }
467
        return $content;
468
    }
469
470
    /**
471
     * Get all pages with links where the content of a page $pageId is also shown on
472
     *
473
     * @param int $pageId
474
     * @return string
475
     */
476
    protected function getPageLinksWhereContentIsAlsoShownOn($pageId): string
477
    {
478
        $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages');
479
        $queryBuilder->getRestrictions()->removeAll();
480
        $queryBuilder->getRestrictions()->add(GeneralUtility::makeInstance(DeletedRestriction::class));
481
        $queryBuilder
482
            ->select('*')
483
            ->from('pages')
484
            ->where($queryBuilder->expr()->eq('content_from_pid', $queryBuilder->createNamedParameter($pageId, \PDO::PARAM_INT)));
485
486
        $links = [];
487
        $rows = $queryBuilder->execute()->fetchAll();
488
        if (!empty($rows)) {
489
            foreach ($rows as $row) {
490
                $linkToPid = GeneralUtility::linkThisScript(['id' => $row['uid']]);
491
                $title = BackendUtility::getRecordTitle('pages', $row);
492
                $link = '<a href="' . htmlspecialchars($linkToPid) . '">' . htmlspecialchars($title) . ' (PID ' . (int)$row['uid'] . ')</a>';
493
                $links[] = $link;
494
            }
495
        }
496
        return implode(', ', $links);
497
    }
498
499
    /**
500
     * @return string $title
501
     */
502
    protected function getLocalizedPageTitle(): string
503
    {
504
        if ($this->current_sys_language > 0) {
505
            $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
506
                ->getQueryBuilderForTable('pages');
507
            $queryBuilder->getRestrictions()
508
                ->removeAll()
509
                ->add(GeneralUtility::makeInstance(DeletedRestriction::class))
510
                ->add(GeneralUtility::makeInstance(WorkspaceRestriction::class, (int)$this->getBackendUser()->workspace));
511
            $localizedPage = $queryBuilder
512
                ->select('*')
513
                ->from('pages')
514
                ->where(
515
                    $queryBuilder->expr()->eq(
516
                        $GLOBALS['TCA']['pages']['ctrl']['transOrigPointerField'],
517
                        $queryBuilder->createNamedParameter($this->id, \PDO::PARAM_INT)
518
                    ),
519
                    $queryBuilder->expr()->eq(
520
                        $GLOBALS['TCA']['pages']['ctrl']['languageField'],
521
                        $queryBuilder->createNamedParameter($this->current_sys_language, \PDO::PARAM_INT)
522
                    )
523
                )
524
                ->setMaxResults(1)
525
                ->execute()
526
                ->fetch();
527
            BackendUtility::workspaceOL('pages', $localizedPage);
528
            return $localizedPage['title'];
529
        }
530
        return $this->pageinfo['title'];
531
    }
532
533
    /**
534
     * Main function.
535
     * Creates some general objects and calls other functions for the main rendering of module content.
536
     *
537
     * @param ServerRequestInterface $request
538
     */
539
    protected function main(ServerRequestInterface $request): void
540
    {
541
        $content = '';
542
        // Access check...
543
        // The page will show only if there is a valid page and if this page may be viewed by the user
544
        if ($this->id && is_array($this->pageinfo)) {
545
            $this->moduleTemplate->getDocHeaderComponent()->setMetaInformation($this->pageinfo);
546
547
            $this->moduleTemplate->addJavaScriptCode('mainJsFunctions', '
548
                if (top.fsMod) {
549
                    top.fsMod.recentIds["web"] = ' . (int)$this->id . ';
550
                    top.fsMod.navFrameHighlightedID["web"] = top.fsMod.currentBank + "_" + ' . (int)$this->id . ';
551
                }
552
                function deleteRecord(table,id,url) {   //
553
                    window.location.href = ' . GeneralUtility::quoteJSvalue((string)$this->uriBuilder->buildUriFromRoute('tce_db') . '&cmd[')
554
                                            . ' + table + "][" + id + "][delete]=1&redirect=" + encodeURIComponent(url);
555
                    return false;
556
                }
557
            ');
558
559
            if ($this->context instanceof PageLayoutContext) {
560
                $backendLayout = $this->context->getBackendLayout();
561
562
                // Find backend layout / columns
563
                if (!empty($backendLayout->getColumnPositionNumbers())) {
564
                    $this->colPosList = implode(',', $backendLayout->getColumnPositionNumbers());
565
                }
566
                // Removing duplicates, if any
567
                $this->colPosList = array_unique(GeneralUtility::intExplode(',', $this->colPosList));
0 ignored issues
show
Documentation Bug introduced by
It seems like array_unique(TYPO3\CMS\C...,', $this->colPosList)) of type array is incompatible with the declared type string of property $colPosList.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
568
                // Accessible columns
569
                if (isset($this->modSharedTSconfig['properties']['colPos_list']) && trim($this->modSharedTSconfig['properties']['colPos_list']) !== '') {
570
                    $this->activeColPosList = array_unique(GeneralUtility::intExplode(',', trim($this->modSharedTSconfig['properties']['colPos_list'])));
0 ignored issues
show
Documentation Bug introduced by
It seems like array_unique(TYPO3\CMS\C...ies']['colPos_list']))) of type array is incompatible with the declared type string of property $activeColPosList.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
571
                    // Match with the list which is present in the colPosList for the current page
572
                    if (!empty($this->colPosList) && !empty($this->activeColPosList)) {
573
                        $this->activeColPosList = array_unique(array_intersect(
574
                            $this->activeColPosList,
575
                            $this->colPosList
576
                        ));
577
                    }
578
                } else {
579
                    $this->activeColPosList = $this->colPosList;
580
                }
581
                $this->activeColPosList = implode(',', $this->activeColPosList);
582
                $this->colPosList = implode(',', $this->colPosList);
583
            }
584
585
            $content .= $this->getHeaderFlashMessagesForCurrentPid();
586
587
            // Render the primary module content:
588
            $content .= '<form action="' . htmlspecialchars((string)$this->uriBuilder->buildUriFromRoute($this->moduleName, ['id' => $this->id])) . '" id="PageLayoutController" method="post">';
589
            // Page title
590
            $content .= '<h1 class="' . ($this->isPageEditable($this->current_sys_language) ? 't3js-title-inlineedit' : '') . '">' . htmlspecialchars($this->getLocalizedPageTitle()) . '</h1>';
591
            // All other listings
592
            $content .= $this->renderContent();
593
            $content .= '</form>';
594
            // Setting up the buttons for the docheader
595
            $this->makeButtons($request);
596
597
            // Create LanguageMenu
598
            $this->makeLanguageMenu();
599
        } else {
600
            $this->moduleTemplate->addJavaScriptCode(
601
                'mainJsFunctions',
602
                'if (top.fsMod) top.fsMod.recentIds["web"] = ' . (int)$this->id . ';'
603
            );
604
            $content .= '<h1>' . htmlspecialchars($GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']) . '</h1>';
605
            $view = GeneralUtility::makeInstance(StandaloneView::class);
606
            $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Templates/InfoBox.html'));
607
            $view->assignMultiple([
608
                'title' => $this->getLanguageService()->getLL('clickAPage_header'),
609
                'message' => $this->getLanguageService()->getLL('clickAPage_content'),
610
                'state' => InfoboxViewHelper::STATE_INFO
611
            ]);
612
            $content .= $view->render();
613
        }
614
        // Set content
615
        $this->moduleTemplate->setContent($content);
616
    }
617
618
    /**
619
     * Rendering content
620
     *
621
     * @return string
622
     */
623
    protected function renderContent(): string
624
    {
625
        $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/ContextMenu');
626
        $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/Tooltip');
627
        $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/Localization');
628
        $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/LayoutModule/DragDrop');
629
        $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/Modal');
630
        $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/LayoutModule/Paste');
631
        $this->pageRenderer->addInlineLanguageLabelFile('EXT:backend/Resources/Private/Language/locallang_layout.xlf');
632
633
        $tableOutput = '';
634
        $numberOfHiddenElements = 0;
635
636
        if ($this->context instanceof PageLayoutContext) {
637
            // Context may not be set, which happens if the page module is viewed by a user with no access to the
638
            // current page, or if the ID parameter is malformed. In this case we do not resolve any backend layout
639
            // or other page structure information and we do not render any "table output" for the module.
640
            $backendLayout = $this->context->getBackendLayout();
0 ignored issues
show
Unused Code introduced by
The assignment to $backendLayout is dead and can be removed.
Loading history...
641
642
            $configuration = $this->context->getDrawingConfiguration();
643
            $configuration->setDefaultLanguageBinding(!empty($this->modTSconfig['properties']['defLangBinding']));
644
            $configuration->setActiveColumns(GeneralUtility::trimExplode(',', $this->activeColPosList));
645
            $configuration->setShowHidden((bool)$this->MOD_SETTINGS['tt_content_showHidden']);
646
            $configuration->setLanguageColumns($this->MOD_MENU['language']);
647
            $configuration->setShowNewContentWizard(empty($this->modTSconfig['properties']['disableNewContentElementWizard']));
648
            $configuration->setSelectedLanguageId((int)$this->MOD_SETTINGS['language']);
649
            if ($this->MOD_SETTINGS['function'] == 2) {
650
                $configuration->setLanguageMode(true);
651
            }
652
653
            $numberOfHiddenElements = $this->getNumberOfHiddenElements($configuration->getLanguageColumns());
654
655
            $pageLayoutDrawer = $this->context->getBackendLayoutRenderer();
656
657
            $pageActionsCallback = null;
658
            if ($this->context->isPageEditable()) {
659
                $languageOverlayId = 0;
660
                $pageLocalizationRecord = BackendUtility::getRecordLocalization('pages', $this->id, (int)$this->current_sys_language);
661
                if (is_array($pageLocalizationRecord)) {
662
                    $pageLocalizationRecord = reset($pageLocalizationRecord);
663
                }
664
                if (!empty($pageLocalizationRecord['uid'])) {
665
                    $languageOverlayId = $pageLocalizationRecord['uid'];
666
                }
667
                $pageActionsCallback = 'function(PageActions) {
668
                    PageActions.setPageId(' . (int)$this->id . ');
669
                    PageActions.setLanguageOverlayId(' . $languageOverlayId . ');
670
                }';
671
            }
672
            $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/PageActions', $pageActionsCallback);
673
            $tableOutput = $pageLayoutDrawer->drawContent();
674
        }
675
676
        if ($this->getBackendUser()->check('tables_select', 'tt_content') && $numberOfHiddenElements > 0) {
677
            // Toggle hidden ContentElements
678
            $tableOutput .= '
679
                <div class="form-check">
680
                    <input type="checkbox" id="checkTt_content_showHidden" class="form-check-input" name="SET[tt_content_showHidden]" value="1" ' . ($this->MOD_SETTINGS['tt_content_showHidden'] ? 'checked="checked"' : '') . ' />
681
                    <label class="form-check-label" for="checkTt_content_showHidden">
682
                        ' . htmlspecialchars($this->getLanguageService()->getLL('hiddenCE')) . ' (<span class="t3js-hidden-counter">' . $numberOfHiddenElements . '</span>)
683
                    </label>
684
                </div>';
685
        }
686
687
        // Init the content
688
        $content = '';
689
        // Additional header content
690
        foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/db_layout.php']['drawHeaderHook'] ?? [] as $hook) {
691
            $params = [];
692
            $content .= GeneralUtility::callUserFunction($hook, $params, $this);
693
        }
694
        $content .= $tableOutput;
695
696
        // Additional footer content
697
        foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/db_layout.php']['drawFooterHook'] ?? [] as $hook) {
698
            $params = [];
699
            $content .= GeneralUtility::callUserFunction($hook, $params, $this);
700
        }
701
        return $content;
702
    }
703
704
    /***************************
705
     *
706
     * Sub-content functions, rendering specific parts of the module content.
707
     *
708
     ***************************/
709
    /**
710
     * This creates the buttons for the modules
711
     * @param ServerRequestInterface $request
712
     */
713
    protected function makeButtons(ServerRequestInterface $request): void
714
    {
715
        // Add CSH (Context Sensitive Help) icon to tool bar
716
        $contextSensitiveHelpButton = $this->buttonBar->makeHelpButton()
717
            ->setModuleName('_MOD_' . $this->moduleName)
718
            ->setFieldName('columns_' . $this->MOD_SETTINGS['function']);
719
        $this->buttonBar->addButton($contextSensitiveHelpButton);
720
        $lang = $this->getLanguageService();
721
        // View page
722
        $pageTsConfig = BackendUtility::getPagesTSconfig($this->id);
723
        // Exclude sysfolders, spacers and recycler by default
724
        $excludeDokTypes = [
725
            PageRepository::DOKTYPE_RECYCLER,
726
            PageRepository::DOKTYPE_SYSFOLDER,
727
            PageRepository::DOKTYPE_SPACER
728
        ];
729
        // Custom override of values
730
        if (isset($pageTsConfig['TCEMAIN.']['preview.']['disableButtonForDokType'])) {
731
            $excludeDokTypes = GeneralUtility::intExplode(
732
                ',',
733
                $pageTsConfig['TCEMAIN.']['preview.']['disableButtonForDokType'],
734
                true
735
            );
736
        }
737
738
        if (
739
            !in_array((int)$this->pageinfo['doktype'], $excludeDokTypes, true)
740
            && !VersionState::cast($this->pageinfo['t3ver_state'])->equals(VersionState::DELETE_PLACEHOLDER)
741
        ) {
742
            $languageParameter = $this->current_sys_language ? ('&L=' . $this->current_sys_language) : '';
743
            $previewDataAttributes = PreviewUriBuilder::create((int)$this->pageinfo['uid'])
744
                ->withRootLine(BackendUtility::BEgetRootLine($this->pageinfo['uid']))
745
                ->withAdditionalQueryParameters($languageParameter)
746
                ->buildDispatcherDataAttributes();
747
            $viewButton = $this->buttonBar->makeLinkButton()
748
                ->setDataAttributes($previewDataAttributes ?? [])
749
                ->setTitle($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.showPage'))
750
                ->setIcon($this->iconFactory->getIcon('actions-view-page', Icon::SIZE_SMALL))
751
                ->setHref('#');
752
753
            $this->buttonBar->addButton($viewButton, ButtonBar::BUTTON_POSITION_LEFT, 3);
754
        }
755
        // Shortcut
756
        $shortcutButton = $this->buttonBar->makeShortcutButton()
757
            ->setRouteIdentifier($this->moduleName)
758
            ->setDisplayName($this->getShortcutTitle())
759
            ->setArguments([
760
                'id' => (int)$this->id,
761
                'SET' => [
762
                    'tt_content_showHidden' => (bool)$this->MOD_SETTINGS['tt_content_showHidden'],
763
                    'function' => (int)$this->MOD_SETTINGS['function'],
764
                    'language' => (int)$this->current_sys_language,
765
                ]
766
            ]);
767
        $this->buttonBar->addButton($shortcutButton);
768
769
        // Cache
770
        $clearCacheButton = $this->buttonBar->makeLinkButton()
771
            ->setHref('#')
772
            ->setDataAttributes(['id' => $this->pageinfo['uid']])
773
            ->setClasses('t3js-clear-page-cache')
774
            ->setTitle($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.clear_cache'))
775
            ->setIcon($this->iconFactory->getIcon('actions-system-cache-clear', Icon::SIZE_SMALL));
776
        $this->buttonBar->addButton($clearCacheButton, ButtonBar::BUTTON_POSITION_RIGHT, 1);
777
778
        // Edit page properties and page language overlay icons
779
        if ($this->isPageEditable(0)) {
780
            /** @var \TYPO3\CMS\Core\Http\NormalizedParams */
781
            $normalizedParams = $request->getAttribute('normalizedParams');
782
            // Edit localized pages only when one specific language is selected
783
            if ($this->MOD_SETTINGS['function'] == 1 && $this->current_sys_language > 0) {
784
                $localizationParentField = $GLOBALS['TCA']['pages']['ctrl']['transOrigPointerField'];
785
                $languageField = $GLOBALS['TCA']['pages']['ctrl']['languageField'];
786
                $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
787
                    ->getQueryBuilderForTable('pages');
788
                $queryBuilder->getRestrictions()
789
                    ->removeAll()
790
                    ->add(GeneralUtility::makeInstance(DeletedRestriction::class))
791
                    ->add(GeneralUtility::makeInstance(WorkspaceRestriction::class, (int)$this->getBackendUser()->workspace));
792
                $overlayRecord = $queryBuilder
793
                    ->select('uid')
794
                    ->from('pages')
795
                    ->where(
796
                        $queryBuilder->expr()->eq(
797
                            $localizationParentField,
798
                            $queryBuilder->createNamedParameter($this->id, \PDO::PARAM_INT)
799
                        ),
800
                        $queryBuilder->expr()->eq(
801
                            $languageField,
802
                            $queryBuilder->createNamedParameter($this->current_sys_language, \PDO::PARAM_INT)
803
                        )
804
                    )
805
                    ->setMaxResults(1)
806
                    ->execute()
807
                    ->fetch();
808
                BackendUtility::workspaceOL('pages', $overlayRecord, (int)$this->getBackendUser()->workspace);
809
                // Edit button
810
                $urlParameters = [
811
                    'edit' => [
812
                        'pages' => [
813
                            $overlayRecord['uid'] => 'edit'
814
                        ]
815
                    ],
816
                    'returnUrl' => $normalizedParams->getRequestUri(),
817
                ];
818
819
                $url = (string)$this->uriBuilder->buildUriFromRoute('record_edit', $urlParameters);
820
                $editLanguageButton = $this->buttonBar->makeLinkButton()
821
                    ->setHref($url)
822
                    ->setTitle($lang->getLL('editPageLanguageOverlayProperties'))
823
                    ->setIcon($this->iconFactory->getIcon('mimetypes-x-content-page-language-overlay', Icon::SIZE_SMALL));
824
                $this->buttonBar->addButton($editLanguageButton, ButtonBar::BUTTON_POSITION_LEFT, 3);
825
            }
826
            $urlParameters = [
827
                'edit' => [
828
                    'pages' => [
829
                        $this->id => 'edit'
830
                    ]
831
                ],
832
                'returnUrl' => $normalizedParams->getRequestUri(),
833
            ];
834
            $url = (string)$this->uriBuilder->buildUriFromRoute('record_edit', $urlParameters);
835
            $editPageButton = $this->buttonBar->makeLinkButton()
836
                ->setHref($url)
837
                ->setTitle($lang->getLL('editPageProperties'))
838
                ->setIcon($this->iconFactory->getIcon('actions-page-open', Icon::SIZE_SMALL));
839
            $this->buttonBar->addButton($editPageButton, ButtonBar::BUTTON_POSITION_LEFT, 3);
840
        }
841
    }
842
843
    /*******************************
844
     *
845
     * Other functions
846
     *
847
     ******************************/
848
    /**
849
     * Returns the number of hidden elements (including those hidden by start/end times)
850
     * on the current page (for the current sys_language)
851
     *
852
     * @param array $languageColumns
853
     * @return int
854
     */
855
    protected function getNumberOfHiddenElements(array $languageColumns): int
856
    {
857
        $andWhere = [];
858
        $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tt_content');
859
        $queryBuilder->getRestrictions()
860
            ->removeAll()
861
            ->add(GeneralUtility::makeInstance(DeletedRestriction::class))
862
            ->add(GeneralUtility::makeInstance(WorkspaceRestriction::class, (int)$this->getBackendUser()->workspace));
863
864
        $queryBuilder
865
            ->count('uid')
866
            ->from('tt_content')
867
            ->where(
868
                $queryBuilder->expr()->eq(
869
                    'pid',
870
                    $queryBuilder->createNamedParameter($this->id, \PDO::PARAM_INT)
871
                )
872
            );
873
874
        if (!empty($languageColumns)) {
875
            // Multi-language view is active
876
            if ($this->current_sys_language > 0) {
877
                $queryBuilder->andWhere(
878
                    $queryBuilder->expr()->in(
879
                        'sys_language_uid',
880
                        [0, $queryBuilder->createNamedParameter($this->current_sys_language, \PDO::PARAM_INT)]
881
                    )
882
                );
883
            }
884
        } else {
885
            $queryBuilder->andWhere(
886
                $queryBuilder->expr()->eq(
887
                    'sys_language_uid',
888
                    $queryBuilder->createNamedParameter($this->current_sys_language, \PDO::PARAM_INT)
889
                )
890
            );
891
        }
892
893
        if (!empty($GLOBALS['TCA']['tt_content']['ctrl']['enablecolumns']['disabled'])) {
894
            $andWhere[] = $queryBuilder->expr()->neq(
895
                'hidden',
896
                $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
897
            );
898
        }
899
900
        if (!empty($GLOBALS['TCA']['tt_content']['ctrl']['enablecolumns']['starttime'])) {
901
            $andWhere[] = $queryBuilder->expr()->andX(
902
                $queryBuilder->expr()->neq(
903
                    'starttime',
904
                    $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
905
                ),
906
                $queryBuilder->expr()->gt(
907
                    'starttime',
908
                    $queryBuilder->createNamedParameter($GLOBALS['SIM_ACCESS_TIME'], \PDO::PARAM_INT)
909
                )
910
            );
911
        }
912
913
        if (!empty($GLOBALS['TCA']['tt_content']['ctrl']['enablecolumns']['endtime'])) {
914
            $andWhere[] = $queryBuilder->expr()->andX(
915
                $queryBuilder->expr()->neq(
916
                    'endtime',
917
                    $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
918
                ),
919
                $queryBuilder->expr()->lte(
920
                    'endtime',
921
                    $queryBuilder->createNamedParameter($GLOBALS['SIM_ACCESS_TIME'], \PDO::PARAM_INT)
922
                )
923
            );
924
        }
925
926
        if (!empty($andWhere)) {
927
            $queryBuilder->andWhere(
928
                $queryBuilder->expr()->orX(...$andWhere)
929
            );
930
        }
931
932
        $count = $queryBuilder
933
            ->execute()
934
            ->fetchColumn(0);
935
936
        return (int)$count;
937
    }
938
939
    /**
940
     * Check if page can be edited by current user
941
     *
942
     * @param int $languageId
943
     * @return bool
944
     */
945
    protected function isPageEditable(int $languageId): bool
946
    {
947
        if ($this->getBackendUser()->isAdmin()) {
948
            return true;
949
        }
950
951
        return !$this->pageinfo['editlock']
952
            && $this->getBackendUser()->doesUserHaveAccess($this->pageinfo, Permission::PAGE_EDIT)
0 ignored issues
show
Bug introduced by
It seems like $this->pageinfo can also be of type boolean; however, parameter $row of TYPO3\CMS\Core\Authentic...n::doesUserHaveAccess() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

952
            && $this->getBackendUser()->doesUserHaveAccess(/** @scrutinizer ignore-type */ $this->pageinfo, Permission::PAGE_EDIT)
Loading history...
953
            && $this->getBackendUser()->checkLanguageAccess($languageId);
954
    }
955
956
    /**
957
     * Check if content can be edited by current user
958
     *
959
     * @param int $languageId
960
     * @return bool
961
     */
962
    protected function isContentEditable(int $languageId): bool
963
    {
964
        if ($this->getBackendUser()->isAdmin()) {
965
            return true;
966
        }
967
968
        return !$this->pageinfo['editlock']
969
            && $this->getBackendUser()->doesUserHaveAccess($this->pageinfo, Permission::CONTENT_EDIT)
0 ignored issues
show
Bug introduced by
It seems like $this->pageinfo can also be of type boolean; however, parameter $row of TYPO3\CMS\Core\Authentic...n::doesUserHaveAccess() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

969
            && $this->getBackendUser()->doesUserHaveAccess(/** @scrutinizer ignore-type */ $this->pageinfo, Permission::CONTENT_EDIT)
Loading history...
970
            && $this->getBackendUser()->checkLanguageAccess($languageId);
971
    }
972
973
    /**
974
     * Returns LanguageService
975
     *
976
     * @return LanguageService
977
     */
978
    protected function getLanguageService(): LanguageService
979
    {
980
        return $GLOBALS['LANG'];
981
    }
982
983
    /**
984
     * Returns the current BE user.
985
     *
986
     * @return BackendUserAuthentication
987
     */
988
    protected function getBackendUser(): BackendUserAuthentication
989
    {
990
        return $GLOBALS['BE_USER'];
991
    }
992
993
    /**
994
     * Make the LanguageMenu
995
     */
996
    protected function makeLanguageMenu(): void
997
    {
998
        if (count($this->MOD_MENU['language']) > 1) {
999
            $languageMenu = $this->moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->makeMenu();
1000
            $languageMenu->setIdentifier('languageMenu');
1001
            foreach ($this->MOD_MENU['language'] as $key => $language) {
1002
                $menuItem = $languageMenu
1003
                    ->makeMenuItem()
1004
                    ->setTitle($language)
1005
                    ->setHref((string)$this->uriBuilder->buildUriFromRoute($this->moduleName) . '&id=' . $this->id . '&SET[language]=' . $key);
1006
                if ((int)$this->current_sys_language === $key) {
1007
                    $menuItem->setActive(true);
1008
                }
1009
                $languageMenu->addMenuItem($menuItem);
1010
            }
1011
            $this->moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->addMenu($languageMenu);
1012
        }
1013
    }
1014
1015
    /**
1016
     * Returns the target page if visible
1017
     *
1018
     * @param array $targetPage
1019
     *
1020
     * @return array
1021
     */
1022
    protected function getTargetPageIfVisible(array $targetPage): array
1023
    {
1024
        return !(bool)($targetPage['hidden'] ?? false) ? $targetPage : [];
1025
    }
1026
1027
    /**
1028
     * Returns the shortcut title for the current page
1029
     *
1030
     * @return string
1031
     */
1032
    protected function getShortcutTitle(): string
1033
    {
1034
        return sprintf(
1035
            '%s: %s [%d]',
1036
            $this->getLanguageService()->sL('LLL:EXT:backend/Resources/Private/Language/locallang_mod.xlf:mlang_labels_tablabel'),
1037
            BackendUtility::getRecordTitle('pages', (array)$this->pageinfo),
1038
            $this->id
1039
        );
1040
    }
1041
}
1042