/
DatabaseRecordList.php
3269 lines (3043 loc) · 152 KB
/
DatabaseRecordList.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\RecordList;
use Psr\EventDispatcher\EventDispatcherInterface;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Backend\Clipboard\Clipboard;
use TYPO3\CMS\Backend\Configuration\TranslationConfigurationProvider;
use TYPO3\CMS\Backend\Module\ModuleData;
use TYPO3\CMS\Backend\Module\ModuleProvider;
use TYPO3\CMS\Backend\RecordList\Event\ModifyRecordListHeaderColumnsEvent;
use TYPO3\CMS\Backend\RecordList\Event\ModifyRecordListRecordActionsEvent;
use TYPO3\CMS\Backend\RecordList\Event\ModifyRecordListTableActionsEvent;
use TYPO3\CMS\Backend\Routing\PreviewUriBuilder;
use TYPO3\CMS\Backend\Routing\UriBuilder;
use TYPO3\CMS\Backend\Tree\Repository\PageTreeRepository;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Backend\View\BackendViewFactory;
use TYPO3\CMS\Backend\View\Event\ModifyDatabaseQueryForRecordListingEvent;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Cache\CacheManager;
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\QueryHelper;
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\Domain\Repository\PageRepository;
use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Imaging\IconFactory;
use TYPO3\CMS\Core\LinkHandling\Exception\UnknownLinkHandlerException;
use TYPO3\CMS\Core\LinkHandling\LinkService;
use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\CMS\Core\Messaging\FlashMessage;
use TYPO3\CMS\Core\Messaging\FlashMessageService;
use TYPO3\CMS\Core\Service\DependencyOrderingService;
use TYPO3\CMS\Core\Type\Bitmask\Permission;
use TYPO3\CMS\Core\Type\ContextualFeedbackSeverity;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\MathUtility;
use TYPO3\CMS\Core\Versioning\VersionState;
/**
* Class for rendering of Web>List module
* @internal This class is a specific TYPO3 Backend implementation and is not part of the TYPO3's Core API.
*/
class DatabaseRecordList
{
// *********
// External:
// *********
/**
* Used to indicate which tables (values in the array) that can have a
* create-new-record link. If the array is empty, all tables are allowed.
*
* @var string[]
*/
public $allowedNewTables = [];
/**
* Used to indicate which tables (values in the array) that cannot have a
* create-new-record link. If the array is empty, all tables are allowed.
*
* @var string[]
*/
public $deniedNewTables = [];
/**
* If TRUE, will show the clipboard related actions in the table header.
*
* @var bool
*/
public $showClipboardActions = false;
/**
* If TRUE, will DISABLE all control panels in lists. (Takes precedence)
*
* @var bool
*/
public $noControlPanels = false;
/**
* If TRUE, clickmenus will be rendered
*
* @var bool
*/
public $clickMenuEnabled = true;
/**
* Space icon used for alignment
*/
protected string $spaceIcon;
/**
* Disable single table view
*
* @var bool
*/
public $disableSingleTableView = false;
// *********
// Internal:
// *********
/**
* Set to the page record (see writeTop())
*
* @var string[]
*/
public $pageRow = [];
/**
* Tables which should not list their translations
*
* @var string
*/
public string $hideTranslations = '';
/**
* Cache for record path
*
* @var mixed[]
*/
protected array $recPath_cache = [];
/**
* Field, to sort list by
*/
public string $sortField = '';
/**
* Data of the module from the user's session
*/
protected ?ModuleData $moduleData = null;
/**
* Page id
*
* @var int
*/
public $id;
/**
* Used for tracking duplicate values of fields
*
* @var string[]
*/
protected array $duplicateStack = [];
/**
* If TRUE, records are listed only if a specific table is selected.
*
* @var bool
*/
public $listOnlyInSingleTableMode = false;
/**
* @var array[] Module configuration
*/
public $modTSconfig;
/**
* Keys are fieldnames and values are td-css-classes to add in addElement();
*/
protected array $addElement_tdCssClass = [];
/**
* Used for tracking next/prev uids
*
* @var int[][]
*/
public $currentTable = [];
/**
* Number of records to show
*/
public int $showLimit = 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 = [];
/**
* Tables which should not get listed
*
* @var string
*/
public $hideTables = '';
/**
* Page select permissions
*
* @var string
*/
public $perms_clause = '';
/**
* Return URL
*
* @var string
*/
public $returnUrl = '';
/**
* Tablename if single-table mode
*
* @var string
*/
public $table = '';
/**
* Some permissions...
*
* @var Permission
*/
public $calcPerms;
/**
* Mode for what happens when a user clicks the title of a record.
*
* @var string
*/
public $clickTitleMode = '';
/**
* Levels to search down.
*/
protected int $searchLevels = 0;
/**
* TSconfig which overwrites TCA-Settings
*
* @var string[][]
*/
public array $tableTSconfigOverTCA = [];
/**
* Fields to display for the current table
*
* @var string[][]
*/
public array $setFields = [];
/**
* Paging for the single table view
*
* @var int
*/
protected $page = 0;
/**
* Search string
*
* @var string
*/
public $searchString = '';
/**
* Field, indicating to sort in reverse order.
*
* @var bool
*/
public bool $sortRev = false;
/**
* String, can contain the field name from a table which must have duplicate values marked.
*/
protected string $duplicateField = '';
/**
* Specify a list of tables which are the only ones allowed to be displayed.
*
* @var string
*/
public $tableList = '';
/**
* Clipboard object
*
* @var Clipboard
*/
public $clipObj;
/**
* Tracking names of elements (for clipboard use)
*
* @var string[]
*/
public $CBnames = [];
/**
* Whether the column selector should be displayed in the tables' header
*
* @internal
*/
public bool $displayColumnSelector = true;
/**
* Whether the record download should be displayed in the tables' header
*
* @internal
*/
public bool $displayRecordDownload = true;
/**
* [$tablename][$uid] = number of references to this record
*
* @var int[][]
*/
protected array $referenceCount = [];
/**
* If defined the records are editable
*/
protected bool $editable = true;
/**
* Array with before/after setting for tables
* Structure:
* 'tableName' => [
* 'before' => ['A', ...]
* 'after' => []
* ]
*
* @var array[]
*/
protected array $tableDisplayOrder = [];
/**
* Override the page ids taken into account by getPageIdConstraint()
*/
protected array $overridePageIdList = [];
/**
* Override/add urlparameters in listUrl() method
* @var mixed[]
*/
protected array $overrideUrlParameters = [];
/**
* Current link: array with table names and uid
*/
protected array $currentLink = [];
/**
* Only used to render translated records, used in list module to show page translations
*/
protected bool $showOnlyTranslatedRecords = false;
/**
* This array contains all possible language uids, which could be translations of a record (excluding pages) in the default language
*
* It mainly depends on the current pageUid.
* Translations are possible, depending on
* - the site config
* - already translated page records
*
* @var int[]
*/
protected array $possibleTranslations = [];
/**
* All languages that are allowed by the user
*
* This is used for the translation handling of pages only.
*/
protected array $languagesAllowedForUser = [];
/**
* A runtime first-level cache to avoid unneeded calls to BackendUtility::getRecord()
*/
protected array $pagePermsCache = [];
protected array $showLocalizeColumn = [];
protected ServerRequestInterface $request;
public function __construct(
protected readonly IconFactory $iconFactory,
protected readonly UriBuilder $uriBuilder,
protected readonly TranslationConfigurationProvider $translateTools,
protected readonly EventDispatcherInterface $eventDispatcher,
protected readonly BackendViewFactory $backendViewFactory,
protected readonly ModuleProvider $moduleProvider,
) {
$this->calcPerms = new Permission();
$this->spaceIcon = '<span class="btn btn-default disabled" aria-hidden="true">' . $this->iconFactory->getIcon('empty-empty', Icon::SIZE_SMALL)->render() . '</span>';
}
public function setRequest(ServerRequestInterface $request)
{
$this->request = $request;
}
/**
* Returns a list of all fields / columns including meta columns such as
* "_REF_" or "_PATH_" which should be rendered for the database table.
*/
public function getColumnsToRender(string $table, bool $includeMetaColumns): array
{
$titleCol = $GLOBALS['TCA'][$table]['ctrl']['label'] ?? '';
// Setting fields selected in columnSelectorBox (saved in uc)
$rowListArray = [];
if (is_array($this->setFields[$table] ?? null)) {
$rowListArray = BackendUtility::getAllowedFieldsForTable($table);
if ($includeMetaColumns) {
$rowListArray[] = '_PATH_';
$rowListArray[] = '_REF_';
}
$rowListArray = array_intersect($rowListArray, $this->setFields[$table]);
}
// if no columns have been specified, show description (if configured)
if (!empty($GLOBALS['TCA'][$table]['ctrl']['descriptionColumn']) && empty($rowListArray)) {
$rowListArray[] = $GLOBALS['TCA'][$table]['ctrl']['descriptionColumn'];
}
// Initialize columns to select
$columnsToSelect = [$titleCol];
if ($includeMetaColumns) {
// If meta columns are enabled, add the record icon
array_unshift($columnsToSelect, 'icon');
if ($this->noControlPanels === false) {
// Add _SELECTOR_ as first item in case control panels are not disabled
array_unshift($columnsToSelect, '_SELECTOR_');
// Control-Panel
$columnsToSelect[] = '_CONTROL_';
}
// Path
if (!in_array('_PATH_', $rowListArray, true) && $this->searchLevels) {
$columnsToSelect[] = '_PATH_';
}
// Localization
if (BackendUtility::isTableLocalizable($table)) {
$columnsToSelect[] = '_LOCALIZATION_';
// Do not show the "Localize to:" field when only translated records should be shown
if (!$this->showOnlyTranslatedRecords) {
$columnsToSelect[] = '_LOCALIZATION_b';
}
}
}
return array_unique(array_merge($columnsToSelect, $rowListArray));
}
/**
* Based on the columns which should be rendered this method returns a list of actual
* database fields to be selected from the query string.
*
* @return string[] a list of all database table fields
*/
public function getFieldsToSelect(string $table, array $columnsToRender): array
{
$selectFields = $columnsToRender;
$selectFields[] = 'uid';
$selectFields[] = 'pid';
if ($table === 'pages') {
$selectFields[] = 'module';
$selectFields[] = 'extendToSubpages';
$selectFields[] = 'nav_hide';
$selectFields[] = 'doktype';
$selectFields[] = 'shortcut';
$selectFields[] = 'shortcut_mode';
$selectFields[] = 'mount_pid';
}
if (is_array($GLOBALS['TCA'][$table]['ctrl']['enablecolumns'] ?? null)) {
$selectFields = array_merge($selectFields, array_values($GLOBALS['TCA'][$table]['ctrl']['enablecolumns']));
}
foreach (['type', 'typeicon_column', 'editlock'] as $field) {
if ($GLOBALS['TCA'][$table]['ctrl'][$field] ?? false) {
$selectFields[] = $GLOBALS['TCA'][$table]['ctrl'][$field];
}
}
if (BackendUtility::isTableWorkspaceEnabled($table)) {
$selectFields[] = 't3ver_state';
$selectFields[] = 't3ver_wsid';
$selectFields[] = 't3ver_oid';
}
if (BackendUtility::isTableLocalizable($table)) {
$selectFields[] = $GLOBALS['TCA'][$table]['ctrl']['languageField'];
$selectFields[] = $GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField'];
}
if ($GLOBALS['TCA'][$table]['ctrl']['label_alt'] ?? false) {
$selectFields = array_merge(
$selectFields,
GeneralUtility::trimExplode(',', $GLOBALS['TCA'][$table]['ctrl']['label_alt'], true)
);
}
// Unique list!
$selectFields = array_unique($selectFields);
$fieldListFields = BackendUtility::getAllowedFieldsForTable($table, false);
// Making sure that the fields in the field-list ARE in the field-list from TCA!
return array_intersect($selectFields, $fieldListFields);
}
/**
* Creates the listing of records from a single table
*
* @param string $table Table name
* @throws \UnexpectedValueException
* @return string HTML table with the listing for the record.
*/
public function getTable($table)
{
// Finding the total amount of records on the page
$queryBuilderTotalItems = $this->getQueryBuilder($table, ['*'], false, 0, 1);
$totalItems = (int)$queryBuilderTotalItems->count('*')
->executeQuery()
->fetchOne();
if ($totalItems === 0) {
return '';
}
// set the limits
// Use default value and overwrite with page ts config and tca config depending on the current view
// Force limit in range 5, 10000
// default 100
$itemsLimitSingleTable = MathUtility::forceIntegerInRange((int)(
$GLOBALS['TCA'][$table]['interface']['maxSingleDBListItems'] ??
$this->modTSconfig['itemsLimitSingleTable'] ??
100
), 5, 10000);
// default 20
$itemsLimitPerTable = MathUtility::forceIntegerInRange((int)(
$GLOBALS['TCA'][$table]['interface']['maxDBListItems'] ??
$this->modTSconfig['itemsLimitPerTable'] ??
20
), 5, 10000);
// Set limit depending on the view (single table vs. default)
$itemsPerPage = $this->table ? $itemsLimitSingleTable : $itemsLimitPerTable;
// Set limit defined by calling code
if ($this->showLimit) {
$itemsPerPage = $this->showLimit;
}
// Set limit from search
if ($this->searchString) {
$itemsPerPage = $totalItems;
}
// Init
$titleCol = $GLOBALS['TCA'][$table]['ctrl']['label'];
$l10nEnabled = BackendUtility::isTableLocalizable($table);
$this->fieldArray = $this->getColumnsToRender($table, true);
// Creating the list of fields to include in the SQL query
$selectFields = $this->getFieldsToSelect($table, $this->fieldArray);
$firstElement = ($this->page - 1) * $itemsPerPage;
if ($firstElement > 2 && $itemsPerPage > 0) {
// Get the two previous rows for sorting if displaying page > 1
$firstElement -= 2;
$itemsPerPage += 2;
$queryBuilder = $this->getQueryBuilder($table, $selectFields, true, $firstElement, $itemsPerPage);
$firstElement += 2;
$itemsPerPage -= 2;
} else {
$queryBuilder = $this->getQueryBuilder($table, $selectFields, true, $firstElement, $itemsPerPage);
}
$queryResult = $queryBuilder->executeQuery();
$columnsOutput = '';
$onlyShowRecordsInSingleTableMode = $this->listOnlyInSingleTableMode && !$this->table;
// Fetch records only if not in single table mode
if ($onlyShowRecordsInSingleTableMode) {
$dbCount = $totalItems;
} elseif ($firstElement + $itemsPerPage <= $totalItems) {
$dbCount = $itemsPerPage + 2;
} else {
$dbCount = $totalItems - $firstElement + 2;
}
// If any records was selected, render the list:
if ($dbCount === 0) {
return '';
}
// Get configuration of collapsed tables from user uc
$lang = $this->getLanguageService();
$tableIdentifier = $table;
// Use a custom table title for translated pages
if ($table === 'pages' && $this->showOnlyTranslatedRecords) {
// pages records in list module are split into two own sections, one for pages with
// sys_language_uid = 0 "Page" and an own section for sys_language_uid > 0 "Page Translation".
// This if sets the different title for the page translation case and a unique table identifier
// which is used in DOM as id.
$tableTitle = htmlspecialchars($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:pageTranslation'));
$tableIdentifier = 'pages_translated';
} else {
$tableTitle = htmlspecialchars($lang->sL($GLOBALS['TCA'][$table]['ctrl']['title']));
if ($tableTitle === '') {
$tableTitle = $table;
}
}
$backendUser = $this->getBackendUserAuthentication();
$tableCollapsed = (bool)($this->moduleData?->get('collapsedTables')[$tableIdentifier] ?? false);
// Header line is drawn
$theData = [];
if ($this->disableSingleTableView) {
$theData[$titleCol] = $tableTitle . ' (<span class="t3js-table-total-items">' . $totalItems . '</span>)';
} else {
$icon = $this->table // @todo separate table header from contract/expand link
? $this->iconFactory
->getIcon('actions-view-table-collapse', Icon::SIZE_SMALL)
->setTitle($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_mod_web_list.xlf:contractView'))
->render()
: $this->iconFactory
->getIcon('actions-view-table-expand', Icon::SIZE_SMALL)
->setTitle($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_mod_web_list.xlf:expandView'))
->render();
$theData[$titleCol] = $this->linkWrapTable($table, $tableTitle . ' (<span class="t3js-table-total-items">' . $totalItems . '</span>) ' . $icon);
}
$tableActions = '';
$tableHeader = $theData[$titleCol];
if (!$onlyShowRecordsInSingleTableMode) {
// Add the "new record" button
$tableActions .= $this->createNewRecordButton($table);
// Render collapse button if in multi table mode
if (!$this->table) {
$title = sprintf(htmlspecialchars($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_mod_web_list.xlf:collapseExpandTable')), $tableTitle);
$tableActions .= '
<button type="button"'
. ' class="btn btn-sm btn-default t3js-toggle-recordlist"'
. ' title="' . $title . '"'
. ' aria-label="' . $title . '"'
. ' aria-expanded="' . ($tableCollapsed ? 'false' : 'true') . '"'
. ' data-recordlist-action="toggle"'
. ' data-table="' . htmlspecialchars($tableIdentifier) . '"'
. ' data-bs-toggle="collapse"'
. ' data-bs-target="#recordlist-' . htmlspecialchars($tableIdentifier) . '">'
. $this->iconFactory->getIcon(($tableCollapsed ? 'actions-view-list-expand' : 'actions-view-list-collapse'), Icon::SIZE_SMALL)->render()
. '</button>';
}
// Show the select box
$tableActions .= $this->columnSelector($table);
// Create the Download button
$tableActions .= $this->createDownloadButtonForTable($table, $totalItems);
}
$currentIdList = [];
// Render table rows only if in multi table view or if in single table view
$rowOutput = '';
if (!$onlyShowRecordsInSingleTableMode || $this->table) {
// Fixing an order table for sortby tables
$this->currentTable = [];
$allowManualSorting = ($GLOBALS['TCA'][$table]['ctrl']['sortby'] ?? false) && !$this->sortField;
$prevUid = 0;
$prevPrevUid = 0;
// Get first two rows and initialize prevPrevUid and prevUid if on page > 1
if ($firstElement > 2 && $itemsPerPage > 0) {
$row = $queryResult->fetchAssociative();
$prevPrevUid = -((int)$row['uid']);
$row = $queryResult->fetchAssociative();
$prevUid = $row['uid'];
}
$accRows = [];
// Accumulate rows here
while ($row = $queryResult->fetchAssociative()) {
if (!$this->isRowListingConditionFulfilled($table, $row)) {
continue;
}
// In offline workspace, look for alternative record
BackendUtility::workspaceOL($table, $row, $backendUser->workspace, true);
if (is_array($row)) {
$accRows[] = $row;
$currentIdList[] = $row['uid'];
if ($allowManualSorting) {
if ($prevUid) {
$this->currentTable['prev'][$row['uid']] = $prevPrevUid;
$this->currentTable['next'][$prevUid] = '-' . $row['uid'];
$this->currentTable['prevUid'][$row['uid']] = $prevUid;
}
$prevPrevUid = isset($this->currentTable['prev'][$row['uid']]) ? -$prevUid : $row['pid'];
$prevUid = $row['uid'];
}
}
}
// Render items:
$this->CBnames = [];
$this->duplicateStack = [];
$cc = 0;
// If no search happened it means that the selected
// records are either default or All language and here we will not select translations
// which point to the main record:
$listTranslatedRecords = $l10nEnabled && $this->searchString === '' && !($this->hideTranslations === '*' || GeneralUtility::inList($this->hideTranslations, $table));
foreach ($accRows as $row) {
// Render item row if counter < limit
if ($cc < $itemsPerPage) {
$cc++;
// Reset translations
$translations = [];
// Initialize with FALSE which causes the localization panel to not be displayed as
// the record is already localized, in free mode or has sys_language_uid -1 set.
// Only set to TRUE if TranslationConfigurationProvider::translationInfo() returns
// an array indicating the record can be translated.
$translationEnabled = false;
// Guard clause so we can quickly return if a record is localized to "all languages"
// It should only be possible to localize a record off default (uid 0)
if ($l10nEnabled && ($row[$GLOBALS['TCA'][$table]['ctrl']['languageField'] ?? null] ?? false) !== -1) {
$translationsRaw = $this->translateTools->translationInfo($table, $row['uid'], 0, $row, $selectFields);
if (is_array($translationsRaw)) {
$translationEnabled = true;
$translations = $translationsRaw['translations'] ?? [];
}
}
$rowOutput .= $this->renderListRow($table, $row, 0, $translations, $translationEnabled);
if ($listTranslatedRecords) {
foreach ($translations ?? [] as $lRow) {
if (!$this->isRowListingConditionFulfilled($table, $lRow)) {
continue;
}
// In offline workspace, look for alternative record:
BackendUtility::workspaceOL($table, $lRow, $backendUser->workspace, true);
if (is_array($lRow) && $backendUser->checkLanguageAccess($lRow[$GLOBALS['TCA'][$table]['ctrl']['languageField']])) {
$currentIdList[] = $lRow['uid'];
$rowOutput .= $this->renderListRow($table, $lRow, 1, [], false);
}
}
}
}
}
// Record navigation is added to the beginning and end of the table if in single table mode
if ($this->table) {
$pagination = $this->renderListNavigation($this->table, $totalItems, $itemsPerPage);
$rowOutput = $pagination . $rowOutput . $pagination;
} elseif ($totalItems > $itemsLimitPerTable) {
// Show that there are more records than shown
$rowOutput .= '
<tr data-multi-record-selection-element="true">
<td colspan="' . (count($this->fieldArray)) . '">
<a href="' . htmlspecialchars($this->listURL() . '&table=' . rawurlencode($tableIdentifier)) . '" class="btn btn-sm btn-default">
' . $this->iconFactory->getIcon('actions-caret-down', Icon::SIZE_SMALL)->render() . '
' . $this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.expandTable') . '
</a>
</td>
</tr>';
}
// The header row for the table is now created
$columnsOutput = $this->renderListHeader($table, $currentIdList);
}
// Initialize multi record selection actions
$multiRecordSelectionActions = '';
if ($this->noControlPanels === false) {
$multiRecordSelectionActions = '
<div class="recordlist-heading-row t3js-multi-record-selection-actions hidden">
<div class="recordlist-heading-title">
<strong>' . htmlspecialchars($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.selection')) . '</strong>
</div>
<div class="recordlist-heading-actions">
' . $this->renderMultiRecordSelectionActions($table, $currentIdList) . '
</div>
</div>
';
}
$recordListMessages = '';
$recordlistMessageEntries = [];
if ($backendUser->workspace > 0 && ExtensionManagementUtility::isLoaded('workspaces') && !BackendUtility::isTableWorkspaceEnabled($table)) {
// In case the table is not editable in workspace inform the user about the missing actions
if ($backendUser->workspaceAllowsLiveEditingInTable($table)) {
$recordlistMessageEntries[] = [
'message' => $lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.editingLiveRecordsWarning'),
'severity' => ContextualFeedbackSeverity::WARNING,
];
} else {
$recordlistMessageEntries[] = [
'message' => $lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.notEditableInWorkspace'),
'severity' => ContextualFeedbackSeverity::INFO,
];
}
}
foreach ($recordlistMessageEntries as $messageEntry) {
$recordListMessages .= '<div class="alert alert-' . $messageEntry['severity']->getCssClass() . '">';
$recordListMessages .= $this->iconFactory->getIcon($messageEntry['severity']->getIconIdentifier(), Icon::SIZE_SMALL)->render();
$recordListMessages .= ' ';
$recordListMessages .= htmlspecialchars($messageEntry['message'], ENT_QUOTES | ENT_HTML5);
$recordListMessages .= '</div>';
}
$collapseClass = $tableCollapsed && !$this->table ? 'collapse' : 'collapse show';
$dataState = $tableCollapsed && !$this->table ? 'collapsed' : 'expanded';
return '
<div class="recordlist" id="t3-table-' . htmlspecialchars($tableIdentifier) . '" data-multi-record-selection-identifier="t3-table-' . htmlspecialchars($tableIdentifier) . '">
<form action="' . htmlspecialchars($this->listURL()) . '#t3-table-' . htmlspecialchars($tableIdentifier) . '" method="post" name="list-table-form-' . htmlspecialchars($tableIdentifier) . '">
<input type="hidden" name="cmd_table" value="' . htmlspecialchars($tableIdentifier) . '" />
<input type="hidden" name="cmd" />
<div class="recordlist-heading ' . ($multiRecordSelectionActions !== '' ? 'multi-record-selection-panel' : '') . '">
<div class="recordlist-heading-row">
<div class="recordlist-heading-title">' . $tableHeader . '</div>
<div class="recordlist-heading-actions">' . $tableActions . '</div>
</div>
' . $multiRecordSelectionActions . '
</div>
' . $recordListMessages . '
<div class="' . $collapseClass . '" data-state="' . $dataState . '" id="recordlist-' . htmlspecialchars($tableIdentifier) . '">
<div class="table-fit">
<table data-table="' . htmlspecialchars($tableIdentifier) . '" class="table table-striped table-hover">
<thead>
' . $columnsOutput . '
</thead>
<tbody data-multi-record-selection-row-selection="true">
' . $rowOutput . '
</tbody>
</table>
</div>
</div>
</form>
</div>
';
}
/**
* If new records can be created on this page, create a button
*/
protected function createNewRecordButton(string $table): string
{
if (!$this->isEditable($table)) {
return '';
}
if (!$this->showNewRecLink($table)) {
return '';
}
$permsAdditional = ($table === 'pages' ? Permission::PAGE_NEW : Permission::CONTENT_EDIT);
if (!$this->calcPerms->isGranted($permsAdditional)) {
return '';
}
$iconIdentifier = 'actions-plus';
$title = $this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_mod_web_list.xlf:new');
$attributes = [
'title' => $title,
'aria-label' => $title,
'class' => 'btn btn-sm btn-default',
'data-recordlist-action' => 'new',
];
if ($table === 'tt_content') {
$attributes['url'] = (string)$this->uriBuilder->buildUriFromRoute(
'new_content_element_wizard',
[
'id' => $this->id,
'returnUrl' => $this->listURL(),
]
);
return '
<typo3-backend-new-content-element-wizard-button ' . GeneralUtility::implodeAttributes($attributes, true) . '">
' . $this->iconFactory->getIcon($iconIdentifier, Icon::SIZE_SMALL)->render() . '
' . htmlspecialchars($title) . '
</typo3-backend-new-content-element-wizard-button>';
}
if ($table === 'pages') {
$iconIdentifier = 'actions-page-new';
$attributes['data-new'] = 'page';
$attributes['href'] = (string)$this->uriBuilder->buildUriFromRoute(
'db_new_pages',
['id' => $this->id, 'returnUrl' => $this->listURL()]
);
} else {
$attributes['href'] = $this->uriBuilder->buildUriFromRoute(
'record_edit',
[
'edit' => [
$table => [
$this->id => 'new',
],
],
'returnUrl' => $this->listURL(),
]
);
}
return '
<a ' . GeneralUtility::implodeAttributes($attributes, true) . '>
' . $this->iconFactory->getIcon($iconIdentifier, Icon::SIZE_SMALL)->render() . '
' . htmlspecialchars($title) . '
</a>';
}
protected function createDownloadButtonForTable(string $table, int $totalItems): string
{
// Do not render the download button for page translations or in case it is disabled
if (!$this->displayRecordDownload
|| ($this->modTSconfig['noExportRecordsLinks'] ?? false)
|| $this->showOnlyTranslatedRecords
) {
return '';
}
$downloadButtonLabel = $this->getLanguageService()->sL('LLL:EXT:backend/Resources/Private/Language/locallang_download.xlf:download');
$downloadButtonTitle = sprintf($this->getLanguageService()->sL('LLL:EXT:backend/Resources/Private/Language/locallang_download.xlf:' . ($totalItems === 1 ? 'downloadRecord' : 'downloadRecords')), $totalItems);
$downloadCancelTitle = $this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.cancel');
$downloadSettingsUrl = $this->uriBuilder->buildUriFromRoute(
'ajax_record_download_settings',
['id' => $this->id, 'table' => $table, 'searchString' => $this->searchString, 'searchLevels' => $this->searchLevels]
);
$downloadSettingsTitle = sprintf(
$this->getLanguageService()->sL('LLL:EXT:backend/Resources/Private/Language/locallang_download.xlf:' . ($totalItems === 1 ? 'downloadRecordSettings' : 'downloadRecordsSettings')),
$this->getLanguageService()->sL($GLOBALS['TCA'][$table]['ctrl']['title'] ?? '') ?: $table,
$totalItems
);
return '
<typo3-recordlist-record-download-button
class="btn btn-sm btn-default"
url="' . htmlspecialchars($downloadSettingsUrl) . '"
subject="' . htmlspecialchars($downloadSettingsTitle) . '"
ok="' . htmlspecialchars($downloadButtonTitle) . '"
close="' . htmlspecialchars($downloadCancelTitle) . '"
data-recordlist-action="download"
>
' . $this->iconFactory->getIcon('actions-download', Icon::SIZE_SMALL) . '
' . htmlspecialchars($downloadButtonLabel) . '
</typo3-recordlist-record-download-button>';
}
/**
* Get preview link for pages or tt_content records
*/
protected function getPreviewUriBuilder(string $table, array $row): PreviewUriBuilder
{
if ($table === 'tt_content') {
// Link to a content element, possibly translated and with anchor
$previewUriBuilder = PreviewUriBuilder::create($this->id)
->withSection('#c' . $row['uid'])
->withLanguage((int)($row[$GLOBALS['TCA']['tt_content']['ctrl']['languageField'] ?? null] ?? 0));
} elseif ($table === 'pages' && ($row[$GLOBALS['TCA']['pages']['ctrl']['transOrigPointerField'] ?? null] ?? 0) > 0) {
// Link to a page translation needs uid of default language page as id
$previewUriBuilder = PreviewUriBuilder::create((int)$row[$GLOBALS['TCA']['pages']['ctrl']['transOrigPointerField']])
->withSection('#c' . $row['uid'])
->withLanguage((int)($row[$GLOBALS['TCA']['pages']['ctrl']['languageField'] ?? null] ?? 0));
} else {
// Link to a page in the default language
$previewUriBuilder = PreviewUriBuilder::create((int)($row['uid'] ?? 0));
}
return $previewUriBuilder;
}
/**
* Check if all row listing conditions are fulfilled.
*
* This function serves as a dummy method to be overridden in extending classes.
*
* @param string $table Table name
* @param string[] $row Record
* @return bool True, if all conditions are fulfilled.
*/
protected function isRowListingConditionFulfilled($table, $row)
{
return true;
}
/**
* Rendering a single row for the list
*
* @param string $table Table name
* @param mixed[] $row Current record
* @param int $indent Indent from left.
* @param array $translations Array of already existing translations for the current record
* @param bool $translationEnabled Whether the record can be translated
* @return string Table row for the element
* @internal
* @see getTable()
*/
public function renderListRow($table, array $row, int $indent, array $translations, bool $translationEnabled)
{
$titleCol = $GLOBALS['TCA'][$table]['ctrl']['label'] ?? '';
$languageService = $this->getLanguageService();
$rowOutput = '';
$id_orig = $this->id;
// If in search mode, make sure the preview will show the correct page
if ((string)$this->searchString !== '') {
$this->id = $row['pid'];
}