PageLayoutController.php 68.4 KB
Newer Older
1
2
3
<?php
namespace TYPO3\CMS\Backend\Controller;

4
/*
5
 * This file is part of the TYPO3 CMS project.
6
 *
7
8
9
 * It is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License, either version 2
 * of the License, or any later version.
10
 *
11
12
 * For the full copyright and license information, please read the
 * LICENSE.txt file that was distributed with this source code.
13
 *
14
15
 * The TYPO3 project - inspiring people to share!
 */
16

17
18
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
19
20
21
22
23
use TYPO3\CMS\Backend\Form\Exception\AccessDeniedException;
use TYPO3\CMS\Backend\Form\FormDataCompiler;
use TYPO3\CMS\Backend\Form\FormDataGroup\TcaDatabaseRecord;
use TYPO3\CMS\Backend\Form\FormResultCompiler;
use TYPO3\CMS\Backend\Form\NodeFactory;
24
25
26
27
use TYPO3\CMS\Backend\Module\ModuleLoader;
use TYPO3\CMS\Backend\Template\Components\ButtonBar;
use TYPO3\CMS\Backend\Template\ModuleTemplate;
use TYPO3\CMS\Backend\Tree\View\ContentLayoutPagePositionMap;
Nicole Cordes's avatar
Nicole Cordes committed
28
use TYPO3\CMS\Backend\Utility\BackendUtility;
29
30
31
use TYPO3\CMS\Backend\View\BackendLayoutView;
use TYPO3\CMS\Backend\View\PageLayoutView;
use TYPO3\CMS\Core\DataHandling\DataHandler;
32
33
use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Imaging\IconFactory;
34
35
use TYPO3\CMS\Core\Messaging\FlashMessage;
use TYPO3\CMS\Core\Messaging\FlashMessageService;
36
use TYPO3\CMS\Core\Page\PageRenderer;
37
use TYPO3\CMS\Core\Type\Bitmask\Permission;
Nicole Cordes's avatar
Nicole Cordes committed
38
use TYPO3\CMS\Core\Utility\GeneralUtility;
39
use TYPO3\CMS\Core\Utility\HttpUtility;
Nicole Cordes's avatar
Nicole Cordes committed
40
use TYPO3\CMS\Core\Utility\MathUtility;
41
use TYPO3\CMS\Core\Versioning\VersionState;
42
use TYPO3\CMS\Fluid\View\StandaloneView;
43
use TYPO3\CMS\Fluid\ViewHelpers\Be\InfoboxViewHelper;
44
use TYPO3\CMS\Frontend\Page\PageRepository;
45
use TYPO3\CMS\Recordlist\RecordList;
Nicole Cordes's avatar
Nicole Cordes committed
46

47
48
49
/**
 * Script Class for Web > Layout module
 */
50
51
class PageLayoutController
{
52

53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
    /**
     * Page Id for which to make the listing
     *
     * @var int
     */
    public $id;

    /**
     * Pointer - for browsing list of records.
     *
     * @var int
     */
    public $pointer;

    /**
     * Thumbnails or not
     *
     * @var string
     */
    public $imagemode;

    /**
     * Search-fields
     *
     * @var string
     */
    public $search_field;

    /**
     * Search-levels
     *
     * @var int
     */
    public $search_levels;

    /**
     * Show-limit
     *
     * @var int
     */
    public $showLimit;

    /**
     * Return URL
     *
     * @var string
     */
    public $returnUrl;

    /**
     * Clear-cache flag - if set, clears page cache for current id.
     *
     * @var bool
     */
    public $clear_cache;

    /**
     * PopView id - for opening a window with the page
     *
     * @var bool
     */
    public $popView;

    /**
     * QuickEdit: Variable, that tells quick edit what to show/edit etc.
     * Format is [tablename]:[uid] with some exceptional values for both parameters (with special meanings).
     *
     * @var string
     */
    public $edit_record;

    /**
     * QuickEdit: If set, this variable tells quick edit that the last edited record had
     * this value as UID and we should look up the new, real uid value in sys_log.
     *
     * @var string
     */
    public $new_unique_uid;

    /**
     * Page select perms clause
     *
     * @var string
     */
    public $perms_clause;

    /**
     * Module TSconfig
     *
     * @var array
     */
    public $modTSconfig;

    /**
     * Module shared TSconfig
     *
     * @var array
     */
    public $modSharedTSconfig;

    /**
     * Current ids page record
     *
     * @var array
     */
    public $pageinfo;

    /**

     * "Pseudo" Description -table name
     *
     * @var string
     */
    public $descrTable;

    /**
     * List of column-integers to edit. Is set from TSconfig, default is "1,0,2,3"
     *
     * @var string
     */
    public $colPosList;

    /**
     * Flag: If content can be edited or not.
     *
     * @var bool
     */
    public $EDIT_CONTENT;

    /**
     * Users permissions integer for this page.
     *
     * @var int
     */
    public $CALC_PERMS;

    /**
     * Currently selected language for editing content elements
     *
     * @var int
     */
    public $current_sys_language;

    /**
     * Module configuration
     *
     * @var array
     */
    public $MCONF = array();

    /**
     * Menu configuration
     *
     * @var array
     */
    public $MOD_MENU = array();

    /**
     * Module settings (session variable)
     *
     * @var array
     */
    public $MOD_SETTINGS = array();

    /**
     * Array of tables to be listed by the Web > Page module in addition to the default tables
     *
     * @var array
     */
    public $externalTables = array();

    /**
     * Module output accumulation
     *
     * @var string
     */
    public $content;

    /**
     * List of column-integers accessible to the current BE user.
     * Is set from TSconfig, default is $colPosList
     *
     * @var string
     */
    public $activeColPosList;

    /**
     * @var array
     */
    protected $eRParts = array();

    /**
     * @var string
     */
    protected $editSelect;

    /**
     * @var bool
     */
    protected $deleteButton;

    /**
     * @var bool
     */
    protected $undoButton;

    /**
     * @var array
     */
    protected $undoButtonR;

    /**
     * @var string
     */
    protected $R_URI;

    /**
     * @var string
     */
    protected $closeUrl;

274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
    /**
     * Caches the available languages in a colPos
     *
     * @var array
     */
    protected $languagesInColumnCache = array();

    /**
     * Caches the amount of content elements as a matrix
     *
     * @var array
     * @internal
     */
    public $contentElementCache = array();

289
290
291
292
293
294
295
296
297
298
299
300
    /**
     * @var IconFactory
     */
    protected $iconFactory;

    /**
     * The name of the module
     *
     * @var string
     */
    protected $moduleName = 'web_layout';

301
302
303
304
305
306
307
308
309
310
    /**
     * @var ModuleTemplate
     */
    protected $moduleTemplate;

    /**
     * @var ButtonBar
     */
    protected $buttonBar;

311
312
313
314
315
316
317
    /**
     * Initializing the module
     *
     * @return void
     */
    public function init()
    {
318
        $this->moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class);
319
        $this->iconFactory = $this->moduleTemplate->getIconFactory();
320
        $this->buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
        $this->getLanguageService()->includeLLFile('EXT:backend/Resources/Private/Language/locallang_layout.xlf');
        // Setting module configuration / page select clause
        $this->MCONF['name'] = $this->moduleName;
        $this->perms_clause = $this->getBackendUser()->getPagePermsClause(1);
        // Get session data
        $sessionData = $this->getBackendUser()->getSessionData(RecordList::class);
        $this->search_field = !empty($sessionData['search_field']) ? $sessionData['search_field'] : '';
        // GPvars:
        $this->id = (int)GeneralUtility::_GP('id');
        $this->pointer = GeneralUtility::_GP('pointer');
        $this->imagemode = GeneralUtility::_GP('imagemode');
        $this->clear_cache = GeneralUtility::_GP('clear_cache');
        $this->popView = GeneralUtility::_GP('popView');
        $this->edit_record = GeneralUtility::_GP('edit_record');
        $this->new_unique_uid = GeneralUtility::_GP('new_unique_uid');
        $this->search_field = GeneralUtility::_GP('search_field');
        $this->search_levels = GeneralUtility::_GP('search_levels');
        $this->showLimit = GeneralUtility::_GP('showLimit');
        $this->returnUrl = GeneralUtility::sanitizeLocalUrl(GeneralUtility::_GP('returnUrl'));
        $this->externalTables = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['cms']['db_layout']['addTables'];
        $sessionData['search_field'] = $this->search_field;
        // Store session data
        $this->getBackendUser()->setAndSaveSessionData(RecordList::class, $sessionData);
        // Load page info array:
        $this->pageinfo = BackendUtility::readPageAccess($this->id, $this->perms_clause);
        // Initialize menu
        $this->menuConfig();
        // Setting sys language from session var:
        $this->current_sys_language = (int)$this->MOD_SETTINGS['language'];
        // CSH / Descriptions:
        $this->descrTable = '_MOD_' . $this->moduleName;
    }

    /**
     * Initialize menu array
     *
     * @return void
     */
    public function menuConfig()
    {
        $lang = $this->getLanguageService();
        // MENU-ITEMS:
        $this->MOD_MENU = array(
            'tt_content_showHidden' => '',
            'function' => array(
                0 => $lang->getLL('m_function_0'),
                1 => $lang->getLL('m_function_1'),
                2 => $lang->getLL('m_function_2')
            ),
            'language' => array(
                0 => $lang->getLL('m_default')
            )
        );
        // example settings:
375
376
377
378
379
        //  $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['cms']['db_layout']['addTables']['tx_myext'] =
        //      array ('default' => array(
        //              'MENU' => 'LLL:EXT:tx_myext/locallang_db.xlf:menuDefault',
        //              'fList' =>  'title,description,image',
        //              'icon' => TRUE));
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
        if (is_array($this->externalTables)) {
            foreach ($this->externalTables as $table => $tableSettings) {
                // delete the default settings from above
                if (is_array($this->MOD_MENU[$table])) {
                    unset($this->MOD_MENU[$table]);
                }
                if (is_array($tableSettings) && count($tableSettings) > 1) {
                    foreach ($tableSettings as $key => $settings) {
                        $this->MOD_MENU[$table][$key] = $lang->sL($settings['MENU']);
                    }
                }
            }
        }
        // First, select all pages_language_overlay records on the current page. Each represents a possibility for a language on the page. Add these to language selector.
        $res = $this->exec_languageQuery($this->id);
        while ($lRow = $this->getDatabaseConnection()->sql_fetch_assoc($res)) {
            if ($this->getBackendUser()->checkLanguageAccess($lRow['uid'])) {
                $this->MOD_MENU['language'][$lRow['uid']] = $lRow['hidden'] ? '(' . $lRow['title'] . ')' : $lRow['title'];
            }
        }
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
        // Setting alternative default label:
        if (($this->modSharedTSconfig['properties']['defaultLanguageLabel'] || $this->modTSconfig['properties']['defaultLanguageLabel']) && isset($this->MOD_MENU['language'][0])) {
            $this->MOD_MENU['language'][0] = $this->modTSconfig['properties']['defaultLanguageLabel'] ? $this->modSharedTSconfig['properties']['defaultLanguageLabel'] : $this->modSharedTSconfig['properties']['defaultLanguageLabel'];
        }
        // Clean up settings
        $this->MOD_SETTINGS = BackendUtility::getModuleData($this->MOD_MENU, GeneralUtility::_GP('SET'), $this->moduleName);
        // For all elements to be shown in draft workspaces & to also show hidden elements by default if user hasn't disabled the option
        if ($this->getBackendUser()->workspace != 0 || $this->MOD_SETTINGS['tt_content_showHidden'] !== '0') {
            $this->MOD_SETTINGS['tt_content_showHidden'] = 1;
        }
        $this->makeActionMenu();
    }

    /**
     * This creates the dropdown menu with the different actions this module is able to provide.
     * For now they are Columns, Quick Edit and Languages.
     *
     * @return void
     */
    protected function makeActionMenu()
    {
        $availableActionArray = array(
            0 => $this->getLanguageService()->getLL('m_function_0'),
            1 => $this->getLanguageService()->getLL('m_function_1'),
            2 => $this->getLanguageService()->getLL('m_function_2')
        );
426
427
428
        // Find if there are ANY languages at all (and if not, remove the language option from function menu).
        $count = $this->getDatabaseConnection()->exec_SELECTcountRows('uid', 'sys_language', $this->getBackendUser()->isAdmin() ? '' : 'hidden=0');
        if (!$count) {
429
            unset($availableActionArray['2']);
430
431
432
433
434
        }
        // page/be_user TSconfig settings and blinding of menu-items
        $this->modSharedTSconfig = BackendUtility::getModTSconfig($this->id, 'mod.SHARED');
        $this->modTSconfig = BackendUtility::getModTSconfig($this->id, 'mod.' . $this->moduleName);
        if ($this->modTSconfig['properties']['QEisDefault']) {
435
            ksort($availableActionArray);
436
        }
437
        $availableActionArray = BackendUtility::unsetMenuItems($this->modTSconfig['properties'], $availableActionArray, 'menu.function');
438
439
        // Remove QuickEdit as option if page type is not...
        if (!GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['FE']['content_doktypes'] . ',6', $this->pageinfo['doktype'])) {
440
            unset($availableActionArray[0]);
441
        }
442
443
444
445
        $actionMenu = $this->moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->makeMenu();
        $actionMenu->setIdentifier('actionMenu');
        $actionMenu->setLabel('');

446
        $defaultKey = null;
447
        $foundDefaultKey = false;
448
449
450
451
452
        foreach ($availableActionArray as $key => $action) {
            $menuItem = $actionMenu
                ->makeMenuItem()
                ->setTitle($action)
                ->setHref(BackendUtility::getModuleUrl($this->moduleName) . '&id=' . $this->id . '&SET[function]=' . $key);
453

454
            if (!$foundDefaultKey) {
455
                $defaultKey = $key;
456
                $foundDefaultKey = true;
457
            }
458
459
            if ((int)$this->MOD_SETTINGS['function'] === $key) {
                $menuItem->setActive(true);
460
                $defaultKey = null;
461
462
            }
            $actionMenu->addMenuItem($menuItem);
463
        }
464
465
466
        if (isset($defaultKey)) {
            $this->MOD_SETTINGS['function'] = $defaultKey;
        }
467
        $this->moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->addMenu($actionMenu);
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
    }

    /**
     * Clears page cache for the current id, $this->id
     *
     * @return void
     */
    public function clearCache()
    {
        if ($this->clear_cache) {
            $tce = GeneralUtility::makeInstance(DataHandler::class);
            $tce->stripslashes_values = false;
            $tce->start(array(), array());
            $tce->clear_cacheCmd($this->id);
        }
    }

    /**
     * Generate the flashmessages for current pid
     *
     * @return string HTML content with flashmessages
     */
    protected function getHeaderFlashMessagesForCurrentPid()
    {
        $content = '';
        $lang = $this->getLanguageService();
494

495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
        // If page is a folder
        if ($this->pageinfo['doktype'] == PageRepository::DOKTYPE_SYSFOLDER) {
            $moduleLoader = GeneralUtility::makeInstance(ModuleLoader::class);
            $moduleLoader->load($GLOBALS['TBE_MODULES']);
            $modules = $moduleLoader->modules;
            if (is_array($modules['web']['sub']['list'])) {
                $title = $lang->getLL('goToListModule');
                $message = '<p>' . $lang->getLL('goToListModuleMessage') . '</p>';
                $message .= '<a class="btn btn-info" href="javascript:top.goToModule(\'web_list\',1);">' . $lang->getLL('goToListModule') . '</a>';
                $view = GeneralUtility::makeInstance(StandaloneView::class);
                $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Templates/InfoBox.html'));
                $view->assignMultiple(array(
                    'title' => $title,
                    'message' => $message,
                    'state' => InfoboxViewHelper::STATE_INFO
                ));
                $content .= $view->render();
            }
        }
        // If content from different pid is displayed
        if ($this->pageinfo['content_from_pid']) {
            $contentPage = BackendUtility::getRecord('pages', (int)$this->pageinfo['content_from_pid']);
            $linkToPid = $this->local_linkThisScript(array('id' => $this->pageinfo['content_from_pid']));
518
            $title = BackendUtility::getRecordTitle('pages', $contentPage);
519
            $link = '<a href="' . $linkToPid . '">' . htmlspecialchars($title) . ' (PID ' . (int)$this->pageinfo['content_from_pid'] . ')</a>';
520
521
522
523
524
525
526
527
528
            $message = sprintf($lang->getLL('content_from_pid_title'), $link);
            $view = GeneralUtility::makeInstance(StandaloneView::class);
            $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Templates/InfoBox.html'));
            $view->assignMultiple(array(
                'title' => $title,
                'message' => $message,
                'state' => InfoboxViewHelper::STATE_INFO
            ));
            $content .= $view->render();
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
        }
        return $content;
    }

    /**
     *
     * @return string $title
     */
    protected function getLocalizedPageTitle()
    {
        if ($this->current_sys_language > 0) {
            $overlayRecord = $this->getDatabaseConnection()->exec_SELECTgetSingleRow(
                'title',
                'pages_language_overlay',
                'pid = ' . (int)$this->id .
544
545
546
                ' AND sys_language_uid = ' . (int)$this->current_sys_language .
                BackendUtility::deleteClause('pages_language_overlay') .
                BackendUtility::versioningPlaceholderClause('pages_language_overlay'),
547
548
                '',
                '',
549
                ''
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
            );
            return $overlayRecord['title'];
        } else {
            return $this->pageinfo['title'];
        }
    }

    /**
     * Injects the request object for the current request or subrequest
     * As this controller goes only through the main() method, it is rather simple for now
     *
     * @param ServerRequestInterface $request the current request
     * @param ResponseInterface $response
     * @return ResponseInterface the response with the content
     */
    public function mainAction(ServerRequestInterface $request, ResponseInterface $response)
    {
        $GLOBALS['SOBE'] = $this;
        $this->init();
        $this->clearCache();
        $this->main();
571
        $response->getBody()->write($this->moduleTemplate->renderContent());
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
        return $response;
    }

    /**
     * Main function.
     * Creates some general objects and calls other functions for the main rendering of module content.
     *
     * @return void
     */
    public function main()
    {
        $lang = $this->getLanguageService();
        // Access check...
        // The page will show only if there is a valid page and if this page may be viewed by the user
        $access = is_array($this->pageinfo) ? 1 : 0;
587
588
        // Content
        $content = '';
589
590
591
592
593
        if ($this->id && $access) {
            // Initialize permission settings:
            $this->CALC_PERMS = $this->getBackendUser()->calcPerms($this->pageinfo);
            $this->EDIT_CONTENT = $this->pageIsNotLockedForEditors();

594
595
            $this->moduleTemplate->getDocHeaderComponent()->setMetaInformation($this->pageinfo);

596
            // override the default jumpToUrl
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
            $this->moduleTemplate->addJavaScriptCode('jumpToUrl', '
                function jumpToUrl(URL,formEl) {
                    if (document.editform && TBE_EDITOR.isFormChanged)  {   // Check if the function exists... (works in all browsers?)
                        if (!TBE_EDITOR.isFormChanged()) {
                            window.location.href = URL;
                        } else if (formEl) {
                            if (formEl.type=="checkbox") formEl.checked = formEl.checked ? 0 : 1;
                        }
                    } else {
                        window.location.href = URL;
                    }
                }
            ');
            $this->moduleTemplate->addJavaScriptCode('mainJsFunctions', '
                if (top.fsMod) {
                    top.fsMod.recentIds["web"] = ' . (int)$this->id . ';
                    top.fsMod.navFrameHighlightedID["web"] = "pages' . (int)$this->id . '_"+top.fsMod.currentBank; ' . (int)$this->id . ';
                }
                ' . ($this->popView ? BackendUtility::viewOnClick($this->id, '', BackendUtility::BEgetRootLine($this->id)) : '') . '
                function deleteRecord(table,id,url) {   //
                    if (confirm(' . GeneralUtility::quoteJSvalue($lang->getLL('deleteWarning')) . ')) {
                        window.location.href = ' . GeneralUtility::quoteJSvalue(BackendUtility::getModuleUrl('tce_db') . '&cmd[') . '+table+"]["+id+"][delete]=1&redirect="+escape(url)+"&vC=' . $this->getBackendUser()->veriCode() . '&prErr=1&uPT=1";
                    }
                    return false;
                }
            ');

624
            // Setting doc-header
625
626
627
628
            $this->moduleTemplate->setForm(
                '<form action="' . htmlspecialchars(BackendUtility::getModuleUrl($this->moduleName, array('id' => $this->id, 'imagemode' =>  $this->imagemode))) . '" method="post">'
            );

629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
            // Find backend layout / coumns
            $backendLayout = GeneralUtility::callUserFunction(BackendLayoutView::class . '->getSelectedBackendLayout', $this->id, $this);
            if (!empty($backendLayout['__colPosList'])) {
                $this->colPosList = implode(',', $backendLayout['__colPosList']);
            }
            // Removing duplicates, if any
            $this->colPosList = array_unique(GeneralUtility::intExplode(',', $this->colPosList));
            // Accessible columns
            if (isset($this->modSharedTSconfig['properties']['colPos_list']) && trim($this->modSharedTSconfig['properties']['colPos_list']) !== '') {
                $this->activeColPosList = array_unique(GeneralUtility::intExplode(',', trim($this->modSharedTSconfig['properties']['colPos_list'])));
                // Match with the list which is present in the colPosList for the current page
                if (!empty($this->colPosList) && !empty($this->activeColPosList)) {
                    $this->activeColPosList = array_unique(array_intersect(
                        $this->activeColPosList,
                        $this->colPosList
                    ));
                }
            } else {
                $this->activeColPosList = $this->colPosList;
            }
            $this->activeColPosList = implode(',', $this->activeColPosList);
            $this->colPosList = implode(',', $this->colPosList);

652
653
654
            $content .= $this->getHeaderFlashMessagesForCurrentPid();


655
656
657
            // Render the primary module content:
            if ($this->MOD_SETTINGS['function'] == 0) {
                // QuickEdit
658
                $content .= $this->renderQuickEdit();
659
660
            } else {
                // Page title
661
                $content .= '<h1 class="t3js-title-inlineedit">' . htmlspecialchars($this->getLocalizedPageTitle()) . '</h1>';
662
                // All other listings
663
                $content .= $this->renderListContent();
664
665
            }

666
667
668
669
            // Setting up the buttons for the docheader
            $this->makeButtons($this->MOD_SETTINGS['function'] == 0 ? 'quickEdit' : '');
            // Create LanguageMenu
            $this->makeLanguageMenu();
670

671
672
673
674
675
676
        } else {
            $this->moduleTemplate->addJavaScriptCode(
                'mainJsFunctions',
                'if (top.fsMod) top.fsMod.recentIds["web"] = ' . (int)$this->id . ';'
            );
            $content .= '<h1>' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'] . '</h1>';
677
678
679
            $view = GeneralUtility::makeInstance(StandaloneView::class);
            $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Templates/InfoBox.html'));
            $view->assignMultiple(array(
680
681
                'title' => $lang->getLL('clickAPage_header'),
                'message' => $lang->getLL('clickAPage_content'),
682
683
                'state' => InfoboxViewHelper::STATE_INFO
            ));
684
            $content .= $view->render();
685
        }
686
687
        // Set content
        $this->moduleTemplate->setContent($content);
688
689
690
691
692
693
694
695
696
697
698
699
700
    }

    /**
     * Rendering the quick-edit view.
     *
     * @return string
     */
    public function renderQuickEdit()
    {
        $databaseConnection = $this->getDatabaseConnection();
        $beUser = $this->getBackendUser();
        $lang = $this->getLanguageService();
        // Alternative form tag; Quick Edit submits its content to tce_db.php.
701
702
703
        $this->moduleTemplate->setForm(
            '<form action="' . htmlspecialchars(BackendUtility::getModuleUrl('tce_db', ['prErr' => 1, 'uPT' => 1])) . '" method="post" enctype="multipart/form-data" name="editform" onsubmit="return TBE_EDITOR.checkSubmit(1);">'
        );
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
        // Set the edit_record value for internal use in this function:
        $edit_record = $this->edit_record;
        // If a command to edit all records in a column is issue, then select all those elements, and redirect to FormEngine
        if (substr($edit_record, 0, 9) == '_EDIT_COL') {
            $res = $databaseConnection->exec_SELECTquery('*', 'tt_content', 'pid=' . (int)$this->id . ' AND colPos=' . (int)substr($edit_record, 10) . ' AND sys_language_uid=' . (int)$this->current_sys_language . ($this->MOD_SETTINGS['tt_content_showHidden'] ? '' : BackendUtility::BEenableFields('tt_content')) . BackendUtility::deleteClause('tt_content') . BackendUtility::versioningPlaceholderClause('tt_content'), '', 'sorting');
            $idListA = array();
            while ($cRow = $databaseConnection->sql_fetch_assoc($res)) {
                $idListA[] = $cRow['uid'];
            }
            $url = BackendUtility::getModuleUrl('record_edit', array(
                'edit[tt_content][' . implode(',', $idListA) . ']' => 'edit',
                'returnUrl' => $this->local_linkThisScript(array('edit_record' => ''))
            ));
            HttpUtility::redirect($url);
        }
        // If the former record edited was the creation of a NEW record, this will look up the created records uid:
        if ($this->new_unique_uid) {
            $res = $databaseConnection->exec_SELECTquery('*', 'sys_log', 'userid=' . (int)$beUser->user['uid'] . ' AND NEWid=' . $databaseConnection->fullQuoteStr($this->new_unique_uid, 'sys_log'));
            $sys_log_row = $databaseConnection->sql_fetch_assoc($res);
            if (is_array($sys_log_row)) {
                $edit_record = $sys_log_row['tablename'] . ':' . $sys_log_row['recuid'];
            }
        }
727
        $edit_record = $this->makeQuickEditMenu($edit_record);
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
        // Splitting the edit-record cmd value into table/uid:
        $this->eRParts = explode(':', $edit_record);
        $tableName = $this->eRParts[0];
        // Delete-button flag?
        $this->deleteButton = MathUtility::canBeInterpretedAsInteger($this->eRParts[1]) && $edit_record && ($tableName !== 'pages' && $this->EDIT_CONTENT || $tableName === 'pages' && $this->CALC_PERMS & Permission::PAGE_DELETE);
        // If undo-button should be rendered (depends on available items in sys_history)
        $this->undoButton = false;
        $undoRes = $databaseConnection->exec_SELECTquery('tstamp', 'sys_history', 'tablename=' . $databaseConnection->fullQuoteStr($tableName, 'sys_history') . ' AND recuid=' . (int)$this->eRParts[1], '', 'tstamp DESC', '1');
        if ($this->undoButtonR = $databaseConnection->sql_fetch_assoc($undoRes)) {
            $this->undoButton = true;
        }
        // Setting up the Return URL for coming back to THIS script (if links take the user to another script)
        $R_URL_parts = parse_url(GeneralUtility::getIndpEnv('REQUEST_URI'));
        $R_URL_getvars = GeneralUtility::_GET();
        unset($R_URL_getvars['popView']);
        unset($R_URL_getvars['new_unique_uid']);
        $R_URL_getvars['edit_record'] = $edit_record;
        $this->R_URI = $R_URL_parts['path'] . '?' . GeneralUtility::implodeArrayForUrl('', $R_URL_getvars);

        // Creating editing form:
        if ($edit_record) {
            // Splitting uid parts for special features, if new:
            list($uidVal, $neighborRecordUid, $ex_colPos) = explode('/', $this->eRParts[1]);

            if ($uidVal === 'new') {
                $command = 'new';
                // Page id of this new record
                $theUid = $this->id;
                if ($neighborRecordUid) {
                    $theUid = $neighborRecordUid;
                }
            } else {
                $command = 'edit';
                $theUid = $uidVal;
                // Convert $uidVal to workspace version if any:
                $draftRecord = BackendUtility::getWorkspaceVersionOfRecord($beUser->workspace, $tableName, $theUid, 'uid');
                if ($draftRecord) {
                    $theUid = $draftRecord['uid'];
                }
            }

            // @todo: Hack because DatabaseInitializeNewRow reads from _GP directly
            $GLOBALS['_GET']['defVals'][$tableName] = array(
                'colPos' => (int)$ex_colPos,
                'sys_language_uid' => (int)$this->current_sys_language
            );

            /** @var TcaDatabaseRecord $formDataGroup */
            $formDataGroup = GeneralUtility::makeInstance(TcaDatabaseRecord::class);
            /** @var FormDataCompiler $formDataCompiler */
            $formDataCompiler = GeneralUtility::makeInstance(FormDataCompiler::class, $formDataGroup);
            /** @var NodeFactory $nodeFactory */
            $nodeFactory = GeneralUtility::makeInstance(NodeFactory::class);

            try {
                $formDataCompilerInput = [
                    'tableName' => $tableName,
                    'vanillaUid' => (int)$theUid,
                    'command' => $command,
                ];
                $formData = $formDataCompiler->compile($formDataCompilerInput);

                if ($command !== 'new') {
                    BackendUtility::lockRecords($tableName, $formData['databaseRow']['uid'], $tableName === 'tt_content' ? $formData['databaseRow']['pid'] : 0);
                }

                $formData['renderType'] = 'outerWrapContainer';
                $formResult = $nodeFactory->create($formData)->render();

                $panel = $formResult['html'];
                $formResult['html'] = '';

                /** @var FormResultCompiler $formResultCompiler */
                $formResultCompiler = GeneralUtility::makeInstance(FormResultCompiler::class);
                $formResultCompiler->mergeResult($formResult);

                $row = $formData['databaseRow'];
                $new_unique_uid = '';
                if ($command === 'new') {
                    $new_unique_uid = $row['uid'];
                }

                // Add hidden fields:
                if ($uidVal == 'new') {
                    $panel .= '<input type="hidden" name="data[' . $tableName . '][' . $row['uid'] . '][pid]" value="' . $row['pid'] . '" />';
                }
814
815
816
817
                $redirect = ($uidVal == 'new' ? BackendUtility::getModuleUrl(
                    $this->moduleName,
                    ['id' => $this->id,'new_unique_uid' => $new_unique_uid,'returnUrl' => $this->returnUrl]
                ) : $this->R_URI);
818
                $panel .= '
819
820
821
822
                    <input type="hidden" name="_serialNumber" value="' . md5(microtime()) . '" />
                    <input type="hidden" name="edit_record" value="' . $edit_record . '" />
                    <input type="hidden" name="redirect" value="' . htmlspecialchars($redirect) . '" />
                    ';
823
                // Add JavaScript as needed around the form:
824
                $content = $formResultCompiler->JStop() . $panel . $formResultCompiler->printNeededJSFunctions();
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840

                // Display "is-locked" message:
                if ($command === 'edit') {
                    $lockInfo = BackendUtility::isRecordLocked($tableName, $formData['databaseRow']['uid']);
                    if ($lockInfo) {
                        /** @var \TYPO3\CMS\Core\Messaging\FlashMessage $flashMessage */
                        $flashMessage = GeneralUtility::makeInstance(FlashMessage::class, htmlspecialchars($lockInfo['msg']), '', FlashMessage::WARNING);
                        /** @var $flashMessageService \TYPO3\CMS\Core\Messaging\FlashMessageService */
                        $flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class);
                        /** @var $defaultFlashMessageQueue \TYPO3\CMS\Core\Messaging\FlashMessageQueue */
                        $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
                        $defaultFlashMessageQueue->enqueue($flashMessage);
                    }
                }
            } catch (AccessDeniedException $e) {
                // If no edit access, print error message:
841
                $content = $this->moduleTemplate->section($lang->getLL('noAccess'), $lang->getLL('noAccess_msg')
842
                    . '<br /><br />'
843
                    . ($beUser->errorMsg ? 'Reason: ' . $beUser->errorMsg . '<br /><br />' : ''), 0, 1);
844
845
846
            }
        } else {
            // If no edit access, print error message:
847
            $content = $this->moduleTemplate->section($lang->getLL('noAccess'), $lang->getLL('noAccess_msg'), 0, 1);
848
849
        }

850
        // Element selection matrix:
851
        if ($tableName === 'tt_content' && MathUtility::canBeInterpretedAsInteger($this->eRParts[1])) {
852
853
            $content .= '<h2>' . $lang->getLL('CEonThisPage') . '</h2>';
            // PositionMap
854
855
            $posMap = GeneralUtility::makeInstance(ContentLayoutPagePositionMap::class);
            $posMap->cur_sys_language = $this->current_sys_language;
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
            $content .= $posMap->printContentElementColumns(
                $this->id,
                $this->eRParts[1],
                $this->colPosList,
                $this->MOD_SETTINGS['tt_content_showHidden'],
                $this->R_URI
            );
            // Toggle hidden ContentElements
            $numberOfHiddenElements = $this->getNumberOfHiddenElements();
            if ($numberOfHiddenElements) {
                $content .= '<div class="checkbox">';
                $content .= '<label for="checkTt_content_showHidden">';
                $content .= BackendUtility::getFuncCheck($this->id, 'SET[tt_content_showHidden]', $this->MOD_SETTINGS['tt_content_showHidden'], '', '', 'id="checkTt_content_showHidden"');
                $content .= (!$numberOfHiddenElements ? ('<span class="text-muted">' . $lang->getLL('hiddenCE', true) . '</span>') : $lang->getLL('hiddenCE', true) . ' (' . $numberOfHiddenElements . ')');
                $content .= '</label>';
                $content .= '</div>';
            }
            // CSH
            $content .= BackendUtility::cshItem($this->descrTable, 'quickEdit_selElement');
875
876
877
878
879
880
881
882
883
884
885
886
        }

        return $content;
    }

    /**
     * Rendering all other listings than QuickEdit
     *
     * @return string
     */
    public function renderListContent()
    {
887
888
        $this->moduleTemplate->getPageRenderer()->loadJquery();
        $this->moduleTemplate->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/ClickMenu');
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
        /** @var $dbList \TYPO3\CMS\Backend\View\PageLayoutView */
        $dbList = GeneralUtility::makeInstance(PageLayoutView::class);
        $dbList->thumbs = $this->imagemode;
        $dbList->no_noWrap = 1;
        $dbList->descrTable = $this->descrTable;
        $this->pointer = MathUtility::forceIntegerInRange($this->pointer, 0, 100000);
        $dbList->script = BackendUtility::getModuleUrl($this->moduleName);
        $dbList->showIcon = 0;
        $dbList->setLMargin = 0;
        $dbList->doEdit = $this->EDIT_CONTENT;
        $dbList->ext_CALC_PERMS = $this->CALC_PERMS;
        $dbList->agePrefixes = $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.minutesHoursDaysYears');
        $dbList->id = $this->id;
        $dbList->nextThree = MathUtility::forceIntegerInRange($this->modTSconfig['properties']['editFieldsAtATime'], 0, 10);
        $dbList->option_newWizard = $this->modTSconfig['properties']['disableNewContentElementWizard'] ? 0 : 1;
        $dbList->defLangBinding = $this->modTSconfig['properties']['defLangBinding'] ? 1 : 0;
        if (!$dbList->nextThree) {
            $dbList->nextThree = 1;
        }
        $dbList->externalTables = $this->externalTables;
        // Create menu for selecting a table to jump to (this is, if more than just pages/tt_content elements are found on the page!)
        // also fills $dbList->activeTables
        $dbList->getTableMenu($this->id);
        // Initialize other variables:
        $tableOutput = array();
        $tableJSOutput = array();
        $CMcounter = 0;
        // Traverse the list of table names which has records on this page (that array is populated
        // by the $dblist object during the function getTableMenu()):
        foreach ($dbList->activeTables as $table => $value) {
919
            $h_func = '';
920
921
            $h_func_b = '';
            if (!isset($dbList->externalTables[$table])) {
922
923
924
925
926
927
928
929
930
931
                // Toggle hidden ContentElements
                $numberOfHiddenElements = $this->getNumberOfHiddenElements();
                if ($numberOfHiddenElements > 0) {
                    $h_func_b = '
                        <div class="checkbox">
                            <label for="checkTt_content_showHidden">
                                <input type="checkbox" id="checkTt_content_showHidden" class="checkbox" name="SET[tt_content_showHidden]" value="1" ' . ($this->MOD_SETTINGS['tt_content_showHidden'] ? 'checked="checked"' : '') . ' />
                                ' . $this->getLanguageService()->getLL('hiddenCE', true) . ' (<span class="t3js-hidden-counter">' . $numberOfHiddenElements . '</span>)
                            </label>
                        </div>';
932
                }
933

934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
                // Boolean: Display up/down arrows and edit icons for tt_content records
                $dbList->tt_contentConfig['showCommands'] = 1;
                // Boolean: Display info-marks or not
                $dbList->tt_contentConfig['showInfo'] = 1;
                // Setting up the tt_content columns to show:
                if (is_array($GLOBALS['TCA']['tt_content']['columns']['colPos']['config']['items'])) {
                    $colList = array();
                    $tcaItems = GeneralUtility::callUserFunction(BackendLayoutView::class . '->getColPosListItemsParsed', $this->id, $this);
                    foreach ($tcaItems as $temp) {
                        $colList[] = $temp[1];
                    }
                } else {
                    // ... should be impossible that colPos has no array. But this is the fallback should it make any sense:
                    $colList = array('1', '0', '2', '3');
                }
                if ($this->colPosList !== '') {
                    $colList = array_intersect(GeneralUtility::intExplode(',', $this->colPosList), $colList);
                }
                // The order of the rows: Default is left(1), Normal(0), right(2), margin(3)
                $dbList->tt_contentConfig['cols'] = implode(',', $colList);
                $dbList->tt_contentConfig['activeCols'] = $this->activeColPosList;
                $dbList->tt_contentConfig['showHidden'] = $this->MOD_SETTINGS['tt_content_showHidden'];
                $dbList->tt_contentConfig['sys_language_uid'] = (int)$this->current_sys_language;
                // If the function menu is set to "Language":
                if ($this->MOD_SETTINGS['function'] == 2) {
                    $dbList->tt_contentConfig['languageMode'] = 1;
                    $dbList->tt_contentConfig['languageCols'] = $this->MOD_MENU['language'];
                    $dbList->tt_contentConfig['languageColsPointer'] = $this->current_sys_language;
                }
            } else {
                if (isset($this->MOD_SETTINGS) && isset($this->MOD_MENU)) {
                    $h_func = BackendUtility::getFuncMenu($this->id, 'SET[' . $table . ']', $this->MOD_SETTINGS[$table], $this->MOD_MENU[$table], '', '');
                }
            }
            // Start the dblist object:
            $dbList->itemsLimitSingleTable = 1000;
            $dbList->start($this->id, $table, $this->pointer, $this->search_field, $this->search_levels, $this->showLimit);
            $dbList->counter = $CMcounter;
            $dbList->ext_function = $this->MOD_SETTINGS['function'];
            // Render versioning selector:
974
            $dbList->HTMLcode .= $this->moduleTemplate->getVersionSelector($this->id);
975
976
977
            // Generate the list of elements here:
            $dbList->generateList();
            // Adding the list content to the tableOutput variable:
978
            $tableOutput[$table] = $h_func .  $dbList->HTMLcode . $h_func_b;
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
            // ... and any accumulated JavaScript goes the same way!
            $tableJSOutput[$table] = $dbList->JScode;
            // Increase global counter:
            $CMcounter += $dbList->counter;
            // Reset variables after operation:
            $dbList->HTMLcode = '';
            $dbList->JScode = '';
        }
        // END: traverse tables
        // For Context Sensitive Menus:
        // Init the content
        $content = '';
        // Additional header content
        $headerContentHook = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/db_layout.php']['drawHeaderHook'];
        if (is_array($headerContentHook)) {
            foreach ($headerContentHook as $hook) {
                $params = array();
                $content .= GeneralUtility::callUserFunction($hook, $params, $this);
            }
        }
        // Add the content for each table we have rendered (traversing $tableOutput variable)
        foreach ($tableOutput as $table => $output) {
1001
            $content .= $output;
1002
1003
1004
1005
        }
        // Making search form:
        if (!$this->modTSconfig['properties']['disableSearchBox'] && !empty($tableOutput)) {
            $this->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/ToggleSearchToolbox');
1006
1007
1008
1009
1010
1011
1012
            $toggleSearchFormButton = $this->buttonBar->makeLinkButton()
                ->setClasses('t3js-toggle-search-toolbox')
                ->setTitle($this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.title.searchIcon', true))
                ->setIcon($this->iconFactory->getIcon('actions-search', Icon::SIZE_SMALL))
                ->setHref('#');
            $this->buttonBar->addButton($toggleSearchFormButton, ButtonBar::BUTTON_POSITION_LEFT, 4);
            $content .= $dbList->getSearchBox(0);
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
        }
        // Additional footer content
        $footerContentHook = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/db_layout.php']['drawFooterHook'];
        if (is_array($footerContentHook)) {
            foreach ($footerContentHook as $hook) {
                $params = array();
                $content .= GeneralUtility::callUserFunction($hook, $params, $this);
            }
        }
        return $content;
    }

1025
1026
1027
1028
1029
1030
1031
1032
    /**
     * @return ModuleTemplate
     */
    public function getModuleTemplate()
    {
        return $this->moduleTemplate;
    }

1033
1034
1035
1036
1037
1038
1039
    /**
     * Print accumulated content of module
     *
     * @return void
     */
    public function printContent()
    {
1040
        echo $this->moduleTemplate->renderContent();
1041
1042
1043
1044
1045
1046
1047
1048
    }

    /***************************
     *
     * Sub-content functions, rendering specific parts of the module content.
     *
     ***************************/
    /**
1049
     * This creates the buttons for die modules
1050
1051
     *
     * @param string $function Identifier for function of module
1052
     * @return void
1053
     */
1054
    protected function makeButtons($function = '')
1055
1056
1057
1058
    {
        $lang = $this->getLanguageService();
        // View page
        if (!VersionState::cast($this->pageinfo['t3ver_state'])->equals(VersionState::DELETE_PLACEHOLDER)) {
1059
1060
1061
1062
1063
1064
1065
            $viewButton = $this->buttonBar->makeLinkButton()
                ->setOnClick(htmlspecialchars(BackendUtility::viewOnClick($this->pageinfo['uid'], '', BackendUtility::BEgetRootLine($this->pageinfo['uid']))))
                ->setTitle($lang->sL('LLL:EXT:lang/locallang_core.xlf:labels.showPage', true))
                ->setIcon($this->iconFactory->getIcon('actions-document-view', Icon::SIZE_SMALL))
                ->setHref('#');

            $this->buttonBar->addButton($viewButton, ButtonBar::BUTTON_POSITION_LEFT, 3);
1066
1067
        }
        // Shortcut
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
        $shortcutButton = $this->buttonBar->makeShortcutButton()
            ->setModuleName($this->moduleName)
            ->setGetVariables([
                'id',
                'M',
                'edit_record',
                'pointer',
                'new_unique_uid',
                'search_field',
                'search_levels',
                'showLimit'
            ])
            ->setSetVariables(array_keys($this->MOD_MENU));
        $this->buttonBar->addButton($shortcutButton);

1083
1084
        // Cache
        if (!$this->modTSconfig['properties']['disableAdvanced']) {
1085
1086
1087
1088
            $clearCacheButton = $this->buttonBar->makeLinkButton()
                ->setHref(BackendUtility::getModuleUrl($this->moduleName, ['id' => $this->pageinfo['uid'], 'clear_cache' => '1']))
                ->setTitle($lang->sL('LLL:EXT:lang/locallang_core.xlf:labels.clear_cache', true))
                ->setIcon($this->iconFactory->getIcon('actions-system-cache-clear', Icon::SIZE_SMALL));
1089
            $this->buttonBar->addButton($clearCacheButton, ButtonBar::BUTTON_POSITION_RIGHT, 1);
1090
1091
1092
1093
1094
1095
1096
1097
1098
        }
        if (!$this->modTSconfig['properties']['disableIconToolbar']) {
            // Move record
            if (MathUtility::canBeInterpretedAsInteger($this->eRParts[1])) {
                $urlParameters = [
                    'table' => $this->eRParts[0],
                    'uid' => $this->eRParts[1],
                    'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
                ];
1099
1100
1101
1102
1103
                $moveButton = $this->buttonBar->makeLinkButton()
                    ->setHref(BackendUtility::getModuleUrl('move_element', $urlParameters))
                    ->setTitle($lang->getLL('move_' . ($this->eRParts[0] == 'tt_content' ? 'record' : 'page'), true))
                    ->setIcon($this->iconFactory->getIcon('actions-' . ($this->eRParts[0] == 'tt_content' ? 'document' : 'page') . '-move', Icon::SIZE_SMALL));
                $this->buttonBar->addButton($moveButton, ButtonBar::BUTTON_POSITION_LEFT, 2);
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
            }

            // Edit page properties and page language overlay icons
            if ($this->pageIsNotLockedForEditors()) {
                // Edit localized page_language_overlay only when one specific language is selected
                if ($this->MOD_SETTINGS['function'] == 1 && $this->current_sys_language > 0) {
                    $overlayRecord = $this->getDatabaseConnection()->exec_SELECTgetSingleRow(
                        'uid',
                        'pages_language_overlay',
                        'pid = ' . (int)$this->id . ' ' .
                        'AND sys_language_uid = ' . (int)$this->current_sys_language .
                        BackendUtility::deleteClause('pages_language_overlay') .
                        BackendUtility::versioningPlaceholderClause('pages_language_overlay'),
                        '',
                        '',
1119
                        ''
1120
                    );
1121
1122
1123
1124
1125
1126
                    $editLanguageButton = $this->buttonBar->makeLinkButton()
                        ->setHref('#')
                        ->setTitle($lang->getLL('editPageLanguageOverlayProperties', true))
                        ->setOnClick(htmlspecialchars(BackendUtility::editOnClick('&edit[pages_language_overlay][' . $overlayRecord['uid'] . ']=edit')))
                        ->setIcon($this->iconFactory->getIcon('mimetypes-x-content-page-language-overlay', Icon::SIZE_SMALL));
                    $this->buttonBar->addButton($editLanguageButton, ButtonBar::BUTTON_POSITION_LEFT, 3);
1127
                }
1128
1129
1130
1131
1132
1133
                $editPageButton = $this->buttonBar->makeLinkButton()
                    ->setHref('#')
                    ->setTitle($lang->getLL('editPageProperties', true))
                    ->setOnClick(htmlspecialchars(BackendUtility::editOnClick('&edit[pages][' . $this->id . ']=edit')))
                    ->setIcon($this->iconFactory->getIcon('actions-page-open', Icon::SIZE_SMALL));
                $this->buttonBar->addButton($editPageButton, ButtonBar::BUTTON_POSITION_LEFT, 3);
1134
1135
1136
            }

            // Add CSH (Context Sensitive Help) icon to tool bar
1137
1138
1139
1140
1141
1142
            $contextSensitiveHelpButton = $this->buttonBar->makeHelpButton()
                ->setModuleName($this->descrTable)
                ->setFieldName(($function === 'quickEdit' ? 'quickEdit' : 'columns_' . $this->MOD_SETTINGS['function']));
            $this->buttonBar->addButton($contextSensitiveHelpButton);

            // QuickEdit
1143
            if ($function == 'quickEdit') {
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
                // Close Record
                $closeButton = $this->buttonBar->makeLinkButton()
                    ->setHref('#')
                    ->setOnClick(htmlspecialchars('jumpToUrl(' . GeneralUtility::quoteJSvalue($this->closeUrl) . '); return false;'))
                    ->setTitle($lang->sL('LLL:EXT:lang/locallang_core.xlf:rm.closeDoc', true))
                    ->setIcon($this->iconFactory->getIcon('actions-document-close', Icon::SIZE_SMALL));
                $this->buttonBar->addButton($closeButton, ButtonBar::BUTTON_POSITION_LEFT, 0);

                // Save Record
                $saveButtonDropdown = $this->buttonBar->makeSplitButton();
                $saveButton = $this->buttonBar->makeInputButton()
                    ->setName('_savedok')
                    ->setValue('1')
                    ->setTitle($lang->sL('LLL:EXT:lang/locallang_core.xlf:rm.saveDoc', true))
                    ->setIcon($this->iconFactory->getIcon('actions-document-save', Icon::SIZE_SMALL));
                $saveButtonDropdown->addItem($saveButton);
                $saveAndCloseButton = $this->buttonBar->makeInputButton()
                    ->setName('_saveandclosedok')
                    ->setValue('1')
                    ->setOnClick('document.editform.redirect.value=\'' . $this->closeUrl . '\';')
                    ->setTitle($lang->sL('LLL:EXT:lang/locallang_core.xlf:rm.saveCloseDoc', true))
                    ->setIcon($this->iconFactory->getIcon('actions-document-save-close', Icon::SIZE_SMALL));
                $saveButtonDropdown->addItem($saveAndCloseButton);
                $saveAndShowPageButton = $this->buttonBar->makeInputButton()
                    ->setName('_savedokview')
                    ->setValue('1')
                    ->setOnClick('document.editform.redirect.value+=\'&popView=1\';')
                    ->setTitle($lang->sL('LLL:EXT:lang/locallang_core.xlf:rm.saveDocShow', true))
                    ->setIcon($this->iconFactory->getIcon('actions-document-save-view', Icon::SIZE_SMALL));
                $saveButtonDropdown->addItem($saveAndShowPageButton);
                $this->buttonBar->addButton($saveButtonDropdown, ButtonBar::BUTTON_POSITION_LEFT, 1);

1176
1177
                // Delete record
                if ($this->deleteButton) {
1178
1179
1180
1181
1182
1183
                    $deleteButton = $this->buttonBar->makeLinkButton()
                        ->setHref('#')
                        ->setOnClick(htmlspecialchars('return deleteRecord(' . GeneralUtility::quoteJSvalue($this->eRParts[0]) . ',' . GeneralUtility::quoteJSvalue($this->eRParts[1]) . ',' . GeneralUtility::quoteJSvalue(GeneralUtility::getIndpEnv('SCRIPT_NAME') . '?id=' . $this->id) . ');'))
                        ->setTitle($lang->getLL('deleteItem', true))
                        ->setIcon($this->iconFactory->getIcon('actions-edit-delete', Icon::SIZE_SMALL));
                    $this->buttonBar->addButton($deleteButton, ButtonBar::BUTTON_POSITION_LEFT, 4);
1184
                }
1185
1186

                // History
1187
                if ($this->undoButton) {
1188
1189
1190
                    $undoButton = $this->buttonBar->makeLinkButton()
                        ->setHref('#')
                        ->setOnClick(htmlspecialchars('window.location.href=' .
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
                            GeneralUtility::quoteJSvalue(
                                BackendUtility::getModuleUrl(
                                    'record_history',
                                    array(
                                        'element' => $this->eRParts[0] . ':' . $this->eRParts[1],
                                        'revert' => 'ALL_FIELDS',
                                        'sumUp' => -1,
                                        'returnUrl' => $this->R_URI,
                                    )
                                )
1201
1202
1203
1204
1205
1206
1207
                            ) . '; return false;'))
                        ->setTitle(htmlspecialchars(sprintf($lang->getLL('undoLastChange'), BackendUtility::calcAge($GLOBALS['EXEC_TIME'] - $this->undoButtonR['tstamp'], $lang->sL('LLL:EXT:lang/locallang_core.xlf:labels.minutesHoursDaysYears')))))
                        ->setIcon($this->iconFactory->getIcon('actions-edit-undo', Icon::SIZE_SMALL));
                    $this->buttonBar->addButton($undoButton, ButtonBar::BUTTON_POSITION_LEFT, 5);
                    $historyButton = $this->buttonBar->makeLinkButton()
                        ->setHref('#')
                        ->setOnClick(htmlspecialchars('jumpToUrl(' .
1208
1209
1210
1211
                            GeneralUtility::quoteJSvalue(
                                BackendUtility::getModuleUrl(
                                    'record_history',
                                    array(
1212
1213
1214
                                            'element' => $this->eRParts[0] . ':' . $this->eRParts[1],
                                            'returnUrl' => $this->R_URI,
                                        )
1215
                                ) . '#latest'
1216
1217
1218
1219
                            ) . ');return false;'))
                        ->setTitle($lang->getLL('recordHistory', true))
                        ->setIcon($this->iconFactory->getIcon('actions-document-history-open', Icon::SIZE_SMALL));
                    $this->buttonBar->addButton($historyButton, ButtonBar::BUTTON_POSITION_LEFT, 3);
1220
                }
1221

1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
            }
        }
    }

    /*******************************
     *
     * Other functions
     *
     ******************************/
    /**
     * Returns the number of hidden elements (including those hidden by start/end times)
     * on the current page (for the current sys_language)
     *
     * @return int
     */
    public function getNumberOfHiddenElements()
    {
        return $this->getDatabaseConnection()->exec_SELECTcountRows(
            'uid',
            'tt_content',
            'pid=' . (int)$this->id . ' AND sys_language_uid=' . (int)$this->current_sys_language . BackendUtility::BEenableFields('tt_content', 1) . BackendUtility::deleteClause('tt_content') . BackendUtility::versioningPlaceholderClause('tt_content')
        );
    }

    /**
     * Returns URL to the current script.
     * In particular the "popView" and "new_unique_uid" Get vars are unset.
     *
     * @param array $params Parameters array, merged with global GET vars.
     * @return string URL
     */
    public function local_linkThisScript($params)
    {
        $params['popView'] = '';
        $params['new_unique_uid'] = '';
        return GeneralUtility::linkThisScript($params);
    }

    /**
     * Returns a SQL query for selecting sys_language records.
     *
     * @param int $id Page id: If zero, the query will select all sys_language records from root level which are NOT hidden. If set to another value, the query will select all sys_language records that has a pages_language_overlay record on that page (and is not hidden, unless you are admin user)
     * @return string Return query string.
     */
    public function exec_languageQuery($id)
    {
        if ($id) {
            $exQ = BackendUtility::deleteClause('pages_language_overlay') .
                ($this->getBackendUser()->isAdmin() ? '' : ' AND sys_language.hidden=0');
            return $this->getDatabaseConnection()->exec_SELECTquery(
                'sys_language.*',
                'pages_language_overlay,sys_language',
                'pages_language_overlay.sys_language_uid=sys_language.uid AND pages_language_overlay.pid=' . (int)$id . $exQ .
1275
                BackendUtility::versioningPlaceholderClause('pages_language_overlay'),
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
                'pages_language_overlay.sys_language_uid,sys_language.uid,sys_language.pid,sys_language.tstamp,sys_language.hidden,sys_language.title,sys_language.language_isocode,sys_language.static_lang_isocode,sys_language.flag',
                'sys_language.title'
            );
        } else {
            return $this->getDatabaseConnection()->exec_SELECTquery(
                'sys_language.*',
                'sys_language',
                'sys_language.hidden=0',
                '',
                'sys_language.title'
            );
        }
    }

1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
    /**
     * Get used languages in a colPos of a page
     *
     * @param int $pageId
     * @param int $colPos
     * @return bool|\mysqli_result|object
     */
    public function getUsedLanguagesInPageAndColumn($pageId, $colPos)
    {
        if (!isset($languagesInColumnCache[$pageId])) {
            $languagesInColumnCache[$pageId] = array();
        }
        if (!isset($languagesInColumnCache[$pageId][$colPos])) {
            $languagesInColumnCache[$pageId][$colPos] = array();
        }

        if (empty($languagesInColumnCache[$pageId][$colPos])) {
            $exQ = BackendUtility::deleteClause('tt_content') .
                ($this->getBackendUser()->isAdmin() ? '' : ' AND sys_language.hidden=0');

            $databaseConnection = $this->getDatabaseConnection();
            $res = $databaseConnection->exec_SELECTquery(
                'sys_language.*',
                'tt_content,sys_language',
                'tt_content.sys_language_uid=sys_language.uid AND tt_content.colPos = ' . (int)$colPos . ' AND tt_content.pid=' . (int)$pageId . $exQ .
                BackendUtility::versioningPlaceholderClause('tt_content'),
                'tt_content.sys_language_uid,sys_language.uid,sys_language.pid,sys_language.tstamp,sys_language.hidden,sys_language.title,sys_language.language_isocode,sys_language.static_lang_isocode,sys_language.flag',
                'sys_language.title'
            );
            while ($row = $databaseConnection->sql_fetch_assoc($res)) {
                $languagesInColumnCache[$pageId][$colPos][$row['uid']] = $row;
            }
            $databaseConnection->sql_free_result($res);
        }

        return $languagesInColumnCache[$pageId][$colPos];
    }

    /**
     * Check if a column of a page for a language is empty. Translation records are ignored here!
     *
     * @param int $colPos
     * @param int $languageId
     * @return bool
     */
    public function isColumnEmpty($colPos, $languageId)
    {
        foreach ($this->contentElementCache[$languageId][$colPos] as $uid => $row) {
            if ((int)$row['l18n_parent'] === 0) {
                return false;
            }
        }
        return true;
    }

    /**
     * Get elements for a column and a language
     *
     * @param int $pageId
     * @param int $colPos
     * @param int $languageId
     * @return array
     */
    public function getElementsFromColumnAndLanguage($pageId, $colPos, $languageId)
    {
        if (!isset($this->contentElementCache[$languageId][$colPos])) {
            $languageId = (int)$languageId;
            $whereClause = 'tt_content.pid=' . (int)$pageId . ' AND tt_content.colPos=' . (int)$colPos . ' AND tt_content.sys_language_uid=' . $languageId . BackendUtility::deleteClause('tt_content');
            if ($languageId > 0) {
                $whereClause .= ' AND tt_content.l18n_parent=0 AND sys_language.uid=' . $languageId . ($this->getBackendUser()->isAdmin() ? '' : ' AND sys_language.hidden=0');
            }

            $databaseConnection = $this->getDatabaseConnection();
            $res = $databaseConnection->exec_SELECTquery(
                'tt_content.uid',
                'tt_content,sys_language',
                $whereClause
            );
            while ($row = $databaseConnection->sql_fetch_assoc($res)) {
                $this->contentElementCache[$languageId][$colPos][$row['uid']] = $row;
            }
            $databaseConnection->sql_free_result($res);
        }
        if (is_array($this->contentElementCache[$languageId][$colPos])) {
            return array_keys($this->contentElementCache[$languageId][$colPos]);
        }
        return array();
    }

1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
    /**
     * Check the editlock access
     *
     * @return bool
     */
    public function pageIsNotLockedForEditors()
    {
        return $this->getBackendUser()->isAdmin() || !($this->CALC_PERMS & Permission::PAGE_EDIT && $this->pageinfo['editlock']);
    }

    /**
     * Returns LanguageService
     *
     * @return \TYPO3\CMS\Lang\LanguageService
     */
    protected function getLanguageService()
    {
        return $GLOBALS['LANG'];
    }

    /**
     * Returns the current BE user.
     *
     * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
     */
    protected function getBackendUser()
    {
        return $GLOBALS['BE_USER'];
    }

    /**
     * Returns the database connection
     *
     * @return \TYPO3\CMS\Core\Database\DatabaseConnection
     */
    protected function getDatabaseConnection()
    {
        return $GLOBALS['TYPO3_DB'];
    }

    /**
     * Returns current PageRenderer
     *
     * @return PageRenderer
     */
    protected function getPageRenderer()
    {
        return GeneralUtility::makeInstance(PageRenderer::class);
    }
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571

    /**
     * @param $edit_record array
     *
     * @return array
     */
    protected function makeQuickEditMenu($edit_record)
    {
        $lang = $this->getLanguageService();
        $databaseConnection = $this->getDatabaseConnection();
        $beUser = $this->getBackendUser();

        $quickEditMenu = $this->moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->makeMenu();
        $quickEditMenu->setIdentifier('quickEditMenu');
        $quickEditMenu->setLabel('');

        // Setting close url/return url for exiting this script:
        // Goes to 'Columns' view if close is pressed (default)
        $this->closeUrl = $this->local_linkThisScript(array('SET' => array('function' => 1)));
        if ($this->returnUrl) {
            $this->closeUrl = $this->returnUrl;
        }
        $retUrlStr = $this->returnUrl ? '&returnUrl=' . rawurlencode($this->returnUrl) : '';

        // Creating the selector box, allowing the user to select which element to edit:
        $isSelected = 0;
        $languageOverlayRecord = '';
        if ($this->current_sys_language) {
            list($languageOverlayRecord) = BackendUtility::getRecordsByField(
                'pages_language_overlay',
                'pid',
                $this->id,
                'AND sys_language_uid=' . (int)$this->current_sys_language
            );
        }
        if (is_array($languageOverlayRecord)) {
            $inValue = 'pages_language_overlay:' . $languageOverlayRecord['uid'];
            $isSelected += (int)$edit_record == $inValue;
            $menuItem = $quickEditMenu->makeMenuItem()
                ->setTitle('[ ' . $lang->getLL('editLanguageHeader', true) . ' ]')
                ->setHref(BackendUtility::getModuleUrl($this->moduleName) . '&id=' . $this->id . '&edit_record=' . $inValue . $retUrlStr)
                ->setActive($edit_record == $inValue);
            $quickEditMenu->addMenuItem($menuItem);
        } else {
            $inValue = 'pages:' . $this->id;
            $isSelected += (int)$edit_record == $inValue;
            $menuItem = $quickEditMenu->makeMenuItem()
                ->setTitle('[ ' . $lang->getLL('editPageProperties', true) . ' ]')
                ->setHref(BackendUtility::getModuleUrl($this->moduleName) . '&id=' . $this->id . '&edit_record=' . $inValue . $retUrlStr)
                ->setActive($edit_record == $inValue);
            $quickEditMenu->addMenuItem($menuItem);
        }
        // Selecting all content elements from this language and allowed colPos:
        $whereClause = 'pid=' . (int)$this->id . ' AND sys_language_uid=' . (int)$this->current_sys_language . ' AND colPos IN (' . $this->colPosList . ')' . ($this->MOD_SETTINGS['tt_content_showHidden'] ? '' : BackendUtility::BEenableFields('tt_content')) . BackendUtility::deleteClause('tt_content') . BackendUtility::versioningPlaceholderClause('tt_content');
        if (!$this->getBackendUser()->user['admin']) {
            $whereClause .= ' AND editlock = 0';
        }
        $res = $databaseConnection->exec_SELECTquery('*', 'tt_content', $whereClause, '', 'colPos,sorting');
        $colPos = null;
        $first = 1;
        // Page is the pid if no record to put this after.
        $prev = $this->id;
        while ($cRow = $databaseConnection->sql_fetch_assoc($res)) {
            BackendUtility::workspaceOL('tt_content', $cRow);
            if (is_array($cRow)) {
                if ($first) {
                    if (!$edit_record) {
                        $edit_record = 'tt_content:' . $cRow['uid'];
                    }
                    $first = 0;
                }
                if (!isset($colPos) || $cRow['colPos'] !== $colPos) {
                    $colPos = $cRow['colPos'];
                    $menuItem = $quickEditMenu->makeMenuItem()
                        ->setTitle(' ')
                        ->setHref('#');
                    $quickEditMenu->addMenuItem($menuItem);
                    $menuItem = $quickEditMenu->makeMenuItem()
                        ->setTitle('__' . $lang->sL(BackendUtility::getLabelFromItemlist('tt_content', 'colPos', $colPos), true) . ':__')
                        ->setHref(BackendUtility::getModuleUrl($this->moduleName) . '&id=' . $this->id . '&edit_record=_EDIT_COL:' . $colPos . $retUrlStr);
                    $quickEditMenu->addMenuItem($menuItem);
                }
                $inValue = 'tt_content:' . $cRow['uid'];
                $isSelected += (int)$edit_record == $inValue;
                $menuItem = $quickEditMenu->makeMenuItem()
                    ->setTitle(htmlspecialchars(GeneralUtility::fixed_lgd_cs(($cRow['header'] ? $cRow['header'] : '[' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:labels.no_title') . '] ' . strip_tags($cRow['bodytext'])), $beUser->uc['titleLen'])))
                    ->setHref(BackendUtility::getModuleUrl($this->moduleName) . '&id=' . $this->id . '&edit_record=' . $inValue . $retUrlStr)
                    ->setActive($edit_record == $inValue);
                $quickEditMenu->addMenuItem($menuItem);
                $prev = -$cRow['uid'];
            }
        }
        // If edit_record is not set (meaning, no content elements was found for this language) we simply set it to create a new element:
        if (!$edit_record) {
            $edit_record = 'tt_content:new/' . $prev . '/' . $colPos;
            $inValue = 'tt_content:new/' . $prev . '/' . $colPos;
            $isSelected += (int)$edit_record == $inValue;
            $menuItem = $quickEditMenu->makeMenuItem()
                ->setTitle('[ ' . $lang->getLL('newLabel', 1) . ' ]')
                ->setHref(BackendUtility::getModuleUrl($this->moduleName) . '&id=' . $this->id . '&edit_record=' . $inValue . $retUrlStr)
                ->setActive($edit_record == $inValue);
            $quickEditMenu->addMenuItem($menuItem);
        }
        // If none is yet selected...
        if (!$isSelected) {
            $menuItem = $quickEditMenu->makeMenuItem()
                ->setTitle('__________')
                ->setHref('#');
            $quickEditMenu->addMenuItem($menuItem);
            $menuItem = $quickEditMenu->makeMenuItem()
                ->setTitle('[ ' . $lang->getLL('newLabel', true) . ' ]')
                ->setHref(BackendUtility::getModuleUrl($this->moduleName) . '&id=' . $this->id . '&edit_record=' . $edit_record . $retUrlStr)
                ->setActive($edit_record == $inValue);
            $quickEditMenu->addMenuItem($menuItem);
        }
        $this->moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->addMenu($quickEditMenu);
        return $edit_record;
    }

    /**
     * Make the LanguageMenu
     *
     * @return void
     */
    protected function makeLanguageMenu()
    {
        if (count($this->MOD_MENU['language']) > 1) {
            $lang = $this->getLanguageService();
            $languageMenu = $this->moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->makeMenu();
            $languageMenu->setIdentifier('languageMenu');
            $languageMenu->setLabel($lang->sL('LLL:EXT:lang/locallang_general.xlf:LGL.language', true));
            foreach ($this->MOD_MENU['language'] as $key => $language) {
                $menuItem = $languageMenu
                    ->makeMenuItem()
                    ->setTitle($language)
                    ->setHref(BackendUtility::getModuleUrl($this->moduleName) . '&id=' . $this->id . '&SET[language]=' . $key);
                if ((int)$this->current_sys_language === $key) {
                    $menuItem->setActive(true);
                }
                $languageMenu->addMenuItem($menuItem);
            }
            $this->moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->addMenu($languageMenu);
        }
    }
1572
}