PageLayoutView.php 188 KB
Newer Older
1
<?php
2

3
4
namespace TYPO3\CMS\Backend\View;

5
/*
6
 * This file is part of the TYPO3 CMS project.
7
 *
8
9
10
 * 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.
11
 *
12
13
 * For the full copyright and license information, please read the
 * LICENSE.txt file that was distributed with this source code.
14
 *
15
16
 * The TYPO3 project - inspiring people to share!
 */
Nicole Cordes's avatar
Nicole Cordes committed
17

18
use Doctrine\DBAL\Driver\Statement;
19
20
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
21
use TYPO3\CMS\Backend\Controller\Page\LocalizationController;
22
use TYPO3\CMS\Backend\Controller\PageLayoutController;
23
24
use TYPO3\CMS\Backend\Routing\UriBuilder;
use TYPO3\CMS\Backend\Tree\View\PageTreeView;
Nicole Cordes's avatar
Nicole Cordes committed
25
use TYPO3\CMS\Backend\Utility\BackendUtility;
26
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
27
use TYPO3\CMS\Core\Database\Connection;
28
use TYPO3\CMS\Core\Database\ConnectionPool;
29
use TYPO3\CMS\Core\Database\Query\QueryBuilder;
30
use TYPO3\CMS\Core\Database\Query\QueryHelper;
31
32
use TYPO3\CMS\Core\Database\Query\Restriction\BackendWorkspaceRestriction;
use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
33
use TYPO3\CMS\Core\Database\ReferenceIndex;
34
use TYPO3\CMS\Core\Exception\SiteNotFoundException;
35
36
use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Imaging\IconFactory;
37
use TYPO3\CMS\Core\Localization\LanguageService;
Nicole Cordes's avatar
Nicole Cordes committed
38
use TYPO3\CMS\Core\Messaging\FlashMessage;
39
use TYPO3\CMS\Core\Messaging\FlashMessageService;
40
use TYPO3\CMS\Core\Page\PageRenderer;
41
use TYPO3\CMS\Core\Routing\SiteMatcher;
42
use TYPO3\CMS\Core\Service\DependencyOrderingService;
43
use TYPO3\CMS\Core\Service\FlexFormService;
44
use TYPO3\CMS\Core\Site\Entity\SiteLanguage;
45
use TYPO3\CMS\Core\Type\Bitmask\Permission;
46
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
Nicole Cordes's avatar
Nicole Cordes committed
47
use TYPO3\CMS\Core\Utility\GeneralUtility;
48
49
use TYPO3\CMS\Core\Utility\HttpUtility;
use TYPO3\CMS\Core\Utility\MathUtility;
50
use TYPO3\CMS\Core\Utility\StringUtility;
51
use TYPO3\CMS\Core\Versioning\VersionState;
52
use TYPO3\CMS\Fluid\View\StandaloneView;
Nicole Cordes's avatar
Nicole Cordes committed
53

54
55
/**
 * Child class for the Web > Page module
56
 * @internal This class is a TYPO3 Backend implementation and is not considered part of the Public TYPO3 API.
57
 */
58
class PageLayoutView implements LoggerAwareInterface
59
{
60
61
    use LoggerAwareTrait;

62
63
64
    /**
     * If TRUE, users/groups are shown in the page info box.
     *
65
     * @var bool
66
     */
67
    public $pI_showUser = false;
68
69
70
71
72
73
74
75
76
77
78

    /**
     * The number of successive records to edit when showing content elements.
     *
     * @var int
     */
    public $nextThree = 3;

    /**
     * If TRUE, disables the edit-column icon for tt_content elements
     *
79
     * @var bool
80
     */
81
    public $pages_noEditColumns = false;
82
83
84
85

    /**
     * If TRUE, new-wizards are linked to rather than the regular new-element list.
     *
86
     * @var bool
87
     */
88
    public $option_newWizard = true;
89
90
91
92
93
94
95
96
97
98
99

    /**
     * If set to "1", will link a big button to content element wizard.
     *
     * @var int
     */
    public $ext_function = 0;

    /**
     * If TRUE, elements will have edit icons (probably this is whether the user has permission to edit the page content). Set externally.
     *
100
     * @var bool
101
     */
102
    public $doEdit = true;
103
104
105
106
107
108
109
110
111
112
113
114
115

    /**
     * Age prefixes for displaying times. May be set externally to localized values.
     *
     * @var string
     */
    public $agePrefixes = ' min| hrs| days| yrs| min| hour| day| year';

    /**
     * Array of tables to be listed by the Web > Page module in addition to the default tables.
     *
     * @var array
     */
116
    public $externalTables = [];
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137

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

    /**
     * If set TRUE, the language mode of tt_content elements will be rendered with hard binding between
     * default language content elements and their translations!
     *
     * @var bool
     */
    public $defLangBinding = false;

    /**
     * External, static: Configuration of tt_content element display:
     *
     * @var array
     */
138
    public $tt_contentConfig = [
139
140
141
142
143
144
145
146
147
148
149
150
151
152
        // Boolean: Display info-marks or not
        'showInfo' => 1,
        // Boolean: Display up/down arrows and edit icons for tt_content records
        'showCommands' => 1,
        'languageCols' => 0,
        'languageMode' => 0,
        'languageColsPointer' => 0,
        'showHidden' => 1,
        // Displays hidden records as well
        'sys_language_uid' => 0,
        // Which language
        'cols' => '1,0,2,3',
        'activeCols' => '1,0,2,3'
        // Which columns can be accessed by current BE user
153
    ];
154
155
156
157
158
159

    /**
     * Contains icon/title of pages which are listed in the tables menu (see getTableMenu() function )
     *
     * @var array
     */
160
    public $activeTables = [];
161
162
163
164

    /**
     * @var array
     */
165
166
167
168
169
    public $tt_contentData = [
        'nextThree' => [],
        'prev' => [],
        'next' => []
    ];
170
171
172
173
174
175

    /**
     * Used to store labels for CTypes for tt_content elements
     *
     * @var array
     */
176
    public $CType_labels = [];
177
178
179
180
181
182

    /**
     * Used to store labels for the various fields in tt_content elements
     *
     * @var array
     */
183
    public $itemLabels = [];
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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
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
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
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
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
    /**
     * Indicates if all available fields for a user should be selected or not.
     *
     * @var int
     */
    public $allFields = 0;

    /**
     * Number of records to show
     *
     * @var int
     */
    public $showLimit = 0;

    /**
     * Shared module configuration, used by localization features
     *
     * @var array
     */
    public $modSharedTSconfig = [];

    /**
     * Tables which should not get listed
     *
     * @var string
     */
    public $hideTables = '';

    /**
     * Containing which fields to display in extended mode
     *
     * @var string[]
     */
    public $displayFields;

    /**
     * Tables which should not list their translations
     *
     * @var string
     */
    public $hideTranslations = '';

    /**
     * If set, csvList is outputted.
     *
     * @var bool
     */
    public $csvOutput = false;

    /**
     * Cache for record path
     *
     * @var mixed[]
     */
    public $recPath_cache = [];

    /**
     * Field, to sort list by
     *
     * @var string
     */
    public $sortField;

    /**
     * default Max items shown per table in "multi-table mode", may be overridden by tables.php
     *
     * @var int
     */
    public $itemsLimitPerTable = 20;

    /**
     * Page select permissions
     *
     * @var string
     */
    public $perms_clause = '';

    /**
     * Page id
     *
     * @var int
     */
    public $id;

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

    /**
     * Tablename if single-table mode
     *
     * @var string
     */
    public $table = '';

    /**
     * Some permissions...
     *
     * @var int
     */
    public $calcPerms = 0;

    /**
     * Mode for what happens when a user clicks the title of a record.
     *
     * @var string
     */
    public $clickTitleMode = '';

    /**
     * Levels to search down.
     *
     * @var int
     */
    public $searchLevels = '';

    /**
     * "LIMIT " in SQL...
     *
     * @var int
     */
    public $iLimit = 0;

    /**
     * Set to the total number of items for a table when selecting.
     *
     * @var string
     */
    public $totalItems = '';

    /**
     * TSconfig which overwrites TCA-Settings
     *
     * @var mixed[][]
     */
    public $tableTSconfigOverTCA = [];

    /**
     * Loaded with page record with version overlay if any.
     *
     * @var string[]
     */
    public $pageRecord = [];

    /**
     * Used for tracking duplicate values of fields
     *
     * @var string[]
     */
    public $duplicateStack = [];

    /**
     * Fields to display for the current table
     *
     * @var string[]
     */
    public $setFields = [];

    /**
     * Current script name
     *
     * @var string
     */
    public $script = 'index.php';

    /**
     * If TRUE, records are listed only if a specific table is selected.
     *
     * @var bool
     */
    public $listOnlyInSingleTableMode = false;

    /**
     * JavaScript code accumulation
     *
     * @var string
     */
    public $JScode = '';

    /**
     * Pointer for browsing list
     *
     * @var int
     */
    public $firstElementNumber = 0;

    /**
     * Counting the elements no matter what...
     *
     * @var int
     */
    public $eCounter = 0;

    /**
     * Search string
     *
     * @var string
     */
    public $searchString = '';

    /**
     * default Max items shown per table in "single-table mode", may be overridden by tables.php
     *
     * @var int
     */
    public $itemsLimitSingleTable = 100;

    /**
     * Field, indicating to sort in reverse order.
     *
     * @var bool
     */
    public $sortRev;

    /**
     * String, can contain the field name from a table which must have duplicate values marked.
     *
     * @var string
     */
    public $duplicateField;

    /**
     * Specify a list of tables which are the only ones allowed to be displayed.
     *
     * @var string
     */
    public $tableList = '';

    /**
     * Array of collapsed / uncollapsed tables in multi table view
     *
     * @var int[][]
     */
    public $tablesCollapsed = [];

    /**
     * @var array[] Module configuration
     */
    public $modTSconfig;

    /**
     * HTML output
     *
     * @var string
     */
    public $HTMLcode = '';

    /**
     * Thumbnails on records containing files (pictures)
     *
     * @var bool
     */
    public $thumbs = 0;

    /**
     * Used for tracking next/prev uids
     *
     * @var int[][]
     */
    public $currentTable = [];

    /**
     * OBSOLETE - NOT USED ANYMORE. leftMargin
     *
     * @var int
     */
    public $leftMargin = 0;

    /**
     * Decides the columns shown. Filled with values that refers to the keys of the data-array. $this->fieldArray[0] is the title column.
     *
     * @var array
     */
    public $fieldArray = [];

    /**
     * Set to zero, if you don't want a left-margin with addElement function
     *
     * @var int
     */
    public $setLMargin = 1;

    /**
     * Contains page translation languages
     *
     * @var array
     */
    public $pageOverlays = [];

    /**
     * Counter increased for each element. Used to index elements for the JavaScript-code that transfers to the clipboard
     *
     * @var int
     */
    public $counter = 0;

484
485
486
487
488
489
490
    /**
     * Contains site languages for this page ID
     *
     * @var SiteLanguage[]
     */
    protected $siteLanguages = [];

491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
    /**
     * Script URL
     *
     * @var string
     */
    public $thisScript = '';

    /**
     * If set this is <td> CSS-classname for odd columns in addElement. Used with db_layout / pages section
     *
     * @var string
     */
    public $oddColumnsCssClass = '';

    /**
     * Not used in this class - but maybe extension classes...
     * Max length of strings
     *
     * @var int
     */
    public $fixedL = 30;

    /**
     * Keys are fieldnames and values are td-parameters to add in addElement(), please use $addElement_tdCSSClass for CSS-classes;
     *
     * @var array
     */
    public $addElement_tdParams = [];

    /**
     * @var int
     */
    public $no_noWrap = 0;

    /**
     * @var int
     */
    public $showIcon = 1;

    /**
     * Keys are fieldnames and values are td-css-classes to add in addElement();
     *
     * @var array
     */
    public $addElement_tdCssClass = [];

537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
    /**
     * @var \TYPO3\CMS\Backend\Clipboard\Clipboard
     */
    protected $clipboard;

    /**
     * User permissions
     *
     * @var int
     */
    public $ext_CALC_PERMS;

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

    /**
     * Caches the available languages in a colPos
     *
     * @var array
     */
561
    protected $languagesInColumnCache = [];
562
563
564
565
566
567
568

    /**
     * Caches the amount of content elements as a matrix
     *
     * @var array
     * @internal
     */
569
    protected $contentElementCache = [];
570
571
572
573
574
575

    /**
     * @var IconFactory
     */
    protected $iconFactory;

576
577
578
579
580
    /**
     * Stores whether a certain language has translations in it
     *
     * @var array
     */
581
    protected $languageHasTranslationsCache = [];
582

583
584
585
586
587
    /**
     * @var LocalizationController
     */
    protected $localizationController;

588
    /**
589
590
591
     * Override the page ids taken into account by getPageIdConstraint()
     *
     * @var array
592
     */
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
    protected $overridePageIdList = [];

    /**
     * Override/add urlparameters in listUrl() method
     *
     * @var string[]
     */
    protected $overrideUrlParameters = [];

    /**
     * Array with before/after setting for tables
     * Structure:
     * 'tableName' => [
     *    'before' => ['A', ...]
     *    'after' => []
     *  ]
     * @var array[]
     */
    protected $tableDisplayOrder = [];

613
614
615
616
617
618
619
    /**
     * Cache the number of references to a record
     *
     * @var array
     */
    protected $referenceCount = [];

620
621
622
623
624
625
626
627
628
629
    /**
     * Construct to initialize class variables.
     */
    public function __construct()
    {
        if (isset($GLOBALS['BE_USER']->uc['titleLen']) && $GLOBALS['BE_USER']->uc['titleLen'] > 0) {
            $this->fixedL = $GLOBALS['BE_USER']->uc['titleLen'];
        }
        $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
        $this->determineScriptUrl();
630
        $this->localizationController = GeneralUtility::makeInstance(LocalizationController::class);
631
        $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
632
        $pageRenderer->addInlineLanguageLabelFile('EXT:backend/Resources/Private/Language/locallang_layout.xlf');
633
        $pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/Tooltip');
634
        $pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/Localization');
635
636
637
638
639
640
    }

    /*****************************************
     *
     * Renderings
     *
Claus Due's avatar
Claus Due committed
641
     *****************************************/
642
643
644
645
646
647
648
649
650
651
652
653
    /**
     * Adds the code of a single table
     *
     * @param string $table Table name
     * @param int $id Current page id
     * @param string $fields
     * @return string HTML for listing.
     */
    public function getTable($table, $id, $fields = '')
    {
        if (isset($this->externalTables[$table])) {
            return $this->getExternalTables($id, $table);
654
655
656
        }
        // Branch out based on table name:
        switch ($table) {
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
                case 'pages':
                    return $this->getTable_pages($id);
                case 'tt_content':
                    return $this->getTable_tt_content($id);
                default:
                    return '';
            }
    }

    /**
     * Renders an external table from page id
     *
     * @param int $id Page id
     * @param string $table Name of the table
     * @return string HTML for the listing
     */
    public function getExternalTables($id, $table)
    {
675
        $this->pageinfo = BackendUtility::readPageAccess($id, '');
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
        $type = $this->getPageLayoutController()->MOD_SETTINGS[$table];
        if (!isset($type)) {
            $type = 0;
        }
        // eg. "name;title;email;company,image"
        $fList = $this->externalTables[$table][$type]['fList'];
        // The columns are separeted by comma ','.
        // Values separated by semicolon ';' are shown in the same column.
        $icon = $this->externalTables[$table][$type]['icon'];
        $addWhere = $this->externalTables[$table][$type]['addWhere'];
        // Create listing
        $out = $this->makeOrdinaryList($table, $id, $fList, $icon, $addWhere);
        return $out;
    }

    /**
     * Renders records from the pages table from page id
     * (Used to get information about the page tree content by "Web>Info"!)
     *
     * @param int $id Page id
     * @return string HTML for the listing
     */
    public function getTable_pages($id)
    {
        // Initializing:
        $out = '';
702
        $lang = $this->getLanguageService();
703
704
705
706
707
        // Select current page:
        if (!$id) {
            // The root has a pseudo record in pageinfo...
            $row = $this->getPageLayoutController()->pageinfo;
        } else {
708
709
710
711
712
713
714
715
716
            $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
                ->getQueryBuilderForTable('pages');
            $queryBuilder->getRestrictions()
                ->removeAll()
                ->add(GeneralUtility::makeInstance(DeletedRestriction::class));
            $row = $queryBuilder
                ->select('*')
                ->from('pages')
                ->where(
717
                    $queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($id, \PDO::PARAM_INT)),
718
                    $this->getBackendUser()->getPagePermsClause(Permission::PAGE_SHOW)
719
720
721
                )
                ->execute()
                ->fetch();
722
723
724
725
726
727
728
729
730
731
732
733
734
            BackendUtility::workspaceOL('pages', $row);
        }
        // If there was found a page:
        if (is_array($row)) {
            // Getting select-depth:
            $depth = (int)$this->getPageLayoutController()->MOD_SETTINGS['pages_levels'];
            // Overriding a few things:
            $this->no_noWrap = 0;
            // Items
            $this->eCounter = $this->firstElementNumber;
            // Creating elements:
            list($flag, $code) = $this->fwd_rwd_nav();
            $out .= $code;
735
            $editUids = [];
736
737
            if ($flag) {
                // Getting children:
738
                $theRows = $this->getPageRecordsRecursive($row['uid'], $depth);
739
                if ($this->getBackendUser()->doesUserHaveAccess($row, 2) && $row['uid'] > 0) {
740
741
742
743
744
745
746
747
748
749
750
751
752
                    $editUids[] = $row['uid'];
                }
                $out .= $this->pages_drawItem($row, $this->fieldArray);
                // Traverse all pages selected:
                foreach ($theRows as $sRow) {
                    if ($this->getBackendUser()->doesUserHaveAccess($sRow, 2)) {
                        $editUids[] = $sRow['uid'];
                    }
                    $out .= $this->pages_drawItem($sRow, $this->fieldArray);
                }
                $this->eCounter++;
            }
            // Header line is drawn
753
            $theData = [];
754
755
756
            $editIdList = implode(',', $editUids);
            // Traverse fields (as set above) in order to create header values:
            foreach ($this->fieldArray as $field) {
757
758
                if ($editIdList
                    && isset($GLOBALS['TCA']['pages']['columns'][$field])
759
                    && $field !== 'uid'
760
761
                    && !$this->pages_noEditColumns
                ) {
762
                    $iTitle = sprintf(
763
764
                        $lang->getLL('editThisColumn'),
                        rtrim(trim($lang->sL(BackendUtility::getItemLabel('pages', $field))), ':')
765
                    );
766
767
768
769
770
771
772
773
774
                    $urlParameters = [
                        'edit' => [
                            'pages' => [
                                $editIdList => 'edit'
                            ]
                        ],
                        'columnsOnly' => $field,
                        'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
                    ];
775
776
                    $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
                    $url = (string)$uriBuilder->buildUriFromRoute('record_edit', $urlParameters);
777
                    $eI = '<a class="btn btn-default" href="' . htmlspecialchars($url)
778
779
780
781
782
783
784
                        . '" title="' . htmlspecialchars($iTitle) . '">'
                        . $this->iconFactory->getIcon('actions-document-open', Icon::SIZE_SMALL)->render() . '</a>';
                } else {
                    $eI = '';
                }
                switch ($field) {
                    case 'title':
785
                        $theData[$field] = $eI . '&nbsp;<strong>'
786
                            . $lang->sL($GLOBALS['TCA']['pages']['columns'][$field]['label'])
787
                            . '</strong>';
788
789
                        break;
                    case 'uid':
790
                        $theData[$field] = '';
791
792
                        break;
                    default:
793
                        if (strpos($field, 'table_') === 0) {
794
795
                            $f2 = substr($field, 6);
                            if ($GLOBALS['TCA'][$f2]) {
796
797
798
799
800
801
                                $theData[$field] = '&nbsp;' .
                                    '<span title="' .
                                    htmlspecialchars($lang->sL($GLOBALS['TCA'][$f2]['ctrl']['title'])) .
                                    '">' .
                                    $this->iconFactory->getIconForRecord($f2, [], Icon::SIZE_SMALL)->render() .
                                    '</span>';
802
803
                            }
                        } else {
804
                            $theData[$field] = $eI . '&nbsp;<strong>'
805
                                . htmlspecialchars($lang->sL($GLOBALS['TCA']['pages']['columns'][$field]['label']))
806
                                . '</strong>';
807
808
809
                        }
                }
            }
810
811
812
813
814
815
816
817
818
819
            $out = '<div class="table-fit">'
                . '<table class="table table-striped table-hover typo3-page-pages">'
                    . '<thead>'
                            . $this->addElement(1, '', $theData)
                    . '</thead>'
                    . '<tbody>'
                        . $out
                    . '</tbody>'
                . '</table>'
                . '</div>';
820
821
822
823
824
825
826
827
828
829
830
831
        }
        return $out;
    }

    /**
     * Renders Content Elements from the tt_content table from page id
     *
     * @param int $id Page id
     * @return string HTML for the listing
     */
    public function getTable_tt_content($id)
    {
832
833
834
        $expressionBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
            ->getConnectionForTable('tt_content')
            ->getExpressionBuilder();
835
        $this->pageinfo = BackendUtility::readPageAccess($this->id, '');
836
837
838
        $this->initializeLanguages();
        $this->initializeClipboard();
        $pageTitleParamForAltDoc = '&recTitle=' . rawurlencode(BackendUtility::getRecordTitle('pages', BackendUtility::getRecordWSOL('pages', $id), true));
839
        /** @var PageRenderer $pageRenderer */
840
841
842
        $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
        $pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/LayoutModule/DragDrop');
        $pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/Modal');
843
        $pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/LayoutModule/Paste');
844
        $pageActionsCallback = '';
845
        if ($this->isPageEditable()) {
846
847
848
849
850
851
852
853
            $languageOverlayId = 0;
            $pageLocalizationRecord = BackendUtility::getRecordLocalization('pages', $this->id, (int)$this->tt_contentConfig['sys_language_uid']);
            if (is_array($pageLocalizationRecord)) {
                $pageLocalizationRecord = reset($pageLocalizationRecord);
            }
            if (!empty($pageLocalizationRecord['uid'])) {
                $languageOverlayId = $pageLocalizationRecord['uid'];
            }
854
            $pageActionsCallback = 'function(PageActions) {
855
                PageActions.setPageId(' . (int)$this->id . ');
856
                PageActions.setLanguageOverlayId(' . $languageOverlayId . ');
857
            }';
858
        }
859
        $pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/PageActions', $pageActionsCallback);
860
        // Get labels for CTypes and tt_content element fields in general:
861
        $this->CType_labels = [];
862
863
864
        foreach ($GLOBALS['TCA']['tt_content']['columns']['CType']['config']['items'] as $val) {
            $this->CType_labels[$val[1]] = $this->getLanguageService()->sL($val[0]);
        }
865

866
        $this->itemLabels = [];
867
868
869
        foreach ($GLOBALS['TCA']['tt_content']['columns'] as $name => $val) {
            $this->itemLabels[$name] = $this->getLanguageService()->sL($val['label']);
        }
870
        $languageColumn = [];
871
872
873
874
875
876
877
878
879
880
        $out = '';

        // Setting language list:
        $langList = $this->tt_contentConfig['sys_language_uid'];
        if ($this->tt_contentConfig['languageMode']) {
            if ($this->tt_contentConfig['languageColsPointer']) {
                $langList = '0,' . $this->tt_contentConfig['languageColsPointer'];
            } else {
                $langList = implode(',', array_keys($this->tt_contentConfig['languageCols']));
            }
881
            $languageColumn = [];
882
883
        }
        $langListArr = GeneralUtility::intExplode(',', $langList);
884
        $defaultLanguageElementsByColumn = [];
885
        $defLangBinding = [];
886
887
888
889
890
891
        // For each languages... :
        // If not languageMode, then we'll only be through this once.
        foreach ($langListArr as $lP) {
            $lP = (int)$lP;

            if (!isset($this->contentElementCache[$lP])) {
892
                $this->contentElementCache[$lP] = [];
893
894
895
            }

            if (count($langListArr) === 1 || $lP === 0) {
896
                $showLanguage = $expressionBuilder->in('sys_language_uid', [$lP, -1]);
897
            } else {
898
                $showLanguage = $expressionBuilder->eq('sys_language_uid', $lP);
899
            }
900
901
            $content = [];
            $head = [];
902

903
904
            $backendLayout = $this->getBackendLayoutView()->getSelectedBackendLayout($this->id);
            $columns = $backendLayout['__colPosList'];
905
            // Select content records per column
906
907
            $contentRecordsPerColumn = $this->getContentRecordsPerColumn('table', $id, $columns, $showLanguage);
            $cList = array_keys($contentRecordsPerColumn);
908
            // For each column, render the content into a variable:
909
            foreach ($cList as $columnId) {
910
911
                if (!isset($this->contentElementCache[$lP])) {
                    $this->contentElementCache[$lP] = [];
912
913
914
                }

                if (!$lP) {
915
                    $defaultLanguageElementsByColumn[$columnId] = [];
916
                }
917

918
                // Start wrapping div
919
920
921
                $content[$columnId] .= '<div data-colpos="' . $columnId . '" data-language-uid="' . $lP . '" class="t3js-sortable t3js-sortable-lang t3js-sortable-lang-' . $lP . ' t3-page-ce-wrapper';
                if (empty($contentRecordsPerColumn[$columnId])) {
                    $content[$columnId] .= ' t3-page-ce-empty';
922
                }
923
                $content[$columnId] .= '">';
924
925
                // Add new content at the top most position
                $link = '';
926
                if ($this->isContentEditable()
927
                    && (!$this->checkIfTranslationsExistInLanguage($contentRecordsPerColumn, $lP))
928
                ) {
929
930
931
932
                    if ($this->option_newWizard) {
                        $urlParameters = [
                            'id' => $id,
                            'sys_language_uid' => $lP,
933
                            'colPos' => $columnId,
934
935
936
                            'uid_pid' => $id,
                            'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
                        ];
937
                        $routeName = BackendUtility::getPagesTSconfig($id)['mod.']['newContentElementWizard.']['override']
938
939
940
                            ?? 'new_content_element_wizard';
                        $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
                        $url = (string)$uriBuilder->buildUriFromRoute($routeName, $urlParameters);
941
942
943
944
945
946
947
948
949
                    } else {
                        $urlParameters = [
                            'edit' => [
                                'tt_content' => [
                                    $id => 'new'
                                ]
                            ],
                            'defVals' => [
                                'tt_content' => [
950
                                    'colPos' => $columnId,
951
952
953
954
955
                                    'sys_language_uid' => $lP
                                ]
                            ],
                            'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
                        ];
956
957
                        $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
                        $url = (string)$uriBuilder->buildUriFromRoute('record_edit', $urlParameters);
958
                    }
959
                    $title = htmlspecialchars($this->getLanguageService()->getLL('newContentElement'));
960
                    $link = '<a href="' . htmlspecialchars($url) . '" '
961
962
                        . 'title="' . $title . '"'
                        . 'data-title="' . $title . '"'
963
                        . 'class="btn btn-default btn-sm ' . ($this->option_newWizard ? 't3js-toggle-new-content-element-wizard' : '') . '">'
964
                        . $this->iconFactory->getIcon('actions-add', Icon::SIZE_SMALL)->render()
965
                        . ' '
966
                        . htmlspecialchars($this->getLanguageService()->getLL('content')) . '</a>';
967
                }
968
                if ($this->getBackendUser()->checkLanguageAccess($lP) && $columnId !== 'unused') {
969
                    $content[$columnId] .= '
970
                    <div class="t3-page-ce t3js-page-ce" data-page="' . (int)$id . '" id="' . StringUtility::getUniqueId() . '">
971
                        <div class="t3js-page-new-ce t3-page-ce-wrapper-new-ce" id="colpos-' . $columnId . '-page-' . $id . '-' . StringUtility::getUniqueId() . '">'
972
973
974
975
976
977
                            . $link
                            . '</div>
                        <div class="t3-page-ce-dropzone-available t3js-page-ce-dropzone-available"></div>
                    </div>
                    ';
                }
978
                $editUidList = '';
979
                if (!isset($contentRecordsPerColumn[$columnId]) || !is_array($contentRecordsPerColumn[$columnId])) {
980
981
982
983
984
985
986
987
988
989
                    $message = GeneralUtility::makeInstance(
                        FlashMessage::class,
                        $this->getLanguageService()->sL('LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:error.invalidBackendLayout'),
                        '',
                        FlashMessage::WARNING
                    );
                    $service = GeneralUtility::makeInstance(FlashMessageService::class);
                    $queue = $service->getMessageQueueByIdentifier();
                    $queue->addMessage($message);
                } else {
990
                    $rowArr = $contentRecordsPerColumn[$columnId];
991
                    $this->generateTtContentDataArray($rowArr);
992

993
                    foreach ((array)$rowArr as $rKey => $row) {
994
                        $this->contentElementCache[$lP][$columnId][$row['uid']] = $row;
995
                        if ($this->tt_contentConfig['languageMode']) {
996
                            $languageColumn[$columnId][$lP] = $head[$columnId] . $content[$columnId];
997
                        }
998
                        if (is_array($row) && !VersionState::cast($row['t3ver_state'])->equals(VersionState::DELETE_PLACEHOLDER)) {
999
                            $singleElementHTML = '<div class="t3-page-ce-dragitem" id="' . StringUtility::getUniqueId() . '">';
1000
                            if (!$lP && ($this->defLangBinding || $row['sys_language_uid'] != -1)) {
For faster browsing, not all history is shown. View entire blame