Completed
Push — master ( f66149...a7372c )
by
unknown
130:24 queued 111:56
created

PageLayoutController::renderContent()   F

Complexity

Conditions 19
Paths 1344

Size

Total Lines 131
Code Lines 89

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 19
eloc 89
c 1
b 0
f 0
nc 1344
nop 0
dl 0
loc 131
rs 0.3499

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

394
                    $linkedPath = '<a href="' . htmlspecialchars($linkToPid) . '">' . htmlspecialchars(/** @scrutinizer ignore-type */ $path) . '</a>';
Loading history...
395
                    $message .= sprintf(htmlspecialchars($lang->getLL('pageIsInternalLinkMessage')), $linkedPath);
396
                    $message .= ' (' . htmlspecialchars($lang->sL(BackendUtility::getLabelFromItemlist('pages', 'shortcut_mode', $shortcutMode))) . ')';
397
                    $state = InfoboxViewHelper::STATE_INFO;
398
                }
399
            } else {
400
                $message = htmlspecialchars($lang->getLL('pageIsMisconfiguredInternalLinkMessage'));
401
                $state = InfoboxViewHelper::STATE_ERROR;
402
            }
403
404
            $view->assignMultiple([
405
                'title' => $this->pageinfo['title'],
406
                'message' => $message,
407
                'state' => $state
408
            ]);
409
            $content .= $view->render();
410
        } elseif ($this->pageinfo['doktype'] === PageRepository::DOKTYPE_LINK) {
411
            if (empty($this->pageinfo['url'])) {
412
                $view->assignMultiple([
413
                    'title' => $this->pageinfo['title'],
414
                    'message' => $lang->getLL('pageIsMisconfiguredExternalLinkMessage'),
415
                    'state' => InfoboxViewHelper::STATE_ERROR
416
                ]);
417
                $content .= $view->render();
418
            } else {
419
                $externalUrl = htmlspecialchars(GeneralUtility::makeInstance(PageRepository::class)->getExtURL($this->pageinfo));
420
                if ($externalUrl !== false) {
421
                    $externalUrlHtml = '<a href="' . $externalUrl . '" target="_blank" rel="noreferrer">' . $externalUrl . '</a>';
422
                    $view->assignMultiple([
423
                        'title' => $this->pageinfo['title'],
424
                        'message' => sprintf($lang->getLL('pageIsExternalLinkMessage'), $externalUrlHtml),
425
                        'state' => InfoboxViewHelper::STATE_INFO
426
                    ]);
427
                    $content .= $view->render();
428
                }
429
            }
430
        }
431
        // If content from different pid is displayed
432
        if ($this->pageinfo['content_from_pid']) {
433
            $contentPage = BackendUtility::getRecord('pages', (int)$this->pageinfo['content_from_pid']);
434
            $linkToPid = GeneralUtility::linkThisScript(['id' => $this->pageinfo['content_from_pid']]);
435
            $title = BackendUtility::getRecordTitle('pages', $contentPage);
436
            $link = '<a href="' . htmlspecialchars($linkToPid) . '">' . htmlspecialchars($title) . ' (PID ' . (int)$this->pageinfo['content_from_pid'] . ')</a>';
437
            $message = sprintf($lang->getLL('content_from_pid_title'), $link);
438
            $view->assignMultiple([
439
                'title' => $title,
440
                'message' => $message,
441
                'state' => InfoboxViewHelper::STATE_INFO
442
            ]);
443
            $content .= $view->render();
444
        } else {
445
            $links = $this->getPageLinksWhereContentIsAlsoShownOn($this->pageinfo['uid']);
446
            if (!empty($links)) {
447
                $message = sprintf($lang->getLL('content_on_pid_title'), $links);
448
                $view->assignMultiple([
449
                    'title' => '',
450
                    'message' => $message,
451
                    'state' => InfoboxViewHelper::STATE_INFO
452
                ]);
453
                $content .= $view->render();
454
            }
455
        }
456
        return $content;
457
    }
458
459
    /**
460
     * Get all pages with links where the content of a page $pageId is also shown on
461
     *
462
     * @param int $pageId
463
     * @return string
464
     */
465
    protected function getPageLinksWhereContentIsAlsoShownOn($pageId): string
466
    {
467
        $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages');
468
        $queryBuilder->getRestrictions()->removeAll();
469
        $queryBuilder->getRestrictions()->add(GeneralUtility::makeInstance(DeletedRestriction::class));
470
        $queryBuilder
471
            ->select('*')
472
            ->from('pages')
473
            ->where($queryBuilder->expr()->eq('content_from_pid', $queryBuilder->createNamedParameter($pageId, \PDO::PARAM_INT)));
474
475
        $links = [];
476
        $rows = $queryBuilder->execute()->fetchAll();
477
        if (!empty($rows)) {
478
            foreach ($rows as $row) {
479
                $linkToPid = GeneralUtility::linkThisScript(['id' => $row['uid']]);
480
                $title = BackendUtility::getRecordTitle('pages', $row);
481
                $link = '<a href="' . htmlspecialchars($linkToPid) . '">' . htmlspecialchars($title) . ' (PID ' . (int)$row['uid'] . ')</a>';
482
                $links[] = $link;
483
            }
484
        }
485
        return implode(', ', $links);
486
    }
487
488
    /**
489
     * @return string $title
490
     */
491
    protected function getLocalizedPageTitle(): string
492
    {
493
        if ($this->current_sys_language > 0) {
494
            $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
495
                ->getQueryBuilderForTable('pages');
496
            $queryBuilder->getRestrictions()
497
                ->removeAll()
498
                ->add(GeneralUtility::makeInstance(DeletedRestriction::class))
499
                ->add(GeneralUtility::makeInstance(BackendWorkspaceRestriction::class));
500
            $localizedPage = $queryBuilder
501
                ->select('*')
502
                ->from('pages')
503
                ->where(
504
                    $queryBuilder->expr()->eq(
505
                        $GLOBALS['TCA']['pages']['ctrl']['transOrigPointerField'],
506
                        $queryBuilder->createNamedParameter($this->id, \PDO::PARAM_INT)
507
                    ),
508
                    $queryBuilder->expr()->eq(
509
                        $GLOBALS['TCA']['pages']['ctrl']['languageField'],
510
                        $queryBuilder->createNamedParameter($this->current_sys_language, \PDO::PARAM_INT)
511
                    )
512
                )
513
                ->setMaxResults(1)
514
                ->execute()
515
                ->fetch();
516
            BackendUtility::workspaceOL('pages', $localizedPage);
517
            return $localizedPage['title'];
518
        }
519
        return $this->pageinfo['title'];
520
    }
521
522
    /**
523
     * Main function.
524
     * Creates some general objects and calls other functions for the main rendering of module content.
525
     *
526
     * @param ServerRequestInterface $request
527
     */
528
    protected function main(ServerRequestInterface $request): void
529
    {
530
        $content = '';
531
        // Access check...
532
        // The page will show only if there is a valid page and if this page may be viewed by the user
533
        if ($this->id && is_array($this->pageinfo)) {
534
            $this->moduleTemplate->getDocHeaderComponent()->setMetaInformation($this->pageinfo);
535
536
            $this->moduleTemplate->addJavaScriptCode('mainJsFunctions', '
537
                if (top.fsMod) {
538
                    top.fsMod.recentIds["web"] = ' . (int)$this->id . ';
539
                    top.fsMod.navFrameHighlightedID["web"] = top.fsMod.currentBank + "_" + ' . (int)$this->id . ';
540
                }
541
                function deleteRecord(table,id,url) {   //
542
                    window.location.href = ' . GeneralUtility::quoteJSvalue((string)$this->uriBuilder->buildUriFromRoute('tce_db') . '&cmd[')
543
                                            . ' + table + "][" + id + "][delete]=1&redirect=" + encodeURIComponent(url);
544
                    return false;
545
                }
546
            ');
547
548
            // Find backend layout / columns
549
            $backendLayout = $this->backendLayouts->getSelectedBackendLayout($this->id);
550
            if (!empty($backendLayout['__colPosList'])) {
551
                $this->colPosList = implode(',', $backendLayout['__colPosList']);
552
            }
553
            // Removing duplicates, if any
554
            $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...
555
            // Accessible columns
556
            if (isset($this->modSharedTSconfig['properties']['colPos_list']) && trim($this->modSharedTSconfig['properties']['colPos_list']) !== '') {
557
                $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...
558
                // Match with the list which is present in the colPosList for the current page
559
                if (!empty($this->colPosList) && !empty($this->activeColPosList)) {
560
                    $this->activeColPosList = array_unique(array_intersect(
561
                        $this->activeColPosList,
562
                        $this->colPosList
563
                    ));
564
                }
565
            } else {
566
                $this->activeColPosList = $this->colPosList;
567
            }
568
            $this->activeColPosList = implode(',', $this->activeColPosList);
569
            $this->colPosList = implode(',', $this->colPosList);
570
571
            $content .= $this->getHeaderFlashMessagesForCurrentPid();
572
573
            // Render the primary module content:
574
            $content .= '<form action="' . htmlspecialchars((string)$this->uriBuilder->buildUriFromRoute($this->moduleName, ['id' => $this->id])) . '" id="PageLayoutController" method="post">';
575
            // Page title
576
            $content .= '<h1 class="' . ($this->isPageEditable($this->current_sys_language) ? 't3js-title-inlineedit' : '') . '">' . htmlspecialchars($this->getLocalizedPageTitle()) . '</h1>';
577
            // All other listings
578
            $content .= $this->renderContent();
579
            $content .= '</form>';
580
            $content .= $this->searchContent;
581
            // Setting up the buttons for the docheader
582
            $this->makeButtons($request);
583
584
            // Create LanguageMenu
585
            $this->makeLanguageMenu();
586
        } else {
587
            $this->moduleTemplate->addJavaScriptCode(
588
                'mainJsFunctions',
589
                'if (top.fsMod) top.fsMod.recentIds["web"] = ' . (int)$this->id . ';'
590
            );
591
            $content .= '<h1>' . htmlspecialchars($GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']) . '</h1>';
592
            $view = GeneralUtility::makeInstance(StandaloneView::class);
593
            $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Templates/InfoBox.html'));
594
            $view->assignMultiple([
595
                'title' => $this->getLanguageService()->getLL('clickAPage_header'),
596
                'message' => $this->getLanguageService()->getLL('clickAPage_content'),
597
                'state' => InfoboxViewHelper::STATE_INFO
598
            ]);
599
            $content .= $view->render();
600
        }
601
        // Set content
602
        $this->moduleTemplate->setContent($content);
603
    }
604
605
    /**
606
     * Rendering content
607
     *
608
     * @return string
609
     */
610
    protected function renderContent(): string
611
    {
612
        $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/ContextMenu');
613
614
        if (GeneralUtility::makeInstance(Features::class)->isFeatureEnabled('fluidBasedPageModule')) {
615
            $selectedCombinedIdentifier = $this->backendLayouts->getSelectedCombinedIdentifier($this->id);
616
            // If no backend layout is selected, use default
617
            if (empty($selectedCombinedIdentifier)) {
618
                $selectedCombinedIdentifier = 'default';
619
            }
620
621
            $backendLayout = $this->backendLayouts->getDataProviderCollection()->getBackendLayout(
622
                $selectedCombinedIdentifier,
623
                $this->id
624
            );
625
626
            $configuration = $backendLayout->getDrawingConfiguration();
627
            $configuration->setPageId($this->id);
628
            $configuration->setDefaultLanguageBinding(!empty($this->modTSconfig['properties']['defLangBinding']));
629
            $configuration->setActiveColumns(GeneralUtility::trimExplode(',', $this->activeColPosList));
630
            $configuration->setShowHidden((bool)$this->MOD_SETTINGS['tt_content_showHidden']);
631
            $configuration->setLanguageColumns(array_combine(array_keys($this->MOD_MENU['language']), array_keys($this->MOD_MENU['language'])));
0 ignored issues
show
Bug introduced by
It seems like array_combine(array_keys...>MOD_MENU['language'])) can also be of type false; however, parameter $languageColumns of TYPO3\CMS\Backend\View\D...n::setLanguageColumns() 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

631
            $configuration->setLanguageColumns(/** @scrutinizer ignore-type */ array_combine(array_keys($this->MOD_MENU['language']), array_keys($this->MOD_MENU['language'])));
Loading history...
632
            $configuration->setLanguageColumnsPointer((int)$this->current_sys_language);
633
            if ($this->MOD_SETTINGS['function'] == 2) {
634
                $configuration->setLanguageMode($this->MOD_SETTINGS['function'] == 2);
635
            }
636
637
            $pageLayoutDrawer = $backendLayout->getBackendLayoutRenderer();
638
            $configuration->setShowNewContentWizard(empty($this->modTSconfig['properties']['disableNewContentElementWizard']));
639
640
            $pageActionsCallback = null;
641
            if ($configuration->isPageEditable()) {
642
                $languageOverlayId = 0;
643
                $pageLocalizationRecord = BackendUtility::getRecordLocalization('pages', $this->id, (int)$this->current_sys_language);
644
                if (is_array($pageLocalizationRecord)) {
645
                    $pageLocalizationRecord = reset($pageLocalizationRecord);
646
                }
647
                if (!empty($pageLocalizationRecord['uid'])) {
648
                    $languageOverlayId = $pageLocalizationRecord['uid'];
649
                }
650
                $pageActionsCallback = 'function(PageActions) {
651
                    PageActions.setPageId(' . (int)$this->id . ');
652
                    PageActions.setLanguageOverlayId(' . $languageOverlayId . ');
653
                }';
654
            }
655
            $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/PageActions', $pageActionsCallback);
656
            $numberOfHiddenElements = $this->getNumberOfHiddenElements($configuration->getLanguageColumns());
657
            $tableOutput = $pageLayoutDrawer->drawContent();
658
        } else {
659
            $dbList = GeneralUtility::makeInstance(PageLayoutView::class);
660
            $dbList->doEdit = $this->isContentEditable($this->current_sys_language);
661
            $dbList->option_newWizard = empty($this->modTSconfig['properties']['disableNewContentElementWizard']);
662
            $dbList->defLangBinding = !empty($this->modTSconfig['properties']['defLangBinding']);
663
            $tcaItems = $this->backendLayouts->getColPosListItemsParsed($this->id);
664
            $numberOfHiddenElements = $this->getNumberOfHiddenElements(is_array($dbList->tt_contentConfig['languageCols']) ? $dbList->tt_contentConfig['languageCols'] : []);
665
            // Setting up the tt_content columns to show:
666
            if (is_array($GLOBALS['TCA']['tt_content']['columns']['colPos']['config']['items'])) {
667
                $colList = [];
668
                foreach ($tcaItems as $temp) {
669
                    $colList[] = $temp[1];
670
                }
671
            } else {
672
                // ... should be impossible that colPos has no array. But this is the fallback should it make any sense:
673
                $colList = ['1', '0', '2', '3'];
674
            }
675
            if ($this->colPosList !== '') {
676
                $colList = array_intersect(GeneralUtility::intExplode(',', $this->colPosList), $colList);
677
            }
678
            // The order of the rows: Default is left(1), Normal(0), right(2), margin(3)
679
            $dbList->tt_contentConfig['cols'] = implode(',', $colList);
680
            $dbList->tt_contentConfig['activeCols'] = $this->activeColPosList;
681
            $dbList->tt_contentConfig['showHidden'] = $this->MOD_SETTINGS['tt_content_showHidden'];
682
            $dbList->tt_contentConfig['sys_language_uid'] = (int)$this->current_sys_language;
683
            // If the function menu is set to "Language":
684
            if ($this->MOD_SETTINGS['function'] == 2) {
685
                $dbList->tt_contentConfig['languageMode'] = 1;
686
                $dbList->tt_contentConfig['languageCols'] = $this->MOD_MENU['language'];
687
                $dbList->tt_contentConfig['languageColsPointer'] = $this->current_sys_language;
688
            }
689
            $tableOutput = $dbList->getTable_tt_content($this->id);
690
            $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/Tooltip');
691
            $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/Localization');
692
            $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/LayoutModule/DragDrop');
693
            $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/Modal');
694
            $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/LayoutModule/Paste');
695
        }
696
697
        $this->pageRenderer->addInlineLanguageLabelFile('EXT:backend/Resources/Private/Language/locallang_layout.xlf');
698
        if ($this->getBackendUser()->check('tables_select', 'tt_content')) {
699
            $h_func_b = '';
700
            // Toggle hidden ContentElements
701
702
            if ($numberOfHiddenElements > 0) {
703
                $h_func_b = '
704
                    <div class="checkbox">
705
                        <label for="checkTt_content_showHidden">
706
                            <input type="checkbox" id="checkTt_content_showHidden" class="checkbox" name="SET[tt_content_showHidden]" value="1" ' . ($this->MOD_SETTINGS['tt_content_showHidden'] ? 'checked="checked"' : '') . ' />
707
                            ' . htmlspecialchars($this->getLanguageService()->getLL('hiddenCE')) . ' (<span class="t3js-hidden-counter">' . $numberOfHiddenElements . '</span>)
708
                        </label>
709
                    </div>';
710
            }
711
        }
712
        $tableOutput .= $h_func_b;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $h_func_b does not seem to be defined for all execution paths leading up to this point.
Loading history...
713
714
        // Init the content
715
        $content = '';
716
        // Additional header content
717
        foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/db_layout.php']['drawHeaderHook'] ?? [] as $hook) {
718
            $params = [];
719
            $content .= GeneralUtility::callUserFunction($hook, $params, $this);
720
        }
721
        $content .= $tableOutput;
722
        // Making search form:
723
        if (!$this->modTSconfig['properties']['disableSearchBox']) {
724
            $this->searchContent = $this->getSearchBox();
725
            if ($this->searchContent) {
726
                $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/ToggleSearchToolbox');
727
                $toggleSearchFormButton = $this->buttonBar->makeLinkButton()
728
                    ->setClasses('t3js-toggle-search-toolbox')
729
                    ->setTitle($this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.title.searchIcon'))
730
                    ->setIcon($this->iconFactory->getIcon('actions-search', Icon::SIZE_SMALL))
731
                    ->setHref('#');
732
                $this->buttonBar->addButton($toggleSearchFormButton, ButtonBar::BUTTON_POSITION_LEFT, 4);
733
            }
734
        }
735
        // Additional footer content
736
        foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/db_layout.php']['drawFooterHook'] ?? [] as $hook) {
737
            $params = [];
738
            $content .= GeneralUtility::callUserFunction($hook, $params, $this);
739
        }
740
        return $content;
741
    }
742
743
    /***************************
744
     *
745
     * Sub-content functions, rendering specific parts of the module content.
746
     *
747
     ***************************/
748
    /**
749
     * This creates the buttons for the modules
750
     * @param ServerRequestInterface $request
751
     */
752
    protected function makeButtons(ServerRequestInterface $request): void
753
    {
754
        // Add CSH (Context Sensitive Help) icon to tool bar
755
        $contextSensitiveHelpButton = $this->buttonBar->makeHelpButton()
756
            ->setModuleName('_MOD_' . $this->moduleName)
757
            ->setFieldName('columns_' . $this->MOD_SETTINGS['function']);
758
        $this->buttonBar->addButton($contextSensitiveHelpButton);
759
        $lang = $this->getLanguageService();
760
        // View page
761
        if (!VersionState::cast($this->pageinfo['t3ver_state'])->equals(VersionState::DELETE_PLACEHOLDER)) {
762
            $languageParameter = $this->current_sys_language ? ('&L=' . $this->current_sys_language) : '';
763
            $onClick = BackendUtility::viewOnClick(
764
                $this->pageinfo['uid'],
765
                '',
766
                BackendUtility::BEgetRootLine($this->pageinfo['uid']),
767
                '',
768
                '',
769
                $languageParameter
770
            );
771
            $viewButton = $this->buttonBar->makeLinkButton()
772
                ->setOnClick($onClick)
773
                ->setTitle($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.showPage'))
774
                ->setIcon($this->iconFactory->getIcon('actions-view-page', Icon::SIZE_SMALL))
775
                ->setHref('#');
776
777
            $this->buttonBar->addButton($viewButton, ButtonBar::BUTTON_POSITION_LEFT, 3);
778
        }
779
        // Shortcut
780
        $shortcutButton = $this->buttonBar->makeShortcutButton()
781
            ->setModuleName($this->moduleName)
782
            ->setGetVariables([
783
                'id',
784
                'route',
785
                'edit_record',
786
            ])
787
            ->setSetVariables(array_keys($this->MOD_MENU));
788
        $this->buttonBar->addButton($shortcutButton);
789
790
        // Cache
791
        if (empty($this->modTSconfig['properties']['disableAdvanced'])) {
792
            $clearCacheButton = $this->buttonBar->makeLinkButton()
793
                ->setHref('#')
794
                ->setDataAttributes(['id' => $this->pageinfo['uid']])
795
                ->setClasses('t3js-clear-page-cache')
796
                ->setTitle($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.clear_cache'))
797
                ->setIcon($this->iconFactory->getIcon('actions-system-cache-clear', Icon::SIZE_SMALL));
798
            $this->buttonBar->addButton($clearCacheButton, ButtonBar::BUTTON_POSITION_RIGHT, 1);
799
        }
800
        if (empty($this->modTSconfig['properties']['disableIconToolbar'])) {
801
            // Edit page properties and page language overlay icons
802
            if ($this->isPageEditable(0)) {
803
                /** @var \TYPO3\CMS\Core\Http\NormalizedParams */
804
                $normalizedParams = $request->getAttribute('normalizedParams');
805
                // Edit localized pages only when one specific language is selected
806
                if ($this->MOD_SETTINGS['function'] == 1 && $this->current_sys_language > 0) {
807
                    $localizationParentField = $GLOBALS['TCA']['pages']['ctrl']['transOrigPointerField'];
808
                    $languageField = $GLOBALS['TCA']['pages']['ctrl']['languageField'];
809
                    $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
810
                        ->getQueryBuilderForTable('pages');
811
                    $queryBuilder->getRestrictions()
812
                        ->removeAll()
813
                        ->add(GeneralUtility::makeInstance(DeletedRestriction::class))
814
                        ->add(GeneralUtility::makeInstance(BackendWorkspaceRestriction::class));
815
                    $overlayRecord = $queryBuilder
816
                        ->select('uid')
817
                        ->from('pages')
818
                        ->where(
819
                            $queryBuilder->expr()->eq(
820
                                $localizationParentField,
821
                                $queryBuilder->createNamedParameter($this->id, \PDO::PARAM_INT)
822
                            ),
823
                            $queryBuilder->expr()->eq(
824
                                $languageField,
825
                                $queryBuilder->createNamedParameter($this->current_sys_language, \PDO::PARAM_INT)
826
                            )
827
                        )
828
                        ->setMaxResults(1)
829
                        ->execute()
830
                        ->fetch();
831
                    // Edit button
832
                    $urlParameters = [
833
                        'edit' => [
834
                            'pages' => [
835
                                $overlayRecord['uid'] => 'edit'
836
                            ]
837
                        ],
838
                        'returnUrl' => $normalizedParams->getRequestUri(),
839
                    ];
840
841
                    $url = (string)$this->uriBuilder->buildUriFromRoute('record_edit', $urlParameters);
842
                    $editLanguageButton = $this->buttonBar->makeLinkButton()
843
                        ->setHref($url)
844
                        ->setTitle($lang->getLL('editPageLanguageOverlayProperties'))
845
                        ->setIcon($this->iconFactory->getIcon('mimetypes-x-content-page-language-overlay', Icon::SIZE_SMALL));
846
                    $this->buttonBar->addButton($editLanguageButton, ButtonBar::BUTTON_POSITION_LEFT, 3);
847
                }
848
                $urlParameters = [
849
                    'edit' => [
850
                        'pages' => [
851
                            $this->id => 'edit'
852
                        ]
853
                    ],
854
                    'returnUrl' => $normalizedParams->getRequestUri(),
855
                ];
856
                $url = (string)$this->uriBuilder->buildUriFromRoute('record_edit', $urlParameters);
857
                $editPageButton = $this->buttonBar->makeLinkButton()
858
                    ->setHref($url)
859
                    ->setTitle($lang->getLL('editPageProperties'))
860
                    ->setIcon($this->iconFactory->getIcon('actions-page-open', Icon::SIZE_SMALL));
861
                $this->buttonBar->addButton($editPageButton, ButtonBar::BUTTON_POSITION_LEFT, 3);
862
            }
863
        }
864
    }
865
866
    /*******************************
867
     *
868
     * Other functions
869
     *
870
     ******************************/
871
    /**
872
     * Returns the number of hidden elements (including those hidden by start/end times)
873
     * on the current page (for the current sys_language)
874
     *
875
     * @param array $languageColumns
876
     * @return int
877
     */
878
    protected function getNumberOfHiddenElements(array $languageColumns): int
879
    {
880
        $andWhere = [];
881
        $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tt_content');
882
        $queryBuilder->getRestrictions()
883
            ->removeAll()
884
            ->add(GeneralUtility::makeInstance(DeletedRestriction::class))
885
            ->add(GeneralUtility::makeInstance(BackendWorkspaceRestriction::class));
886
887
        $queryBuilder
888
            ->count('uid')
889
            ->from('tt_content')
890
            ->where(
891
                $queryBuilder->expr()->eq(
892
                    'pid',
893
                    $queryBuilder->createNamedParameter($this->id, \PDO::PARAM_INT)
894
                )
895
            );
896
897
        if (!empty($languageColumns)) {
898
            // Multi-language view is active
899
            if ($this->current_sys_language > 0) {
900
                $queryBuilder->andWhere(
901
                    $queryBuilder->expr()->in(
902
                        'sys_language_uid',
903
                        [0, $queryBuilder->createNamedParameter($this->current_sys_language, \PDO::PARAM_INT)]
904
                    )
905
                );
906
            }
907
        } else {
908
            $queryBuilder->andWhere(
909
                $queryBuilder->expr()->eq(
910
                    'sys_language_uid',
911
                    $queryBuilder->createNamedParameter($this->current_sys_language, \PDO::PARAM_INT)
912
                )
913
            );
914
        }
915
916
        if (!empty($GLOBALS['TCA']['tt_content']['ctrl']['enablecolumns']['disabled'])) {
917
            $andWhere[] = $queryBuilder->expr()->neq(
918
                'hidden',
919
                $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
920
            );
921
        }
922
923
        if (!empty($GLOBALS['TCA']['tt_content']['ctrl']['enablecolumns']['starttime'])) {
924
            $andWhere[] = $queryBuilder->expr()->andX(
925
                $queryBuilder->expr()->neq(
926
                    'starttime',
927
                    $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
928
                ),
929
                $queryBuilder->expr()->gt(
930
                    'starttime',
931
                    $queryBuilder->createNamedParameter($GLOBALS['SIM_ACCESS_TIME'], \PDO::PARAM_INT)
932
                )
933
            );
934
        }
935
936
        if (!empty($GLOBALS['TCA']['tt_content']['ctrl']['enablecolumns']['endtime'])) {
937
            $andWhere[] = $queryBuilder->expr()->andX(
938
                $queryBuilder->expr()->neq(
939
                    'endtime',
940
                    $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
941
                ),
942
                $queryBuilder->expr()->lte(
943
                    'endtime',
944
                    $queryBuilder->createNamedParameter($GLOBALS['SIM_ACCESS_TIME'], \PDO::PARAM_INT)
945
                )
946
            );
947
        }
948
949
        if (!empty($andWhere)) {
950
            $queryBuilder->andWhere(
951
                $queryBuilder->expr()->orX(...$andWhere)
952
            );
953
        }
954
955
        $count = $queryBuilder
956
            ->execute()
957
            ->fetchColumn(0);
958
959
        return (int)$count;
960
    }
961
962
    /**
963
     * Check if page can be edited by current user
964
     *
965
     * @param int|null $languageId
966
     * @return bool
967
     */
968
    protected function isPageEditable(int $languageId): bool
969
    {
970
        if ($this->getBackendUser()->isAdmin()) {
971
            return true;
972
        }
973
974
        return !$this->pageinfo['editlock']
975
            && $this->getBackendUser()->doesUserHaveAccess($this->pageinfo, Permission::PAGE_EDIT)
976
            && $this->getBackendUser()->checkLanguageAccess($languageId);
977
    }
978
979
    /**
980
     * Check if content can be edited by current user
981
     *
982
     * @param int $languageId
983
     * @return bool
984
     */
985
    protected function isContentEditable(int $languageId): bool
986
    {
987
        if ($this->getBackendUser()->isAdmin()) {
988
            return true;
989
        }
990
991
        return !$this->pageinfo['editlock']
992
            && $this->getBackendUser()->doesUserHaveAccess($this->pageinfo, Permission::CONTENT_EDIT)
993
            && $this->getBackendUser()->checkLanguageAccess($languageId);
994
    }
995
996
    /**
997
     * Returns LanguageService
998
     *
999
     * @return LanguageService
1000
     */
1001
    protected function getLanguageService(): LanguageService
1002
    {
1003
        return $GLOBALS['LANG'];
1004
    }
1005
1006
    /**
1007
     * Returns the current BE user.
1008
     *
1009
     * @return BackendUserAuthentication
1010
     */
1011
    protected function getBackendUser(): BackendUserAuthentication
1012
    {
1013
        return $GLOBALS['BE_USER'];
1014
    }
1015
1016
    /**
1017
     * Make the LanguageMenu
1018
     */
1019
    protected function makeLanguageMenu(): void
1020
    {
1021
        if (count($this->MOD_MENU['language']) > 1) {
1022
            $languageMenu = $this->moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->makeMenu();
1023
            $languageMenu->setIdentifier('languageMenu');
1024
            foreach ($this->MOD_MENU['language'] as $key => $language) {
1025
                $menuItem = $languageMenu
1026
                    ->makeMenuItem()
1027
                    ->setTitle($language)
1028
                    ->setHref((string)$this->uriBuilder->buildUriFromRoute($this->moduleName) . '&id=' . $this->id . '&SET[language]=' . $key);
1029
                if ((int)$this->current_sys_language === $key) {
1030
                    $menuItem->setActive(true);
1031
                }
1032
                $languageMenu->addMenuItem($menuItem);
1033
            }
1034
            $this->moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->addMenu($languageMenu);
1035
        }
1036
    }
1037
1038
    /**
1039
     * Returns the target page if visible
1040
     *
1041
     * @param array $targetPage
1042
     *
1043
     * @return array
1044
     */
1045
    protected function getTargetPageIfVisible(array $targetPage): array
1046
    {
1047
        return !(bool)($targetPage['hidden'] ?? false) ? $targetPage : [];
1048
    }
1049
1050
    /**
1051
     * Creates the search box
1052
     *
1053
     * @return string HTML for the search box
1054
     */
1055
    protected function getSearchBox(): string
1056
    {
1057
        if (!$this->getBackendUser()->check('modules', 'web_list')) {
1058
            return '';
1059
        }
1060
        $lang = $this->getLanguageService();
1061
        $listModule = $this->uriBuilder->buildUriFromRoute('web_list', ['id' => $this->id]);
1062
        // Make level selector:
1063
        $opt = [];
1064
1065
        // "New" generation of search levels ... based on TS config
1066
        $config = BackendUtility::getPagesTSconfig($this->id);
1067
        $searchLevelsFromTSconfig = $config['mod.']['web_list.']['searchLevel.']['items.'];
1068
        $searchLevelItems = [];
1069
1070
        // get translated labels for search levels from pagets
1071
        foreach ($searchLevelsFromTSconfig as $keySearchLevel => $labelConfigured) {
1072
            $label = $lang->sL('LLL:' . $labelConfigured);
1073
            if ($label === '') {
1074
                $label = $labelConfigured;
1075
            }
1076
            $searchLevelItems[$keySearchLevel] = $label;
1077
        }
1078
1079
        foreach ($searchLevelItems as $kv => $label) {
1080
            $opt[] = '<option value="' . $kv . '"' . ($kv === 0 ? ' selected="selected"' : '') . '>'
1081
                . htmlspecialchars($label)
1082
                . '</option>';
1083
        }
1084
        $searchLevelLabel = $lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.title.search_levels');
1085
        $searchStringLabel = $lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.label.searchString');
1086
        $lMenu = '<select class="form-control" name="search_levels" title="' . htmlspecialchars($searchLevelLabel) . '" id="search_levels">' . implode('', $opt) . '</select>';
1087
        return '<div class="db_list-searchbox-form db_list-searchbox-toolbar module-docheader-bar module-docheader-bar-search t3js-module-docheader-bar t3js-module-docheader-bar-search" id="db_list-searchbox-toolbar" style="display: none;">
1088
			<form action="' . htmlspecialchars((string)$listModule) . '" method="post">
1089
                <div id="typo3-dblist-search">
1090
                    <div class="panel panel-default">
1091
                        <div class="panel-body">
1092
                            <div class="row">
1093
                                <div class="form-group col-xs-12">
1094
                                    <label for="search_field">' . htmlspecialchars($searchStringLabel) . ': </label>
1095
									<input class="form-control" type="search" placeholder="' . htmlspecialchars($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.enterSearchString')) . '" title="' . htmlspecialchars($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.title.searchString')) . '" name="search_field" id="search_field" value="" />
1096
                                </div>
1097
                                <div class="form-group col-xs-12 col-sm-6">
1098
									<label for="search_levels">' . htmlspecialchars($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.label.search_levels')) . ': </label>
1099
									' . $lMenu . '
1100
                                </div>
1101
                                <div class="form-group col-xs-12 col-sm-6">
1102
									<label for="showLimit">' . htmlspecialchars($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.label.limit')) . ': </label>
1103
									<input class="form-control" type="number" min="0" max="10000" placeholder="10" title="' . htmlspecialchars($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.title.limit')) . '" name="showLimit" id="showLimit" value="" />
1104
                                </div>
1105
                                <div class="form-group col-xs-12">
1106
                                    <div class="form-control-wrap">
1107
                                        <button type="submit" class="btn btn-default" name="search" title="' . htmlspecialchars($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.title.search')) . '">
1108
                                            ' . $this->iconFactory->getIcon('actions-search', Icon::SIZE_SMALL)->render() . ' ' . htmlspecialchars($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.search')) . '
1109
                                        </button>
1110
                                    </div>
1111
                                </div>
1112
                            </div>
1113
                        </div>
1114
                    </div>
1115
                </div>
1116
            </form>
1117
        </div>';
1118
    }
1119
}
1120