/
PageLayoutView.php
2085 lines (1961 loc) · 98 KB
/
PageLayoutView.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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
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
484
485
486
487
488
489
490
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
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
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
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
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
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
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
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
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
919
920
921
922
923
924
925
926
927
928
929
930
931
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
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/*
* This file is part of the TYPO3 CMS project.
*
* 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.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Backend\View;
use Doctrine\DBAL\Driver\Statement;
use Psr\EventDispatcher\EventDispatcherInterface;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use TYPO3\CMS\Backend\Clipboard\Clipboard;
use TYPO3\CMS\Backend\Controller\Page\LocalizationController;
use TYPO3\CMS\Backend\Routing\UriBuilder;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Backend\View\Drawing\DrawingConfiguration;
use TYPO3\CMS\Backend\View\Event\AfterSectionMarkupGeneratedEvent;
use TYPO3\CMS\Backend\View\Event\BeforeSectionMarkupGeneratedEvent;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Database\Connection;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\QueryBuilder;
use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
use TYPO3\CMS\Core\Database\Query\Restriction\WorkspaceRestriction;
use TYPO3\CMS\Core\Database\ReferenceIndex;
use TYPO3\CMS\Core\Exception\SiteNotFoundException;
use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Imaging\IconFactory;
use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\CMS\Core\Messaging\FlashMessage;
use TYPO3\CMS\Core\Messaging\FlashMessageService;
use TYPO3\CMS\Core\Page\PageRenderer;
use TYPO3\CMS\Core\Service\FlexFormService;
use TYPO3\CMS\Core\Site\Entity\NullSite;
use TYPO3\CMS\Core\Site\Entity\SiteLanguage;
use TYPO3\CMS\Core\Site\SiteFinder;
use TYPO3\CMS\Core\Type\Bitmask\Permission;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\StringUtility;
use TYPO3\CMS\Core\Versioning\VersionState;
use TYPO3\CMS\Fluid\View\StandaloneView;
/**
* Child class for the Web > Page module
* @internal This class is a TYPO3 Backend implementation and is not considered part of the Public TYPO3 API.
* @deprecated Will be removed in TYPO3 11
*/
class PageLayoutView implements LoggerAwareInterface
{
use LoggerAwareTrait;
/**
* If TRUE, new-wizards are linked to rather than the regular new-element list.
*
* @var bool
*/
public $option_newWizard = true;
/**
* If TRUE, elements will have edit icons (probably this is whether the user has permission to edit the page content). Set externally.
*
* @var bool
*/
public $doEdit = true;
/**
* 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
*/
public $tt_contentConfig = [
'languageCols' => 0,
'languageMode' => 0,
'languageColsPointer' => 0,
// Displays hidden records as well
'showHidden' => 1,
// Which language
'sys_language_uid' => 0,
'cols' => '1,0,2,3',
// Which columns can be accessed by current BE user
'activeCols' => '1,0,2,3'
];
/**
* Used to move content up / down
* @var array
*/
public $tt_contentData = [
'prev' => [],
'next' => []
];
/**
* Used to store labels for CTypes for tt_content elements
*
* @var array
*/
public $CType_labels = [];
/**
* Used to store labels for the various fields in tt_content elements
*
* @var array
*/
public $itemLabels = [];
/**
* Page id
*
* @var int
*/
public $id;
/**
* Loaded with page record with version overlay if any.
*
* @var string[]
*/
public $pageRecord = [];
/**
* Contains site languages for this page ID
*
* @var SiteLanguage[]
*/
protected $siteLanguages = [];
/**
* @var Clipboard
*/
protected $clipboard;
/**
* Current ids page record
*
* @var array
*/
protected $pageinfo;
/**
* Caches the amount of content elements as a matrix
*
* @var array
* @internal
*/
protected $contentElementCache = [];
/**
* @var IconFactory
*/
protected $iconFactory;
/**
* Stores whether a certain language has translations in it
*
* @var array
*/
protected $languageHasTranslationsCache = [];
/**
* @var LocalizationController
*/
protected $localizationController;
/**
* Cache the number of references to a record
*
* @var array
*/
protected $referenceCount = [];
/**
* @var EventDispatcherInterface
*/
protected $eventDispatcher;
/**
* @var UriBuilder
*/
protected $uriBuilder;
public function __construct(EventDispatcherInterface $eventDispatcher)
{
$this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
$this->uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
$this->localizationController = GeneralUtility::makeInstance(LocalizationController::class);
$this->eventDispatcher = $eventDispatcher;
}
/**
* @param DrawingConfiguration $drawingConfiguration
* @return PageLayoutView
* @internal
*/
public static function createFromDrawingConfiguration(DrawingConfiguration $drawingConfiguration): PageLayoutView
{
/** @var PageLayoutView $pageLayoutView */
$pageLayoutView = GeneralUtility::makeInstance(self::class);
$pageLayoutView->id = $drawingConfiguration->getPageId();
$pageLayoutView->pageinfo = BackendUtility::readPageAccess($pageLayoutView->id, '');
$pageLayoutView->pageRecord = $drawingConfiguration->getPageRecord();
$pageLayoutView->option_newWizard = $drawingConfiguration->getShowNewContentWizard();
$pageLayoutView->defLangBinding = $drawingConfiguration->getDefaultLanguageBinding();
$pageLayoutView->tt_contentConfig['cols'] = implode(',', $drawingConfiguration->getActiveColumns());
$pageLayoutView->tt_contentConfig['activeCols'] = implode(',', $drawingConfiguration->getActiveColumns());
$pageLayoutView->tt_contentConfig['showHidden'] = $drawingConfiguration->getShowHidden();
$pageLayoutView->tt_contentConfig['sys_language_uid'] = $drawingConfiguration->getLanguageColumnsPointer();
if ($drawingConfiguration->getLanguageMode()) {
$pageLayoutView->tt_contentConfig['languageMode'] = 1;
$pageLayoutView->tt_contentConfig['languageCols'] = $drawingConfiguration->getLanguageColumns();
$pageLayoutView->tt_contentConfig['languageColsPointer'] = $drawingConfiguration->getLanguageColumnsPointer();
}
$pageLayoutView->doEdit = $pageLayoutView->isContentEditable($drawingConfiguration->getLanguageColumnsPointer());
$pageLayoutView->CType_labels = $drawingConfiguration->getContentTypeLabels();
$pageLayoutView->itemLabels = $drawingConfiguration->getItemLabels();
return $pageLayoutView;
}
protected function initialize()
{
$this->resolveSiteLanguages($this->id);
$this->pageRecord = BackendUtility::getRecordWSOL('pages', $this->id);
$this->initializeClipboard();
$this->pageinfo = BackendUtility::readPageAccess($this->id, '');
$pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
$pageActionsCallback = null;
if ($this->isPageEditable()) {
$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'];
}
$pageActionsCallback = 'function(PageActions) {
PageActions.setPageId(' . (int)$this->id . ');
PageActions.setLanguageOverlayId(' . $languageOverlayId . ');
}';
}
$pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/PageActions', $pageActionsCallback);
// Get labels for CTypes and tt_content element fields in general:
$this->CType_labels = [];
foreach ($GLOBALS['TCA']['tt_content']['columns']['CType']['config']['items'] as $val) {
$this->CType_labels[$val[1]] = $this->getLanguageService()->sL($val[0]);
}
$this->itemLabels = [];
foreach ($GLOBALS['TCA']['tt_content']['columns'] as $name => $val) {
$this->itemLabels[$name] = $this->getLanguageService()->sL($val['label']);
}
}
/**
* Build a list of language IDs that should be rendered in this view
* @return int[]
*/
protected function getSelectedLanguages(): array
{
$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']));
}
}
return GeneralUtility::intExplode(',', $langList);
}
/**
* 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)
{
$this->id = (int)$id;
$this->initialize();
$expressionBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
->getConnectionForTable('tt_content')
->getExpressionBuilder();
$languageColumn = [];
$out = '';
$tcaItems = GeneralUtility::makeInstance(BackendLayoutView::class)->getColPosListItemsParsed($this->id);
$languageIds = $this->getSelectedLanguages();
$defaultLanguageElementsByColumn = [];
$defLangBinding = [];
// For each languages...
// If not languageMode, then we'll only be through this once.
foreach ($languageIds as $lP) {
if (!isset($this->contentElementCache[$lP])) {
$this->contentElementCache[$lP] = [];
}
if (count($languageIds) === 1 || $lP === 0) {
$showLanguage = $expressionBuilder->in('sys_language_uid', [$lP, -1]);
} else {
$showLanguage = $expressionBuilder->eq('sys_language_uid', $lP);
}
$content = [];
$head = [];
$backendLayout = $this->getBackendLayoutView()->getSelectedBackendLayout($this->id);
$columns = $backendLayout['__colPosList'];
// Select content records per column
$contentRecordsPerColumn = $this->getContentRecordsPerColumn('tt_content', $id, $columns, $showLanguage);
$cList = array_keys($contentRecordsPerColumn);
// For each column, render the content into a variable:
foreach ($cList as $columnId) {
if (!isset($this->contentElementCache[$lP])) {
$this->contentElementCache[$lP] = [];
}
if (!$lP) {
$defaultLanguageElementsByColumn[$columnId] = [];
}
// Start wrapping div
$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';
}
$content[$columnId] .= '">';
// Add new content at the top most position
$link = '';
if ($this->isContentEditable()
&& (!$this->checkIfTranslationsExistInLanguage($contentRecordsPerColumn, $lP))
) {
if ($this->option_newWizard) {
$urlParameters = [
'id' => $id,
'sys_language_uid' => $lP,
'colPos' => $columnId,
'uid_pid' => $id,
'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
];
$routeName = BackendUtility::getPagesTSconfig($id)['mod.']['newContentElementWizard.']['override']
?? 'new_content_element_wizard';
$url = (string)$this->uriBuilder->buildUriFromRoute($routeName, $urlParameters);
} else {
$urlParameters = [
'edit' => [
'tt_content' => [
$id => 'new'
]
],
'defVals' => [
'tt_content' => [
'colPos' => $columnId,
'sys_language_uid' => $lP
]
],
'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
];
$url = (string)$this->uriBuilder->buildUriFromRoute('record_edit', $urlParameters);
}
$title = htmlspecialchars($this->getLanguageService()->getLL('newContentElement'));
$link = '<a href="' . htmlspecialchars($url) . '" '
. 'title="' . $title . '"'
. 'data-title="' . $title . '"'
. 'class="btn btn-default btn-sm ' . ($this->option_newWizard ? 't3js-toggle-new-content-element-wizard' : '') . '">'
. $this->iconFactory->getIcon('actions-add', Icon::SIZE_SMALL)->render()
. ' '
. htmlspecialchars($this->getLanguageService()->getLL('content')) . '</a>';
}
if ($this->getBackendUser()->checkLanguageAccess($lP) && $columnId !== 'unused') {
$content[$columnId] .= '
<div class="t3-page-ce t3js-page-ce" data-page="' . (int)$id . '" id="' . StringUtility::getUniqueId() . '">
<div class="t3js-page-new-ce t3-page-ce-wrapper-new-ce" id="colpos-' . $columnId . '-page-' . $id . '-' . StringUtility::getUniqueId() . '">'
. $link
. '</div>
<div class="t3-page-ce-dropzone-available t3js-page-ce-dropzone-available"></div>
</div>
';
}
$editUidList = '';
if (!isset($contentRecordsPerColumn[$columnId]) || !is_array($contentRecordsPerColumn[$columnId])) {
$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 {
$rowArr = $contentRecordsPerColumn[$columnId];
$this->generateTtContentDataArray($rowArr);
foreach ((array)$rowArr as $rKey => $row) {
$this->contentElementCache[$lP][$columnId][$row['uid']] = $row;
if ($this->tt_contentConfig['languageMode']) {
$languageColumn[$columnId][$lP] = $head[$columnId] . $content[$columnId];
}
if (is_array($row) && !VersionState::cast($row['t3ver_state'])->equals(VersionState::DELETE_PLACEHOLDER)) {
$singleElementHTML = '<div class="t3-page-ce-dragitem" id="' . StringUtility::getUniqueId() . '">';
if (!$lP && ($this->defLangBinding || $row['sys_language_uid'] != -1)) {
$defaultLanguageElementsByColumn[$columnId][] = ($row['_ORIG_uid'] ?? $row['uid']);
}
$editUidList .= $row['uid'] . ',';
$disableMoveAndNewButtons = $this->defLangBinding && $lP > 0 && $this->checkIfTranslationsExistInLanguage($contentRecordsPerColumn, $lP);
$singleElementHTML .= $this->tt_content_drawHeader(
$row,
0,
$disableMoveAndNewButtons,
true,
$this->hasContentModificationAndAccessPermissions()
);
$innerContent = '<div ' . ($row['_ORIG_uid'] ? ' class="ver-element"' : '') . '>'
. $this->tt_content_drawItem($row) . '</div>';
$singleElementHTML .= '<div class="t3-page-ce-body-inner">' . $innerContent . '</div></div>'
. $this->tt_content_drawFooter($row);
$isDisabled = $this->isDisabled('tt_content', $row);
$statusHidden = $isDisabled ? ' t3-page-ce-hidden t3js-hidden-record' : '';
$displayNone = !$this->tt_contentConfig['showHidden'] && $isDisabled ? ' style="display: none;"' : '';
$highlightHeader = '';
if ($this->checkIfTranslationsExistInLanguage([], (int)$row['sys_language_uid']) && (int)$row['l18n_parent'] === 0) {
$highlightHeader = ' t3-page-ce-danger';
} elseif ($columnId === 'unused') {
$highlightHeader = ' t3-page-ce-warning';
}
$singleElementHTML = '<div class="t3-page-ce' . $highlightHeader . ' t3js-page-ce t3js-page-ce-sortable ' . $statusHidden . '" id="element-tt_content-'
. $row['uid'] . '" data-table="tt_content" data-uid="' . $row['uid'] . '"' . $displayNone . '>' . $singleElementHTML . '</div>';
$singleElementHTML .= '<div class="t3-page-ce" data-colpos="' . $columnId . '">';
$singleElementHTML .= '<div class="t3js-page-new-ce t3-page-ce-wrapper-new-ce" id="colpos-' . $columnId . '-page-' . $id .
'-' . StringUtility::getUniqueId() . '">';
// Add icon "new content element below"
if (!$disableMoveAndNewButtons
&& $this->isContentEditable($lP)
&& (!$this->checkIfTranslationsExistInLanguage($contentRecordsPerColumn, $lP))
&& $columnId !== 'unused'
) {
// New content element:
if ($this->option_newWizard) {
$urlParameters = [
'id' => $row['pid'],
'sys_language_uid' => $row['sys_language_uid'],
'colPos' => $row['colPos'],
'uid_pid' => -$row['uid'],
'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
];
$routeName = BackendUtility::getPagesTSconfig($row['pid'])['mod.']['newContentElementWizard.']['override']
?? 'new_content_element_wizard';
$url = (string)$this->uriBuilder->buildUriFromRoute($routeName, $urlParameters);
} else {
$urlParameters = [
'edit' => [
'tt_content' => [
-$row['uid'] => 'new'
]
],
'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
];
$url = (string)$this->uriBuilder->buildUriFromRoute('record_edit', $urlParameters);
}
$title = htmlspecialchars($this->getLanguageService()->getLL('newContentElement'));
$singleElementHTML .= '<a href="' . htmlspecialchars($url) . '" '
. 'title="' . $title . '"'
. 'data-title="' . $title . '"'
. 'class="btn btn-default btn-sm ' . ($this->option_newWizard ? 't3js-toggle-new-content-element-wizard' : '') . '">'
. $this->iconFactory->getIcon('actions-add', Icon::SIZE_SMALL)->render()
. ' '
. htmlspecialchars($this->getLanguageService()->getLL('content')) . '</a>';
}
$singleElementHTML .= '</div></div><div class="t3-page-ce-dropzone-available t3js-page-ce-dropzone-available"></div></div>';
if ($this->defLangBinding && $this->tt_contentConfig['languageMode']) {
$defLangBinding[$columnId][$lP][$row[$lP ? 'l18n_parent' : 'uid'] ?: $row['uid']] = $singleElementHTML;
} else {
$content[$columnId] .= $singleElementHTML;
}
} else {
unset($rowArr[$rKey]);
}
}
$content[$columnId] .= '</div>';
if ($columnId === 'unused') {
if (empty($unusedElementsMessage)) {
$unusedElementsMessage = GeneralUtility::makeInstance(
FlashMessage::class,
$this->getLanguageService()->getLL('staleUnusedElementsWarning'),
$this->getLanguageService()->getLL('staleUnusedElementsWarningTitle'),
FlashMessage::WARNING
);
$service = GeneralUtility::makeInstance(FlashMessageService::class);
$queue = $service->getMessageQueueByIdentifier();
$queue->addMessage($unusedElementsMessage);
}
$colTitle = $this->getLanguageService()->sL('LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:colPos.I.unused');
$editParam = '';
} else {
$colTitle = '';
foreach ($tcaItems as $item) {
if ($item[1] == $columnId) {
$colTitle = $this->getLanguageService()->sL($item[0]);
}
}
if (empty($colTitle)) {
$colTitle = BackendUtility::getProcessedValue('tt_content', 'colPos', $columnId);
}
$editParam = $this->doEdit && !empty($rowArr)
? '&edit[tt_content][' . $editUidList . ']=edit&recTitle=' . rawurlencode(BackendUtility::getRecordTitle('pages', $this->pageRecord, true))
: '';
}
$head[$columnId] .= $this->tt_content_drawColHeader($colTitle, $editParam);
}
}
// For each column, fit the rendered content into a table cell:
$out = '';
if ($this->tt_contentConfig['languageMode']) {
// in language mode process the content elements, but only fill $languageColumn. output will be generated later
$sortedLanguageColumn = [];
foreach ($cList as $columnId) {
if (GeneralUtility::inList($this->tt_contentConfig['activeCols'], $columnId) || $columnId === 'unused') {
$languageColumn[$columnId][$lP] = $head[$columnId] . $content[$columnId];
// We sort $languageColumn again according to $cList as it may contain data already from above.
$sortedLanguageColumn[$columnId] = $languageColumn[$columnId];
}
}
if (!empty($languageColumn['unused'])) {
$sortedLanguageColumn['unused'] = $languageColumn['unused'];
}
$languageColumn = $sortedLanguageColumn;
} else {
// GRID VIEW:
$grid = '<div class="t3-grid-container"><table border="0" cellspacing="0" cellpadding="0" width="100%" class="t3-page-columns t3-grid-table t3js-page-columns">';
// Add colgroups
$colCount = (int)$backendLayout['__config']['backend_layout.']['colCount'];
$rowCount = (int)$backendLayout['__config']['backend_layout.']['rowCount'];
$colSpan = 0;
$rowSpan = 0;
$grid .= '<colgroup>';
for ($i = 0; $i < $colCount; $i++) {
$grid .= '<col />';
}
$grid .= '</colgroup>';
// Check how to handle restricted columns
$hideRestrictedCols = (bool)(BackendUtility::getPagesTSconfig($id)['mod.']['web_layout.']['hideRestrictedCols'] ?? false);
// Cycle through rows
for ($row = 1; $row <= $rowCount; $row++) {
$rowConfig = $backendLayout['__config']['backend_layout.']['rows.'][$row . '.'];
if (!isset($rowConfig)) {
continue;
}
$grid .= '<tr>';
for ($col = 1; $col <= $colCount; $col++) {
$columnConfig = $rowConfig['columns.'][$col . '.'];
if (!isset($columnConfig)) {
continue;
}
// Which tt_content colPos should be displayed inside this cell
$columnKey = (int)$columnConfig['colPos'];
// Render the grid cell
$colSpan = (int)$columnConfig['colspan'];
$rowSpan = (int)$columnConfig['rowspan'];
$grid .= '<td valign="top"' .
($colSpan > 0 ? ' colspan="' . $colSpan . '"' : '') .
($rowSpan > 0 ? ' rowspan="' . $rowSpan . '"' : '') .
' data-colpos="' . (int)$columnConfig['colPos'] . '" data-language-uid="' . $lP . '" class="t3js-page-lang-column-' . $lP . ' t3js-page-column t3-grid-cell t3-page-column t3-page-column-' . $columnKey .
((!isset($columnConfig['colPos']) || $columnConfig['colPos'] === '') ? ' t3-grid-cell-unassigned' : '') .
((isset($columnConfig['colPos']) && $columnConfig['colPos'] !== '' && !$head[$columnKey]) || !GeneralUtility::inList($this->tt_contentConfig['activeCols'], $columnConfig['colPos']) ? ($hideRestrictedCols ? ' t3-grid-cell-restricted t3-grid-cell-hidden' : ' t3-grid-cell-restricted') : '') .
($colSpan > 0 ? ' t3-gridCell-width' . $colSpan : '') .
($rowSpan > 0 ? ' t3-gridCell-height' . $rowSpan : '') . '">';
// Draw the pre-generated header with edit and new buttons if a colPos is assigned.
// If not, a new header without any buttons will be generated.
if (isset($columnConfig['colPos']) && $columnConfig['colPos'] !== '' && $head[$columnKey]
&& GeneralUtility::inList($this->tt_contentConfig['activeCols'], $columnConfig['colPos'])
) {
$grid .= $head[$columnKey];
$grid .= $this->dispatchSectionMarkupGeneratedEvent('before', $lP, $columnConfig);
$grid .= $content[$columnKey];
} elseif (isset($columnConfig['colPos']) && $columnConfig['colPos'] !== ''
&& GeneralUtility::inList($this->tt_contentConfig['activeCols'], $columnConfig['colPos'])
) {
if (!$hideRestrictedCols) {
$grid .= $this->tt_content_drawColHeader($this->getLanguageService()->getLL('noAccess'));
$grid .= $this->dispatchSectionMarkupGeneratedEvent('before', $lP, $columnConfig);
}
} elseif (isset($columnConfig['colPos']) && $columnConfig['colPos'] !== ''
&& !GeneralUtility::inList($this->tt_contentConfig['activeCols'], $columnConfig['colPos'])
) {
if (!$hideRestrictedCols) {
$grid .= $this->tt_content_drawColHeader($this->getLanguageService()->sL($columnConfig['name']) .
' (' . $this->getLanguageService()->getLL('noAccess') . ')');
$grid .= $this->dispatchSectionMarkupGeneratedEvent('before', $lP, $columnConfig);
}
} elseif (isset($columnConfig['name']) && $columnConfig['name'] !== '') {
$grid .= $this->tt_content_drawColHeader($this->getLanguageService()->sL($columnConfig['name'])
. ' (' . $this->getLanguageService()->getLL('notAssigned') . ')');
$grid .= $this->dispatchSectionMarkupGeneratedEvent('before', $lP, $columnConfig);
} else {
$grid .= $this->tt_content_drawColHeader($this->getLanguageService()->getLL('notAssigned'));
$grid .= $this->dispatchSectionMarkupGeneratedEvent('before', $lP, $columnConfig);
}
$grid .= $this->dispatchSectionMarkupGeneratedEvent('after', $lP, $columnConfig);
$grid .= '</td>';
}
$grid .= '</tr>';
}
if (!empty($content['unused'])) {
$grid .= '<tr>';
// Which tt_content colPos should be displayed inside this cell
$columnKey = 'unused';
// Render the grid cell
$colSpan = (int)$backendLayout['__config']['backend_layout.']['colCount'];
$grid .= '<td valign="top"' .
($colSpan > 0 ? ' colspan="' . $colSpan . '"' : '') .
($rowSpan > 0 ? ' rowspan="' . $rowSpan . '"' : '') .
' data-colpos="unused" data-language-uid="' . $lP . '" class="t3js-page-lang-column-' . $lP . ' t3js-page-column t3-grid-cell t3-page-column t3-page-column-' . $columnKey .
($colSpan > 0 ? ' t3-gridCell-width' . $colSpan : '') . '">';
// Draw the pre-generated header with edit and new buttons if a colPos is assigned.
// If not, a new header without any buttons will be generated.
$grid .= $head[$columnKey] . $content[$columnKey];
$grid .= '</td></tr>';
}
$out .= $grid . '</table></div>';
}
}
$elFromTable = $this->clipboard->elFromTable('tt_content');
if (!empty($elFromTable) && $this->isPageEditable()) {
$pasteItem = substr(key($elFromTable), 11);
$pasteRecord = BackendUtility::getRecord('tt_content', (int)$pasteItem);
$pasteTitle = $pasteRecord['header'] ?: $pasteItem;
$copyMode = $this->clipboard->clipData['normal']['mode'] ? '-' . $this->clipboard->clipData['normal']['mode'] : '';
$inlineJavaScript = '
top.pasteIntoLinkTemplate = '
. $this->tt_content_drawPasteIcon($pasteItem, $pasteTitle, $copyMode, 't3js-paste-into', 'pasteIntoColumn')
. ';
top.pasteAfterLinkTemplate = '
. $this->tt_content_drawPasteIcon($pasteItem, $pasteTitle, $copyMode, 't3js-paste-after', 'pasteAfterRecord')
. ';';
} else {
$inlineJavaScript = '
top.pasteIntoLinkTemplate = \'\';
top.pasteAfterLinkTemplate = \'\';';
}
$pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
$pageRenderer->addJsInlineCode('pasteLinkTemplates', $inlineJavaScript);
// If language mode, then make another presentation:
// Notice that THIS presentation will override the value of $out!
// But it needs the code above to execute since $languageColumn is filled with content we need!
if ($this->tt_contentConfig['languageMode']) {
return $this->generateLanguageView($languageIds, $defaultLanguageElementsByColumn, $languageColumn);
}
return $out;
}
/**
* Shows the content elements of the selected languages in each column.
* @param array $languageIds languages to render
* @param array $defaultLanguageElementsByColumn
* @param array $languageColumn
* @return string the compiled content
*/
protected function generateLanguageView(array $languageIds, array $defaultLanguageElementsByColumn, array $languageColumn): string
{
// Get language selector:
$languageSelector = $this->languageSelector($this->id);
// Reset out - we will make new content here:
$out = '';
// Traverse languages found on the page and build up the table displaying them side by side:
$cCont = [];
$sCont = [];
foreach ($languageIds as $languageId) {
$languageMode = '';
$labelClass = 'info';
// Header:
$languageId = (int)$languageId;
// Determine language mode
if ($languageId > 0 && isset($this->languageHasTranslationsCache[$languageId]['mode'])) {
switch ($this->languageHasTranslationsCache[$languageId]['mode']) {
case 'mixed':
$languageMode = $this->getLanguageService()->getLL('languageModeMixed');
$labelClass = 'danger';
break;
case 'connected':
$languageMode = $this->getLanguageService()->getLL('languageModeConnected');
break;
case 'free':
$languageMode = $this->getLanguageService()->getLL('languageModeFree');
break;
default:
// we'll let opcode optimize this intentionally empty case
}
}
$columnAttributes = [
'valign' => 'top',
'class' => 't3-page-column t3-page-column-lang-name',
'data-language-uid' => $languageId,
'data-language-title' => $this->siteLanguages[$languageId]->getTitle(),
'data-flag-identifier' => $this->siteLanguages[$languageId]->getFlagIdentifier()
];
$cCont[$languageId] = '
<td ' . GeneralUtility::implodeAttributes($columnAttributes, true) . '>
<h2>' . htmlspecialchars($this->tt_contentConfig['languageCols'][$languageId]) . '</h2>
' . ($languageMode !== '' ? '<span class="label label-' . $labelClass . '">' . $languageMode . '</span>' : '') . '
</td>';
$editLink = '';
$recordIcon = '';
$viewLink = '';
// "View page" icon is added:
if (!VersionState::cast($this->pageinfo['t3ver_state'])->equals(VersionState::DELETE_PLACEHOLDER)) {
$onClick = BackendUtility::viewOnClick(
$this->id,
'',
BackendUtility::BEgetRootLine($this->id),
'',
'',
'&L=' . $languageId
);
$viewLink = '<a href="#" class="btn btn-default btn-sm" onclick="' . htmlspecialchars($onClick) . '" title="' . htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.showPage')) . '">' . $this->iconFactory->getIcon('actions-view', Icon::SIZE_SMALL)->render() . '</a>';
}
// Language overlay page header:
if ($languageId) {
$pageLocalizationRecord = BackendUtility::getRecordLocalization('pages', $this->id, $languageId);
if (is_array($pageLocalizationRecord)) {
$pageLocalizationRecord = reset($pageLocalizationRecord);
}
BackendUtility::workspaceOL('pages', $pageLocalizationRecord);
$recordIcon = BackendUtility::wrapClickMenuOnIcon(
$this->iconFactory->getIconForRecord('pages', $pageLocalizationRecord, Icon::SIZE_SMALL)->render(),
'pages',
$pageLocalizationRecord['uid']
);
$urlParameters = [
'edit' => [
'pages' => [
$pageLocalizationRecord['uid'] => 'edit'
]
],
// Disallow manual adjustment of the language field for pages
'overrideVals' => [
'pages' => [
'sys_language_uid' => $languageId
]
],
'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
];
$url = (string)$this->uriBuilder->buildUriFromRoute('record_edit', $urlParameters);
if ($this->getBackendUser()->check('tables_modify', 'pages')) {
$editLink = '<a href="' . htmlspecialchars($url) . '" class="btn btn-default btn-sm"'
. ' title="' . htmlspecialchars($this->getLanguageService()->getLL('edit')) . '">'
. $this->iconFactory->getIcon('actions-open', Icon::SIZE_SMALL)->render() . '</a>';
}
$defaultLanguageElements = [];
array_walk($defaultLanguageElementsByColumn, function (array $columnContent) use (&$defaultLanguageElements) {
$defaultLanguageElements = array_merge($defaultLanguageElements, $columnContent);
});
$localizationButtons = [];
$localizationButtons[] = $this->newLanguageButton(
$this->getNonTranslatedTTcontentUids($defaultLanguageElements, $this->id, $languageId),
$languageId
);
$languageLabel =
'<div class="btn-group">'
. $viewLink
. $editLink
. (!empty($localizationButtons) ? implode(LF, $localizationButtons) : '')
. '</div>'
. ' ' . $recordIcon . ' ' . htmlspecialchars(GeneralUtility::fixed_lgd_cs($pageLocalizationRecord['title'], 20))
;
} else {
if ($this->getBackendUser()->checkLanguageAccess(0)) {
$recordIcon = BackendUtility::wrapClickMenuOnIcon(
$this->iconFactory->getIconForRecord('pages', $this->pageRecord, Icon::SIZE_SMALL)->render(),
'pages',
$this->id
);
$urlParameters = [
'edit' => [
'pages' => [
$this->id => 'edit'
]
],
'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
];
$url = (string)$this->uriBuilder->buildUriFromRoute('record_edit', $urlParameters);
if ($this->getBackendUser()->check('tables_modify', 'pages')) {
$editLink = '<a href="' . htmlspecialchars($url) . '" class="btn btn-default btn-sm"'
. ' title="' . htmlspecialchars($this->getLanguageService()->getLL('edit')) . '">'
. $this->iconFactory->getIcon('actions-open', Icon::SIZE_SMALL)->render() . '</a>';
}
}
$languageLabel =
'<div class="btn-group">'
. $viewLink
. $editLink
. '</div>'
. ' ' . $recordIcon . ' ' . htmlspecialchars(GeneralUtility::fixed_lgd_cs($this->pageRecord['title'], 20));
}
$sCont[$languageId] = '
<td class="t3-page-column t3-page-lang-label nowrap">' . $languageLabel . '</td>';
}
// Add headers:
$out .= '<tr>' . implode('', $cCont) . '</tr>';
$out .= '<tr>' . implode('', $sCont) . '</tr>';
unset($cCont, $sCont);
// Traverse previously built content for the columns:
foreach ($languageColumn as $cKey => $cCont) {
$out .= '<tr>';
foreach ($cCont as $languageId => $columnContent) {
$out .= '<td valign="top" data-colpos="' . $cKey . '" class="t3-grid-cell t3-page-column t3js-page-column t3js-page-lang-column t3js-page-lang-column-' . $languageId . '">' . $columnContent . '</td>';
}
$out .= '</tr>';
if ($this->defLangBinding && !empty($defLangBinding[$cKey])) {
$maxItemsCount = max(array_map('count', $defLangBinding[$cKey]));
for ($i = 0; $i < $maxItemsCount; $i++) {
$defUid = $defaultLanguageElementsByColumn[$cKey][$i] ?? 0;
$cCont = [];
foreach ($languageIds as $languageId) {
if ($languageId > 0
&& is_array($defLangBinding[$cKey][$languageId])
&& !$this->checkIfTranslationsExistInLanguage($defaultLanguageElementsByColumn[$cKey], $languageId)
&& count($defLangBinding[$cKey][$languageId]) > $i
) {
$slice = array_slice($defLangBinding[$cKey][$languageId], $i, 1);
$element = $slice[0] ?? '';
} else {
$element = $defLangBinding[$cKey][$languageId][$defUid] ?? '';
}
$cCont[] = $element;
}
$out .= '
<tr>
<td valign="top" class="t3-grid-cell">' . implode('</td>
<td valign="top" class="t3-grid-cell">', $cCont) . '</td>
</tr>';
}
}
}
// Finally, wrap it all in a table and add the language selector on top of it:
return $languageSelector . '
<div class="t3-grid-container">
<table cellpadding="0" cellspacing="0" class="t3-page-columns t3-grid-table t3js-page-columns">
' . $out . '
</table>
</div>';
}
/**
* Gets content records per column.
* This is required for correct workspace overlays.
*
* @param string $table Name of table storing content records, by default tt_content
* @param int $id Page Id to be used (not used at all, but part of the API, see $this->pidSelect)
* @param array $columns colPos values to be considered to be shown
* @param string $additionalWhereClause Additional where clause for database select
* @return array Associative array for each column (colPos)
*/
protected function getContentRecordsPerColumn($table, $id, array $columns, $additionalWhereClause = '')
{
$contentRecordsPerColumn = array_fill_keys($columns, []);
$columns = array_flip($columns);
$queryBuilder = $this->getQueryBuilder(
$table,
$id,
[
$additionalWhereClause
]
);
// Traverse any selected elements and render their display code:
$results = $this->getResult($queryBuilder->execute());
$unused = [];
$hookArray = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['record_is_used'] ?? [];
foreach ($results as $record) {
$used = isset($columns[$record['colPos']]);
foreach ($hookArray as $_funcRef) {
$_params = ['columns' => $columns, 'record' => $record, 'used' => $used];
$used = GeneralUtility::callUserFunction($_funcRef, $_params, $this);
}
if ($used) {
$columnValue = (string)$record['colPos'];
$contentRecordsPerColumn[$columnValue][] = $record;
} else {
$unused[] = $record;
}
}
if (!empty($unused)) {
$contentRecordsPerColumn['unused'] = $unused;
}
return $contentRecordsPerColumn;
}
/**
* Draw header for a content element column:
*
* @param string $colName Column name
* @param string $editParams Edit params (Syntax: &edit[...] for FormEngine)
* @return string HTML table
*/
public function tt_content_drawColHeader($colName, $editParams = '')
{
$icons = '';
// Edit whole of column:
if ($editParams && $this->hasContentModificationAndAccessPermissions() && $this->getBackendUser()->checkLanguageAccess(0)) {
$link = $this->uriBuilder->buildUriFromRoute('record_edit') . $editParams . '&returnUrl=' . rawurlencode(GeneralUtility::getIndpEnv('REQUEST_URI'));
$icons = '<a href="' . htmlspecialchars($link) . '" title="'
. htmlspecialchars($this->getLanguageService()->getLL('editColumn')) . '">'
. $this->iconFactory->getIcon('actions-document-open', Icon::SIZE_SMALL)->render() . '</a>';
$icons = '<div class="t3-page-column-header-icons">' . $icons . '</div>';
}
return '<div class="t3-page-column-header">
' . $icons . '
<div class="t3-page-column-header-label">' . htmlspecialchars($colName) . '</div>
</div>';
}
/**
* Draw a paste icon either for pasting into a column or for pasting after a record
*
* @param int $pasteItem ID of the item in the clipboard
* @param string $pasteTitle Title for the JS modal
* @param string $copyMode copy or cut
* @param string $cssClass CSS class to determine if pasting is done into column or after record
* @param string $title title attribute of the generated link
*
* @return string Generated HTML code with link and icon
*/
protected function tt_content_drawPasteIcon($pasteItem, $pasteTitle, $copyMode, $cssClass, $title)
{
$pasteIcon = json_encode(
' <a data-content="' . htmlspecialchars($pasteItem) . '"'
. ' data-title="' . htmlspecialchars($pasteTitle) . '"'
. ' data-severity="warning"'
. ' class="t3js-paste t3js-paste' . htmlspecialchars($copyMode) . ' ' . htmlspecialchars($cssClass) . ' btn btn-default btn-sm"'
. ' title="' . htmlspecialchars($this->getLanguageService()->getLL($title)) . '">'
. $this->iconFactory->getIcon('actions-document-paste-into', Icon::SIZE_SMALL)->render()
. '</a>'
);
return $pasteIcon;
}
/**
* Draw the footer for a single tt_content element
*
* @param array $row Record array
* @return string HTML of the footer
* @throws \UnexpectedValueException
*/
protected function tt_content_drawFooter(array $row)
{
$content = '';
// Get processed values:
$info = [];
$this->getProcessedValue('tt_content', 'starttime,endtime,fe_group,space_before_class,space_after_class', $row, $info);
// Content element annotation
if (!empty($GLOBALS['TCA']['tt_content']['ctrl']['descriptionColumn']) && !empty($row[$GLOBALS['TCA']['tt_content']['ctrl']['descriptionColumn']])) {
$info[] = htmlspecialchars($row[$GLOBALS['TCA']['tt_content']['ctrl']['descriptionColumn']]);
}
// Call drawFooter hooks
foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['tt_content_drawFooter'] ?? [] as $className) {
$hookObject = GeneralUtility::makeInstance($className);
if (!$hookObject instanceof PageLayoutViewDrawFooterHookInterface) {
throw new \UnexpectedValueException($className . ' must implement interface ' . PageLayoutViewDrawFooterHookInterface::class, 1404378171);
}
$hookObject->preProcess($this, $info, $row);
}
// Display info from records fields:
if (!empty($info)) {