Passed
Push — master ( c38fc4...4e12b6 )
by
unknown
13:55
created

getHeaderFlashMessagesForCurrentPid()   F

Complexity

Conditions 22
Paths 75

Size

Total Lines 124
Code Lines 100

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 22
eloc 100
c 0
b 0
f 0
nc 75
nop 0
dl 0
loc 124
rs 3.3333

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" data-dispatch-action="TYPO3.ModuleMenu.showModule" data-dispatch-args-list="web_list">'
362
                    . $lang->getLL('goToListModule') . '</a>';
363
                $view->assignMultiple([
364
                    'title' => $title,
365
                    'message' => $message,
366
                    'state' => InfoboxViewHelper::STATE_INFO
367
                ]);
368
                $content .= $view->render();
369
            }
370
        } elseif ($this->pageinfo['doktype'] === PageRepository::DOKTYPE_SHORTCUT) {
371
            $shortcutMode = (int)$this->pageinfo['shortcut_mode'];
372
            $targetPage = [];
373
            $message = '';
374
            $state = InfoboxViewHelper::STATE_ERROR;
375
376
            if ($shortcutMode || $this->pageinfo['shortcut']) {
377
                switch ($shortcutMode) {
378
                    case PageRepository::SHORTCUT_MODE_NONE:
379
                        $targetPage = $this->getTargetPageIfVisible($this->pageRepository->getPage($this->pageinfo['shortcut']));
380
                        $message .= $targetPage === [] ? $lang->getLL('pageIsMisconfiguredOrNotAccessibleInternalLinkMessage') : '';
381
                        break;
382
                    case PageRepository::SHORTCUT_MODE_FIRST_SUBPAGE:
383
                        $menuOfPages = $this->pageRepository->getMenu($this->pageinfo['uid'], '*', 'sorting', 'AND hidden = 0');
384
                        $targetPage = reset($menuOfPages) ?: [];
385
                        $message .= $targetPage === [] ? $lang->getLL('pageIsMisconfiguredFirstSubpageMessage') : '';
386
                        break;
387
                    case PageRepository::SHORTCUT_MODE_PARENT_PAGE:
388
                        $targetPage = $this->getTargetPageIfVisible($this->pageRepository->getPage($this->pageinfo['pid']));
389
                        $message .= $targetPage === [] ? $lang->getLL('pageIsMisconfiguredParentPageMessage') : '';
390
                        break;
391
                    case PageRepository::SHORTCUT_MODE_RANDOM_SUBPAGE:
392
                        $possibleTargetPages = $this->pageRepository->getMenu($this->pageinfo['uid'], '*', 'sorting', 'AND hidden = 0');
393
                        if ($possibleTargetPages === []) {
394
                            $message .= $lang->getLL('pageIsMisconfiguredOrNotAccessibleRandomInternalLinkMessage');
395
                            break;
396
                        }
397
                        $message = $lang->getLL('pageIsRandomInternalLinkMessage');
398
                        $state = InfoboxViewHelper::STATE_INFO;
399
                        break;
400
                }
401
                $message = htmlspecialchars($message);
402
                if ($targetPage !== [] && $shortcutMode !== PageRepository::SHORTCUT_MODE_RANDOM_SUBPAGE) {
403
                    $linkToPid = GeneralUtility::linkThisScript(['id' => $targetPage['uid']]);
404
                    $path = BackendUtility::getRecordPath($targetPage['uid'], $this->getBackendUser()->getPagePermsClause(Permission::PAGE_SHOW), 1000);
405
                    $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

405
                    $linkedPath = '<a href="' . htmlspecialchars($linkToPid) . '">' . htmlspecialchars(/** @scrutinizer ignore-type */ $path) . '</a>';
Loading history...
406
                    $message .= sprintf(htmlspecialchars($lang->getLL('pageIsInternalLinkMessage')), $linkedPath);
407
                    $message .= ' (' . htmlspecialchars($lang->sL(BackendUtility::getLabelFromItemlist('pages', 'shortcut_mode', (string)$shortcutMode))) . ')';
408
                    $state = InfoboxViewHelper::STATE_INFO;
409
                }
410
            } else {
411
                $message = htmlspecialchars($lang->getLL('pageIsMisconfiguredInternalLinkMessage'));
412
                $state = InfoboxViewHelper::STATE_ERROR;
413
            }
414
415
            $view->assignMultiple([
416
                'title' => $this->pageinfo['title'],
417
                'message' => $message,
418
                'state' => $state
419
            ]);
420
            $content .= $view->render();
421
        } elseif ($this->pageinfo['doktype'] === PageRepository::DOKTYPE_LINK) {
422
            if (empty($this->pageinfo['url'])) {
423
                $view->assignMultiple([
424
                    'title' => $this->pageinfo['title'],
425
                    'message' => $lang->getLL('pageIsMisconfiguredExternalLinkMessage'),
426
                    'state' => InfoboxViewHelper::STATE_ERROR
427
                ]);
428
                $content .= $view->render();
429
            } else {
430
                $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

430
                $externalUrl = $this->pageRepository->getExtURL(/** @scrutinizer ignore-type */ $this->pageinfo);
Loading history...
431
                if (is_string($externalUrl)) {
432
                    $externalUrl = htmlspecialchars($externalUrl);
433
                    $externalUrlHtml = '<a href="' . $externalUrl . '" target="_blank" rel="noreferrer">' . $externalUrl . '</a>';
434
                    $view->assignMultiple([
435
                        'title' => $this->pageinfo['title'],
436
                        'message' => sprintf($lang->getLL('pageIsExternalLinkMessage'), $externalUrlHtml),
437
                        'state' => InfoboxViewHelper::STATE_INFO
438
                    ]);
439
                    $content .= $view->render();
440
                }
441
            }
442
        }
443
        // If content from different pid is displayed
444
        if ($this->pageinfo['content_from_pid']) {
445
            $contentPage = (array)BackendUtility::getRecord('pages', (int)$this->pageinfo['content_from_pid']);
446
            $linkToPid = GeneralUtility::linkThisScript(['id' => $this->pageinfo['content_from_pid']]);
447
            $title = BackendUtility::getRecordTitle('pages', $contentPage);
448
            $link = '<a href="' . htmlspecialchars($linkToPid) . '">' . htmlspecialchars($title) . ' (PID ' . (int)$this->pageinfo['content_from_pid'] . ')</a>';
449
            $message = sprintf($lang->getLL('content_from_pid_title'), $link);
450
            $view->assignMultiple([
451
                'title' => $title,
452
                'message' => $message,
453
                'state' => InfoboxViewHelper::STATE_INFO
454
            ]);
455
            $content .= $view->render();
456
        } else {
457
            $links = $this->getPageLinksWhereContentIsAlsoShownOn($this->pageinfo['uid']);
458
            if (!empty($links)) {
459
                $message = sprintf($lang->getLL('content_on_pid_title'), $links);
460
                $view->assignMultiple([
461
                    'title' => '',
462
                    'message' => $message,
463
                    'state' => InfoboxViewHelper::STATE_INFO
464
                ]);
465
                $content .= $view->render();
466
            }
467
        }
468
        return $content;
469
    }
470
471
    /**
472
     * Get all pages with links where the content of a page $pageId is also shown on
473
     *
474
     * @param int $pageId
475
     * @return string
476
     */
477
    protected function getPageLinksWhereContentIsAlsoShownOn($pageId): string
478
    {
479
        $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages');
480
        $queryBuilder->getRestrictions()->removeAll();
481
        $queryBuilder->getRestrictions()->add(GeneralUtility::makeInstance(DeletedRestriction::class));
482
        $queryBuilder
483
            ->select('*')
484
            ->from('pages')
485
            ->where($queryBuilder->expr()->eq('content_from_pid', $queryBuilder->createNamedParameter($pageId, \PDO::PARAM_INT)));
486
487
        $links = [];
488
        $rows = $queryBuilder->execute()->fetchAll();
489
        if (!empty($rows)) {
490
            foreach ($rows as $row) {
491
                $linkToPid = GeneralUtility::linkThisScript(['id' => $row['uid']]);
492
                $title = BackendUtility::getRecordTitle('pages', $row);
493
                $link = '<a href="' . htmlspecialchars($linkToPid) . '">' . htmlspecialchars($title) . ' (PID ' . (int)$row['uid'] . ')</a>';
494
                $links[] = $link;
495
            }
496
        }
497
        return implode(', ', $links);
498
    }
499
500
    /**
501
     * @return string $title
502
     */
503
    protected function getLocalizedPageTitle(): string
504
    {
505
        if ($this->current_sys_language > 0) {
506
            $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
507
                ->getQueryBuilderForTable('pages');
508
            $queryBuilder->getRestrictions()
509
                ->removeAll()
510
                ->add(GeneralUtility::makeInstance(DeletedRestriction::class))
511
                ->add(GeneralUtility::makeInstance(WorkspaceRestriction::class, (int)$this->getBackendUser()->workspace));
512
            $localizedPage = $queryBuilder
513
                ->select('*')
514
                ->from('pages')
515
                ->where(
516
                    $queryBuilder->expr()->eq(
517
                        $GLOBALS['TCA']['pages']['ctrl']['transOrigPointerField'],
518
                        $queryBuilder->createNamedParameter($this->id, \PDO::PARAM_INT)
519
                    ),
520
                    $queryBuilder->expr()->eq(
521
                        $GLOBALS['TCA']['pages']['ctrl']['languageField'],
522
                        $queryBuilder->createNamedParameter($this->current_sys_language, \PDO::PARAM_INT)
523
                    )
524
                )
525
                ->setMaxResults(1)
526
                ->execute()
527
                ->fetch();
528
            BackendUtility::workspaceOL('pages', $localizedPage);
529
            return $localizedPage['title'];
530
        }
531
        return $this->pageinfo['title'];
532
    }
533
534
    /**
535
     * Main function.
536
     * Creates some general objects and calls other functions for the main rendering of module content.
537
     *
538
     * @param ServerRequestInterface $request
539
     */
540
    protected function main(ServerRequestInterface $request): void
541
    {
542
        $content = '';
543
        // Access check...
544
        // The page will show only if there is a valid page and if this page may be viewed by the user
545
        if ($this->id && is_array($this->pageinfo)) {
546
            $this->moduleTemplate->getDocHeaderComponent()->setMetaInformation($this->pageinfo);
547
548
            $this->moduleTemplate->addJavaScriptCode('mainJsFunctions', '
549
                if (top.fsMod) {
550
                    top.fsMod.recentIds["web"] = ' . (int)$this->id . ';
551
                    top.fsMod.navFrameHighlightedID["web"] = top.fsMod.currentBank + "_" + ' . (int)$this->id . ';
552
                }
553
                function deleteRecord(table,id,url) {   //
554
                    window.location.href = ' . GeneralUtility::quoteJSvalue((string)$this->uriBuilder->buildUriFromRoute('tce_db') . '&cmd[')
555
                                            . ' + table + "][" + id + "][delete]=1&redirect=" + encodeURIComponent(url);
556
                    return false;
557
                }
558
            ');
559
560
            if ($this->context instanceof PageLayoutContext) {
561
                $backendLayout = $this->context->getBackendLayout();
562
563
                // Find backend layout / columns
564
                if (!empty($backendLayout->getColumnPositionNumbers())) {
565
                    $this->colPosList = implode(',', $backendLayout->getColumnPositionNumbers());
566
                }
567
                // Removing duplicates, if any
568
                $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...
569
                // Accessible columns
570
                if (isset($this->modSharedTSconfig['properties']['colPos_list']) && trim($this->modSharedTSconfig['properties']['colPos_list']) !== '') {
571
                    $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...
572
                    // Match with the list which is present in the colPosList for the current page
573
                    if (!empty($this->colPosList) && !empty($this->activeColPosList)) {
574
                        $this->activeColPosList = array_unique(array_intersect(
575
                            $this->activeColPosList,
576
                            $this->colPosList
577
                        ));
578
                    }
579
                } else {
580
                    $this->activeColPosList = $this->colPosList;
581
                }
582
                $this->activeColPosList = implode(',', $this->activeColPosList);
583
                $this->colPosList = implode(',', $this->colPosList);
584
            }
585
586
            $content .= $this->getHeaderFlashMessagesForCurrentPid();
587
588
            // Render the primary module content:
589
            $content .= '<form action="' . htmlspecialchars((string)$this->uriBuilder->buildUriFromRoute($this->moduleName, ['id' => $this->id])) . '" id="PageLayoutController" method="post">';
590
            // Page title
591
            $content .= '<h1 class="' . ($this->isPageEditable($this->current_sys_language) ? 't3js-title-inlineedit' : '') . '">' . htmlspecialchars($this->getLocalizedPageTitle()) . '</h1>';
592
            // All other listings
593
            $content .= $this->renderContent();
594
            $content .= '</form>';
595
            // Setting up the buttons for the docheader
596
            $this->makeButtons($request);
597
598
            // Create LanguageMenu
599
            $this->makeLanguageMenu();
600
        } else {
601
            $this->moduleTemplate->addJavaScriptCode(
602
                'mainJsFunctions',
603
                'if (top.fsMod) top.fsMod.recentIds["web"] = ' . (int)$this->id . ';'
604
            );
605
            $content .= '<h1>' . htmlspecialchars($GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']) . '</h1>';
606
            $view = GeneralUtility::makeInstance(StandaloneView::class);
607
            $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Templates/InfoBox.html'));
608
            $view->assignMultiple([
609
                'title' => $this->getLanguageService()->getLL('clickAPage_header'),
610
                'message' => $this->getLanguageService()->getLL('clickAPage_content'),
611
                'state' => InfoboxViewHelper::STATE_INFO
612
            ]);
613
            $content .= $view->render();
614
        }
615
        // Set content
616
        $this->moduleTemplate->setContent($content);
617
    }
618
619
    /**
620
     * Rendering content
621
     *
622
     * @return string
623
     */
624
    protected function renderContent(): string
625
    {
626
        $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/ContextMenu');
627
        $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/Tooltip');
628
        $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/Localization');
629
        $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/LayoutModule/DragDrop');
630
        $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/Modal');
631
        $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/LayoutModule/Paste');
632
        $this->pageRenderer->addInlineLanguageLabelFile('EXT:backend/Resources/Private/Language/locallang_layout.xlf');
633
634
        $tableOutput = '';
635
        $numberOfHiddenElements = 0;
636
637
        if ($this->context instanceof PageLayoutContext) {
638
            // Context may not be set, which happens if the page module is viewed by a user with no access to the
639
            // current page, or if the ID parameter is malformed. In this case we do not resolve any backend layout
640
            // or other page structure information and we do not render any "table output" for the module.
641
            $backendLayout = $this->context->getBackendLayout();
0 ignored issues
show
Unused Code introduced by
The assignment to $backendLayout is dead and can be removed.
Loading history...
642
643
            $configuration = $this->context->getDrawingConfiguration();
644
            $configuration->setDefaultLanguageBinding(!empty($this->modTSconfig['properties']['defLangBinding']));
645
            $configuration->setActiveColumns(GeneralUtility::trimExplode(',', $this->activeColPosList));
646
            $configuration->setShowHidden((bool)$this->MOD_SETTINGS['tt_content_showHidden']);
647
            $configuration->setLanguageColumns($this->MOD_MENU['language']);
648
            $configuration->setShowNewContentWizard(empty($this->modTSconfig['properties']['disableNewContentElementWizard']));
649
            $configuration->setSelectedLanguageId((int)$this->MOD_SETTINGS['language']);
650
            if ($this->MOD_SETTINGS['function'] == 2) {
651
                $configuration->setLanguageMode(true);
652
            }
653
654
            $numberOfHiddenElements = $this->getNumberOfHiddenElements($configuration->getLanguageColumns());
655
656
            $pageLayoutDrawer = $this->context->getBackendLayoutRenderer();
657
658
            $pageActionsCallback = null;
659
            if ($this->context->isPageEditable()) {
660
                $languageOverlayId = 0;
661
                $pageLocalizationRecord = BackendUtility::getRecordLocalization('pages', $this->id, (int)$this->current_sys_language);
662
                if (is_array($pageLocalizationRecord)) {
663
                    $pageLocalizationRecord = reset($pageLocalizationRecord);
664
                }
665
                if (!empty($pageLocalizationRecord['uid'])) {
666
                    $languageOverlayId = $pageLocalizationRecord['uid'];
667
                }
668
                $pageActionsCallback = 'function(PageActions) {
669
                    PageActions.setPageId(' . (int)$this->id . ');
670
                    PageActions.setLanguageOverlayId(' . $languageOverlayId . ');
671
                }';
672
            }
673
            $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/PageActions', $pageActionsCallback);
674
            $tableOutput = $pageLayoutDrawer->drawContent();
675
        }
676
677
        if ($this->getBackendUser()->check('tables_select', 'tt_content') && $numberOfHiddenElements > 0) {
678
            // Toggle hidden ContentElements
679
            $tableOutput .= '
680
                <div class="form-check">
681
                    <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"' : '') . ' />
682
                    <label class="form-check-label" for="checkTt_content_showHidden">
683
                        ' . htmlspecialchars($this->getLanguageService()->getLL('hiddenCE')) . ' (<span class="t3js-hidden-counter">' . $numberOfHiddenElements . '</span>)
684
                    </label>
685
                </div>';
686
        }
687
688
        // Init the content
689
        $content = '';
690
        // Additional header content
691
        foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/db_layout.php']['drawHeaderHook'] ?? [] as $hook) {
692
            $params = [];
693
            $content .= GeneralUtility::callUserFunction($hook, $params, $this);
694
        }
695
        $content .= $tableOutput;
696
697
        // Additional footer content
698
        foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/db_layout.php']['drawFooterHook'] ?? [] as $hook) {
699
            $params = [];
700
            $content .= GeneralUtility::callUserFunction($hook, $params, $this);
701
        }
702
        return $content;
703
    }
704
705
    /***************************
706
     *
707
     * Sub-content functions, rendering specific parts of the module content.
708
     *
709
     ***************************/
710
    /**
711
     * This creates the buttons for the modules
712
     * @param ServerRequestInterface $request
713
     */
714
    protected function makeButtons(ServerRequestInterface $request): void
715
    {
716
        // Add CSH (Context Sensitive Help) icon to tool bar
717
        $contextSensitiveHelpButton = $this->buttonBar->makeHelpButton()
718
            ->setModuleName('_MOD_' . $this->moduleName)
719
            ->setFieldName('columns_' . $this->MOD_SETTINGS['function']);
720
        $this->buttonBar->addButton($contextSensitiveHelpButton);
721
        $lang = $this->getLanguageService();
722
        // View page
723
        $pageTsConfig = BackendUtility::getPagesTSconfig($this->id);
724
        // Exclude sysfolders, spacers and recycler by default
725
        $excludeDokTypes = [
726
            PageRepository::DOKTYPE_RECYCLER,
727
            PageRepository::DOKTYPE_SYSFOLDER,
728
            PageRepository::DOKTYPE_SPACER
729
        ];
730
        // Custom override of values
731
        if (isset($pageTsConfig['TCEMAIN.']['preview.']['disableButtonForDokType'])) {
732
            $excludeDokTypes = GeneralUtility::intExplode(
733
                ',',
734
                $pageTsConfig['TCEMAIN.']['preview.']['disableButtonForDokType'],
735
                true
736
            );
737
        }
738
739
        if (
740
            !in_array((int)$this->pageinfo['doktype'], $excludeDokTypes, true)
741
            && !VersionState::cast($this->pageinfo['t3ver_state'])->equals(VersionState::DELETE_PLACEHOLDER)
742
        ) {
743
            $languageParameter = $this->current_sys_language ? ('&L=' . $this->current_sys_language) : '';
744
            $previewDataAttributes = PreviewUriBuilder::create((int)$this->pageinfo['uid'])
745
                ->withRootLine(BackendUtility::BEgetRootLine($this->pageinfo['uid']))
746
                ->withAdditionalQueryParameters($languageParameter)
747
                ->buildDispatcherDataAttributes();
748
            $viewButton = $this->buttonBar->makeLinkButton()
749
                ->setDataAttributes($previewDataAttributes ?? [])
750
                ->setTitle($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.showPage'))
751
                ->setIcon($this->iconFactory->getIcon('actions-view-page', Icon::SIZE_SMALL))
752
                ->setHref('#');
753
754
            $this->buttonBar->addButton($viewButton, ButtonBar::BUTTON_POSITION_LEFT, 3);
755
        }
756
        // Shortcut
757
        $shortcutButton = $this->buttonBar->makeShortcutButton()
758
            ->setRouteIdentifier($this->moduleName)
759
            ->setDisplayName($this->getShortcutTitle())
760
            ->setArguments([
761
                'id' => (int)$this->id,
762
                'SET' => [
763
                    'tt_content_showHidden' => (bool)$this->MOD_SETTINGS['tt_content_showHidden'],
764
                    'function' => (int)$this->MOD_SETTINGS['function'],
765
                    'language' => (int)$this->current_sys_language,
766
                ]
767
            ]);
768
        $this->buttonBar->addButton($shortcutButton);
769
770
        // Cache
771
        $clearCacheButton = $this->buttonBar->makeLinkButton()
772
            ->setHref('#')
773
            ->setDataAttributes(['id' => $this->pageinfo['uid']])
774
            ->setClasses('t3js-clear-page-cache')
775
            ->setTitle($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.clear_cache'))
776
            ->setIcon($this->iconFactory->getIcon('actions-system-cache-clear', Icon::SIZE_SMALL));
777
        $this->buttonBar->addButton($clearCacheButton, ButtonBar::BUTTON_POSITION_RIGHT, 1);
778
779
        // Edit page properties and page language overlay icons
780
        if ($this->isPageEditable(0)) {
781
            /** @var \TYPO3\CMS\Core\Http\NormalizedParams */
782
            $normalizedParams = $request->getAttribute('normalizedParams');
783
            // Edit localized pages only when one specific language is selected
784
            if ($this->MOD_SETTINGS['function'] == 1 && $this->current_sys_language > 0) {
785
                $localizationParentField = $GLOBALS['TCA']['pages']['ctrl']['transOrigPointerField'];
786
                $languageField = $GLOBALS['TCA']['pages']['ctrl']['languageField'];
787
                $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
788
                    ->getQueryBuilderForTable('pages');
789
                $queryBuilder->getRestrictions()
790
                    ->removeAll()
791
                    ->add(GeneralUtility::makeInstance(DeletedRestriction::class))
792
                    ->add(GeneralUtility::makeInstance(WorkspaceRestriction::class, (int)$this->getBackendUser()->workspace));
793
                $overlayRecord = $queryBuilder
794
                    ->select('uid')
795
                    ->from('pages')
796
                    ->where(
797
                        $queryBuilder->expr()->eq(
798
                            $localizationParentField,
799
                            $queryBuilder->createNamedParameter($this->id, \PDO::PARAM_INT)
800
                        ),
801
                        $queryBuilder->expr()->eq(
802
                            $languageField,
803
                            $queryBuilder->createNamedParameter($this->current_sys_language, \PDO::PARAM_INT)
804
                        )
805
                    )
806
                    ->setMaxResults(1)
807
                    ->execute()
808
                    ->fetch();
809
                BackendUtility::workspaceOL('pages', $overlayRecord, (int)$this->getBackendUser()->workspace);
810
                // Edit button
811
                $urlParameters = [
812
                    'edit' => [
813
                        'pages' => [
814
                            $overlayRecord['uid'] => 'edit'
815
                        ]
816
                    ],
817
                    'returnUrl' => $normalizedParams->getRequestUri(),
818
                ];
819
820
                $url = (string)$this->uriBuilder->buildUriFromRoute('record_edit', $urlParameters);
821
                $editLanguageButton = $this->buttonBar->makeLinkButton()
822
                    ->setHref($url)
823
                    ->setTitle($lang->getLL('editPageLanguageOverlayProperties'))
824
                    ->setIcon($this->iconFactory->getIcon('mimetypes-x-content-page-language-overlay', Icon::SIZE_SMALL));
825
                $this->buttonBar->addButton($editLanguageButton, ButtonBar::BUTTON_POSITION_LEFT, 3);
826
            }
827
            $urlParameters = [
828
                'edit' => [
829
                    'pages' => [
830
                        $this->id => 'edit'
831
                    ]
832
                ],
833
                'returnUrl' => $normalizedParams->getRequestUri(),
834
            ];
835
            $url = (string)$this->uriBuilder->buildUriFromRoute('record_edit', $urlParameters);
836
            $editPageButton = $this->buttonBar->makeLinkButton()
837
                ->setHref($url)
838
                ->setTitle($lang->getLL('editPageProperties'))
839
                ->setIcon($this->iconFactory->getIcon('actions-page-open', Icon::SIZE_SMALL));
840
            $this->buttonBar->addButton($editPageButton, ButtonBar::BUTTON_POSITION_LEFT, 3);
841
        }
842
    }
843
844
    /*******************************
845
     *
846
     * Other functions
847
     *
848
     ******************************/
849
    /**
850
     * Returns the number of hidden elements (including those hidden by start/end times)
851
     * on the current page (for the current sys_language)
852
     *
853
     * @param array $languageColumns
854
     * @return int
855
     */
856
    protected function getNumberOfHiddenElements(array $languageColumns): int
857
    {
858
        $andWhere = [];
859
        $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tt_content');
860
        $queryBuilder->getRestrictions()
861
            ->removeAll()
862
            ->add(GeneralUtility::makeInstance(DeletedRestriction::class))
863
            ->add(GeneralUtility::makeInstance(WorkspaceRestriction::class, (int)$this->getBackendUser()->workspace));
864
865
        $queryBuilder
866
            ->count('uid')
867
            ->from('tt_content')
868
            ->where(
869
                $queryBuilder->expr()->eq(
870
                    'pid',
871
                    $queryBuilder->createNamedParameter($this->id, \PDO::PARAM_INT)
872
                )
873
            );
874
875
        if (!empty($languageColumns)) {
876
            // Multi-language view is active
877
            if ($this->current_sys_language > 0) {
878
                $queryBuilder->andWhere(
879
                    $queryBuilder->expr()->in(
880
                        'sys_language_uid',
881
                        [0, $queryBuilder->createNamedParameter($this->current_sys_language, \PDO::PARAM_INT)]
882
                    )
883
                );
884
            }
885
        } else {
886
            $queryBuilder->andWhere(
887
                $queryBuilder->expr()->eq(
888
                    'sys_language_uid',
889
                    $queryBuilder->createNamedParameter($this->current_sys_language, \PDO::PARAM_INT)
890
                )
891
            );
892
        }
893
894
        if (!empty($GLOBALS['TCA']['tt_content']['ctrl']['enablecolumns']['disabled'])) {
895
            $andWhere[] = $queryBuilder->expr()->neq(
896
                'hidden',
897
                $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
898
            );
899
        }
900
901
        if (!empty($GLOBALS['TCA']['tt_content']['ctrl']['enablecolumns']['starttime'])) {
902
            $andWhere[] = $queryBuilder->expr()->andX(
903
                $queryBuilder->expr()->neq(
904
                    'starttime',
905
                    $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
906
                ),
907
                $queryBuilder->expr()->gt(
908
                    'starttime',
909
                    $queryBuilder->createNamedParameter($GLOBALS['SIM_ACCESS_TIME'], \PDO::PARAM_INT)
910
                )
911
            );
912
        }
913
914
        if (!empty($GLOBALS['TCA']['tt_content']['ctrl']['enablecolumns']['endtime'])) {
915
            $andWhere[] = $queryBuilder->expr()->andX(
916
                $queryBuilder->expr()->neq(
917
                    'endtime',
918
                    $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
919
                ),
920
                $queryBuilder->expr()->lte(
921
                    'endtime',
922
                    $queryBuilder->createNamedParameter($GLOBALS['SIM_ACCESS_TIME'], \PDO::PARAM_INT)
923
                )
924
            );
925
        }
926
927
        if (!empty($andWhere)) {
928
            $queryBuilder->andWhere(
929
                $queryBuilder->expr()->orX(...$andWhere)
930
            );
931
        }
932
933
        $count = $queryBuilder
934
            ->execute()
935
            ->fetchColumn(0);
936
937
        return (int)$count;
938
    }
939
940
    /**
941
     * Check if page can be edited by current user
942
     *
943
     * @param int $languageId
944
     * @return bool
945
     */
946
    protected function isPageEditable(int $languageId): bool
947
    {
948
        if ($this->getBackendUser()->isAdmin()) {
949
            return true;
950
        }
951
952
        return !$this->pageinfo['editlock']
953
            && $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

953
            && $this->getBackendUser()->doesUserHaveAccess(/** @scrutinizer ignore-type */ $this->pageinfo, Permission::PAGE_EDIT)
Loading history...
954
            && $this->getBackendUser()->checkLanguageAccess($languageId);
955
    }
956
957
    /**
958
     * Check if content can be edited by current user
959
     *
960
     * @param int $languageId
961
     * @return bool
962
     */
963
    protected function isContentEditable(int $languageId): bool
964
    {
965
        if ($this->getBackendUser()->isAdmin()) {
966
            return true;
967
        }
968
969
        return !$this->pageinfo['editlock']
970
            && $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

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