34ce004fc927c3d30429ab8b4d5174e9f64acab1
[Packages/TYPO3.CMS.git] / typo3 / sysext / recordlist / Classes / RecordList / DatabaseRecordList.php
1 <?php
2 namespace TYPO3\CMS\Recordlist\RecordList;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Backend\Configuration\TranslationConfigurationProvider;
18 use TYPO3\CMS\Backend\Module\BaseScriptClass;
19 use TYPO3\CMS\Backend\RecordList\RecordListGetTableHookInterface;
20 use TYPO3\CMS\Backend\Routing\UriBuilder;
21 use TYPO3\CMS\Backend\Template\Components\ButtonBar;
22 use TYPO3\CMS\Backend\Template\DocumentTemplate;
23 use TYPO3\CMS\Backend\Template\ModuleTemplate;
24 use TYPO3\CMS\Backend\Tree\View\PageTreeView;
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 use TYPO3\CMS\Core\Database\Query\Restriction\BackendWorkspaceRestriction;
32 use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
33 use TYPO3\CMS\Core\Imaging\Icon;
34 use TYPO3\CMS\Core\Imaging\IconFactory;
35 use TYPO3\CMS\Core\Localization\LanguageService;
36 use TYPO3\CMS\Core\Log\LogManager;
37 use TYPO3\CMS\Core\Messaging\FlashMessage;
38 use TYPO3\CMS\Core\Messaging\FlashMessageService;
39 use TYPO3\CMS\Core\Service\DependencyOrderingService;
40 use TYPO3\CMS\Core\Type\Bitmask\Permission;
41 use TYPO3\CMS\Core\Utility\CsvUtility;
42 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
43 use TYPO3\CMS\Core\Utility\GeneralUtility;
44 use TYPO3\CMS\Core\Utility\HttpUtility;
45 use TYPO3\CMS\Core\Utility\MathUtility;
46 use TYPO3\CMS\Frontend\Page\PageRepository;
47
48 /**
49 * Class for rendering of Web>List module
50 */
51 class DatabaseRecordList
52 {
53 // *********
54 // External:
55 // *********
56
57 /**
58 * Used to indicate which tables (values in the array) that can have a
59 * create-new-record link. If the array is empty, all tables are allowed.
60 *
61 * @var string[]
62 */
63 public $allowedNewTables = [];
64
65 /**
66 * Used to indicate which tables (values in the array) that cannot have a
67 * create-new-record link. If the array is empty, all tables are allowed.
68 *
69 * @var string[]
70 */
71 public $deniedNewTables = [];
72
73 /**
74 * If TRUE, the control panel will contain links to the create-new wizards for
75 * pages and tt_content elements (normally, the link goes to just creatinga new
76 * element without the wizards!).
77 *
78 * @var bool
79 */
80 public $newWizards = false;
81
82 /**
83 * If TRUE, will disable the rendering of clipboard + control panels.
84 *
85 * @var bool
86 */
87 public $dontShowClipControlPanels = false;
88
89 /**
90 * If TRUE, will show the clipboard in the field list.
91 *
92 * @var bool
93 */
94 public $showClipboard = false;
95
96 /**
97 * If TRUE, will DISABLE all control panels in lists. (Takes precedence)
98 *
99 * @var bool
100 */
101 public $noControlPanels = false;
102
103 /**
104 * If TRUE, clickmenus will be rendered
105 *
106 * @var bool
107 */
108 public $clickMenuEnabled = true;
109
110 /**
111 * Count of record rows in view
112 *
113 * @var int
114 */
115 public $totalRowCount;
116
117 /**
118 * Space icon used for alignment
119 *
120 * @var string
121 */
122 public $spaceIcon;
123
124 /**
125 * Disable single table view
126 *
127 * @var bool
128 */
129 public $disableSingleTableView = false;
130
131 // *********
132 // Internal:
133 // *********
134
135 /**
136 * Set to the page record (see writeTop())
137 *
138 * @var string[]
139 */
140 public $pageRow = [];
141
142 /**
143 * Shared module configuration, used by localization features
144 *
145 * @var array
146 */
147 public $modSharedTSconfig = [];
148
149 /**
150 * Contains page translation languages
151 *
152 * @var array
153 */
154 public $pageOverlays = [];
155
156 /**
157 * Contains sys language icons and titles
158 *
159 * @var array
160 */
161 public $languageIconTitles = [];
162
163 /**
164 * Tables which should not list their translations
165 *
166 * @var string
167 */
168 public $hideTranslations = '';
169
170 /**
171 * If set, the listing is returned as CSV instead.
172 *
173 * @var bool
174 */
175 public $csvOutput = false;
176
177 /**
178 * Cache for record path
179 *
180 * @var mixed[]
181 */
182 public $recPath_cache = [];
183
184 /**
185 * Field, to sort list by
186 *
187 * @var string
188 */
189 public $sortField;
190
191 /**
192 * default Max items shown per table in "multi-table mode", may be overridden by tables.php
193 *
194 * @var int
195 */
196 public $itemsLimitPerTable = 20;
197
198 /**
199 * Keys are fieldnames and values are td-parameters to add in addElement(), please use $addElement_tdCSSClass for CSS-classes;
200 *
201 * @var array
202 */
203 public $addElement_tdParams = [];
204
205 /**
206 * Page id
207 *
208 * @var int
209 */
210 public $id;
211
212 /**
213 * @var int
214 */
215 public $no_noWrap = 0;
216
217 /**
218 * Set to zero, if you don't want a left-margin with addElement function
219 *
220 * @var int
221 */
222 public $setLMargin = 1;
223
224 /**
225 * Used for tracking duplicate values of fields
226 *
227 * @var string[]
228 */
229 public $duplicateStack = [];
230
231 /**
232 * Current script name
233 *
234 * @var string
235 */
236 public $script = 'index.php';
237
238 /**
239 * If TRUE, records are listed only if a specific table is selected.
240 *
241 * @var bool
242 */
243 public $listOnlyInSingleTableMode = false;
244
245 /**
246 * Script URL
247 *
248 * @var string
249 */
250 public $thisScript = '';
251
252 /**
253 * JavaScript code accumulation
254 *
255 * @var string
256 */
257 public $JScode = '';
258
259 /**
260 * @var TranslationConfigurationProvider
261 */
262 public $translateTools;
263
264 /**
265 * default Max items shown per table in "single-table mode", may be overridden by tables.php
266 *
267 * @var int
268 */
269 public $itemsLimitSingleTable = 100;
270
271 /**
272 * Array of collapsed / uncollapsed tables in multi table view
273 *
274 * @var int[][]
275 */
276 public $tablesCollapsed = [];
277
278 /**
279 * @var array[] Module configuration
280 */
281 public $modTSconfig;
282
283 /**
284 * String with accumulated HTML content
285 *
286 * @var string
287 */
288 public $HTMLcode = '';
289
290 /**
291 * Keys are fieldnames and values are td-css-classes to add in addElement();
292 *
293 * @var array
294 */
295 public $addElement_tdCssClass = [];
296
297 /**
298 * Thumbnails on records containing files (pictures)
299 *
300 * @var bool
301 */
302 public $thumbs = 0;
303
304 /**
305 * Used for tracking next/prev uids
306 *
307 * @var int[][]
308 */
309 public $currentTable = [];
310
311 /**
312 * Indicates if all available fields for a user should be selected or not.
313 *
314 * @var int
315 */
316 public $allFields = 0;
317
318 /**
319 * Number of records to show
320 *
321 * @var int
322 */
323 public $showLimit = 0;
324
325 /**
326 * Decides the columns shown. Filled with values that refers to the keys of the data-array. $this->fieldArray[0] is the title column.
327 *
328 * @var array
329 */
330 public $fieldArray = [];
331
332 /**
333 * Tables which should not get listed
334 *
335 * @var string
336 */
337 public $hideTables = '';
338
339 /**
340 * Containing which fields to display in extended mode
341 *
342 * @var string[]
343 */
344 public $displayFields;
345
346 /**
347 * If set this is <td> CSS-classname for odd columns in addElement. Used with db_layout / pages section
348 *
349 * @var string
350 */
351 public $oddColumnsCssClass = '';
352
353 /**
354 * Not used in this class - but maybe extension classes...
355 * Max length of strings
356 *
357 * @var int
358 */
359 public $fixedL = 30;
360
361 /**
362 * Page select permissions
363 *
364 * @var string
365 */
366 public $perms_clause = '';
367
368 /**
369 * Return URL
370 *
371 * @var string
372 */
373 public $returnUrl = '';
374
375 /**
376 * Tablename if single-table mode
377 *
378 * @var string
379 */
380 public $table = '';
381
382 /**
383 * Some permissions...
384 *
385 * @var int
386 */
387 public $calcPerms = 0;
388
389 /**
390 * Mode for what happens when a user clicks the title of a record.
391 *
392 * @var string
393 */
394 public $clickTitleMode = '';
395
396 /**
397 * @var int
398 */
399 public $showIcon = 1;
400
401 /**
402 * Levels to search down.
403 *
404 * @var int
405 */
406 public $searchLevels = '';
407
408 /**
409 * "LIMIT " in SQL...
410 *
411 * @var int
412 */
413 public $iLimit = 0;
414
415 /**
416 * Set to the total number of items for a table when selecting.
417 *
418 * @var string
419 */
420 public $totalItems = '';
421
422 /**
423 * OBSOLETE - NOT USED ANYMORE. leftMargin
424 *
425 * @var int
426 */
427 public $leftMargin = 0;
428
429 /**
430 * TSconfig which overwrites TCA-Settings
431 *
432 * @var mixed[][]
433 */
434 public $tableTSconfigOverTCA = [];
435
436 /**
437 * Loaded with page record with version overlay if any.
438 *
439 * @var string[]
440 */
441 public $pageRecord = [];
442
443 /**
444 * Fields to display for the current table
445 *
446 * @var string[]
447 */
448 public $setFields = [];
449
450 /**
451 * Counter increased for each element. Used to index elements for the JavaScript-code that transfers to the clipboard
452 *
453 * @var int
454 */
455 public $counter = 0;
456
457 /**
458 * Pointer for browsing list
459 *
460 * @var int
461 */
462 public $firstElementNumber = 0;
463
464 /**
465 * Counting the elements no matter what...
466 *
467 * @var int
468 */
469 public $eCounter = 0;
470
471 /**
472 * Search string
473 *
474 * @var string
475 */
476 public $searchString = '';
477
478 /**
479 * Field, indicating to sort in reverse order.
480 *
481 * @var bool
482 */
483 public $sortRev;
484
485 /**
486 * String, can contain the field name from a table which must have duplicate values marked.
487 *
488 * @var string
489 */
490 public $duplicateField;
491
492 /**
493 * Specify a list of tables which are the only ones allowed to be displayed.
494 *
495 * @var string
496 */
497 public $tableList = '';
498
499 /**
500 * Used to accumulate CSV lines for CSV export.
501 *
502 * @var string[]
503 */
504 protected $csvLines = [];
505
506 /**
507 * Clipboard object
508 *
509 * @var \TYPO3\CMS\Backend\Clipboard\Clipboard
510 */
511 public $clipObj;
512
513 /**
514 * Tracking names of elements (for clipboard use)
515 *
516 * @var string[]
517 */
518 public $CBnames = [];
519
520 /**
521 * [$tablename][$uid] = number of references to this record
522 *
523 * @var int[][]
524 */
525 protected $referenceCount = [];
526
527 /**
528 * Translations of the current record
529 *
530 * @var string[]
531 */
532 public $translations;
533
534 /**
535 * select fields for the query which fetches the translations of the current
536 * record
537 *
538 * @var string
539 */
540 public $selFieldList;
541
542 /**
543 * @var mixed[]
544 */
545 public $pageinfo;
546
547 /**
548 * Injected by RecordList
549 *
550 * @var string[]
551 */
552 public $MOD_MENU;
553
554 /**
555 * If defined the records are editable
556 *
557 * @var bool
558 */
559 protected $editable = true;
560
561 /**
562 * @var IconFactory
563 */
564 protected $iconFactory;
565
566 /**
567 * Array with before/after setting for tables
568 * Structure:
569 * 'tableName' => [
570 * 'before' => ['A', ...]
571 * 'after' => []
572 * ]
573 *
574 * @var array[]
575 */
576 protected $tableDisplayOrder = [];
577
578 /**
579 * Override the page ids taken into account by getPageIdConstraint()
580 *
581 * @var array
582 */
583 protected $overridePageIdList = [];
584
585 /**
586 * Override/add urlparameters in listUrl() method
587 * @var string[]
588 */
589 protected $overrideUrlParameters = [];
590
591 /**
592 * Only used to render translated records, used in list module to show page translations
593 *
594 * @var bool
595 */
596 protected $showOnlyTranslatedRecords = false;
597
598 /**
599 * Constructor
600 */
601 public function __construct()
602 {
603 if (isset($GLOBALS['BE_USER']->uc['titleLen']) && $GLOBALS['BE_USER']->uc['titleLen'] > 0) {
604 $this->fixedL = $GLOBALS['BE_USER']->uc['titleLen'];
605 }
606 $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
607 $this->getTranslateTools();
608 $this->determineScriptUrl();
609
610 $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
611 }
612
613 /**
614 * Create the panel of buttons for submitting the form or otherwise perform
615 * operations.
616 *
617 * @return string[] All available buttons as an assoc. array
618 */
619 public function getButtons()
620 {
621 $module = $this->getModule();
622 $backendUser = $this->getBackendUserAuthentication();
623 $lang = $this->getLanguageService();
624 $buttons = [
625 'csh' => '',
626 'view' => '',
627 'edit' => '',
628 'hide_unhide' => '',
629 'move' => '',
630 'new_record' => '',
631 'paste' => '',
632 'level_up' => '',
633 'cache' => '',
634 'reload' => '',
635 'shortcut' => '',
636 'back' => '',
637 'csv' => '',
638 'export' => ''
639 ];
640 /** @var \TYPO3\CMS\Backend\Routing\UriBuilder $uriBuilder */
641 $uriBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Routing\UriBuilder::class);
642 // Get users permissions for this page record:
643 $localCalcPerms = $backendUser->calcPerms($this->pageRow);
644 // CSH
645 if ((string)$this->id === '') {
646 $buttons['csh'] = BackendUtility::cshItem('xMOD_csh_corebe', 'list_module_noId');
647 } elseif (!$this->id) {
648 $buttons['csh'] = BackendUtility::cshItem('xMOD_csh_corebe', 'list_module_root');
649 } else {
650 $buttons['csh'] = BackendUtility::cshItem('xMOD_csh_corebe', 'list_module');
651 }
652 if (isset($this->id)) {
653 // View Exclude doktypes 254,255 Configuration:
654 // mod.web_list.noViewWithDokTypes = 254,255
655 if (isset($module->modTSconfig['properties']['noViewWithDokTypes'])) {
656 $noViewDokTypes = GeneralUtility::trimExplode(',', $module->modTSconfig['properties']['noViewWithDokTypes'], true);
657 } else {
658 //default exclusion: doktype 254 (folder), 255 (recycler)
659 $noViewDokTypes = [
660 PageRepository::DOKTYPE_SYSFOLDER,
661 PageRepository::DOKTYPE_RECYCLER
662 ];
663 }
664 if (!in_array($this->pageRow['doktype'], $noViewDokTypes)) {
665 $onClick = htmlspecialchars(BackendUtility::viewOnClick($this->id, '', BackendUtility::BEgetRootLine($this->id)));
666 $buttons['view'] = '<a href="#" onclick="' . $onClick . '" title="'
667 . htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.showPage')) . '">'
668 . $this->iconFactory->getIcon('actions-document-view', Icon::SIZE_SMALL)->render() . '</a>';
669 }
670 // New record on pages that are not locked by editlock
671 if (!$module->modTSconfig['properties']['noCreateRecordsLink'] && $this->editLockPermissions()) {
672 $onClick = htmlspecialchars('return jumpExt(' . GeneralUtility::quoteJSvalue((string)$uriBuilder->buildUriFromRoute('db_new', ['id' => $this->id])) . ');');
673 $buttons['new_record'] = '<a href="#" onclick="' . $onClick . '" title="'
674 . htmlspecialchars($lang->getLL('newRecordGeneral')) . '">'
675 . $this->iconFactory->getIcon('actions-add', Icon::SIZE_SMALL)->render() . '</a>';
676 }
677 // If edit permissions are set, see
678 // \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
679 if ($localCalcPerms & Permission::PAGE_EDIT && !empty($this->id) && $this->editLockPermissions() && $this->getBackendUserAuthentication()->checkLanguageAccess(0)) {
680 // Edit
681 $params = '&edit[pages][' . $this->pageRow['uid'] . ']=edit';
682 $onClick = htmlspecialchars(BackendUtility::editOnClick($params, '', -1));
683 $buttons['edit'] = '<a href="#" onclick="' . $onClick . '" title="' . htmlspecialchars($lang->getLL('editPage')) . '">'
684 . $this->iconFactory->getIcon('actions-page-open', Icon::SIZE_SMALL)->render()
685 . '</a>';
686 }
687 // Paste
688 if (($localCalcPerms & Permission::PAGE_NEW || $localCalcPerms & Permission::CONTENT_EDIT) && $this->editLockPermissions()) {
689 $elFromTable = $this->clipObj->elFromTable('');
690 if (!empty($elFromTable)) {
691 $confirmText = $this->clipObj->confirmMsgText('pages', $this->pageRow, 'into', $elFromTable);
692 $buttons['paste'] = '<a'
693 . ' href="' . htmlspecialchars($this->clipObj->pasteUrl('', $this->id)) . '"'
694 . ' title="' . htmlspecialchars($lang->getLL('clip_paste')) . '"'
695 . ' class="t3js-modal-trigger"'
696 . ' data-severity="warning"'
697 . ' data-title="' . htmlspecialchars($lang->getLL('clip_paste')) . '"'
698 . ' data-content="' . htmlspecialchars($confirmText) . '"'
699 . '>'
700 . $this->iconFactory->getIcon('actions-document-paste-into', Icon::SIZE_SMALL)->render()
701 . '</a>';
702 }
703 }
704 // Cache
705 $buttons['cache'] = '<a href="' . htmlspecialchars(($this->listURL() . '&clear_cache=1')) . '" title="'
706 . htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.clear_cache')) . '">'
707 . $this->iconFactory->getIcon('actions-system-cache-clear', Icon::SIZE_SMALL)->render() . '</a>';
708 if ($this->table && (!isset($module->modTSconfig['properties']['noExportRecordsLinks'])
709 || (isset($module->modTSconfig['properties']['noExportRecordsLinks'])
710 && !$module->modTSconfig['properties']['noExportRecordsLinks']))
711 ) {
712 // CSV
713 $buttons['csv'] = '<a href="' . htmlspecialchars(($this->listURL() . '&csv=1')) . '" title="'
714 . htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.csv')) . '">'
715 . $this->iconFactory->getIcon('actions-document-export-csv', Icon::SIZE_SMALL)->render() . '</a>';
716 // Export
717 if (ExtensionManagementUtility::isLoaded('impexp')) {
718 $url = (string)$uriBuilder->buildUriFromRoute('xMOD_tximpexp', ['tx_impexp[action]' => 'export']);
719 $buttons['export'] = '<a href="' . htmlspecialchars($url . '&tx_impexp[list][]='
720 . rawurlencode($this->table . ':' . $this->id)) . '" title="'
721 . htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:rm.export')) . '">'
722 . $this->iconFactory->getIcon('actions-document-export-t3d', Icon::SIZE_SMALL)->render() . '</a>';
723 }
724 }
725 // Reload
726 $buttons['reload'] = '<a href="' . htmlspecialchars($this->listURL()) . '" title="'
727 . htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.reload')) . '">'
728 . $this->iconFactory->getIcon('actions-refresh', Icon::SIZE_SMALL)->render() . '</a>';
729 // Shortcut
730 if ($backendUser->mayMakeShortcut()) {
731 $buttons['shortcut'] = $this->getDocumentTemplate()->makeShortcutIcon(
732 'id, M, imagemode, pointer, table, search_field, search_levels, showLimit, sortField, sortRev',
733 implode(',', array_keys($this->MOD_MENU)),
734 'web_list'
735 );
736 }
737 // Back
738 if ($this->returnUrl) {
739 $href = htmlspecialchars(GeneralUtility::linkThisUrl($this->returnUrl, ['id' => $this->id]));
740 $buttons['back'] = '<a href="' . $href . '" class="typo3-goBack" title="'
741 . htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.goBack')) . '">'
742 . $this->iconFactory->getIcon('actions-view-go-back', Icon::SIZE_SMALL)->render() . '</a>';
743 }
744 }
745 return $buttons;
746 }
747
748 /**
749 * Create the panel of buttons for submitting the form or otherwise perform
750 * operations.
751 *
752 * @param ModuleTemplate $moduleTemplate
753 */
754 public function getDocHeaderButtons(ModuleTemplate $moduleTemplate)
755 {
756 $buttonBar = $moduleTemplate->getDocHeaderComponent()->getButtonBar();
757 $module = $this->getModule();
758 $backendUser = $this->getBackendUserAuthentication();
759 $lang = $this->getLanguageService();
760 // Get users permissions for this page record:
761 $localCalcPerms = $backendUser->calcPerms($this->pageRow);
762 /** @var \TYPO3\CMS\Backend\Routing\UriBuilder $uriBuilder */
763 $uriBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Routing\UriBuilder::class);
764 // CSH
765 if ((string)$this->id === '') {
766 $fieldName = 'list_module_noId';
767 } elseif (!$this->id) {
768 $fieldName = 'list_module_root';
769 } else {
770 $fieldName = 'list_module';
771 }
772 $cshButton = $buttonBar->makeHelpButton()
773 ->setModuleName('xMOD_csh_corebe')
774 ->setFieldName($fieldName);
775 $buttonBar->addButton($cshButton);
776 if (isset($this->id)) {
777 // View Exclude doktypes 254,255 Configuration:
778 // mod.web_list.noViewWithDokTypes = 254,255
779 if (isset($module->modTSconfig['properties']['noViewWithDokTypes'])) {
780 $noViewDokTypes = GeneralUtility::trimExplode(',', $module->modTSconfig['properties']['noViewWithDokTypes'], true);
781 } else {
782 //default exclusion: doktype 254 (folder), 255 (recycler)
783 $noViewDokTypes = [
784 PageRepository::DOKTYPE_SYSFOLDER,
785 PageRepository::DOKTYPE_RECYCLER
786 ];
787 }
788 // New record on pages that are not locked by editlock
789 if (!$module->modTSconfig['properties']['noCreateRecordsLink'] && $this->editLockPermissions()) {
790 $onClick = 'return jumpExt(' . GeneralUtility::quoteJSvalue((string)$uriBuilder->buildUriFromRoute('db_new', ['id' => $this->id])) . ');';
791 $newRecordButton = $buttonBar->makeLinkButton()
792 ->setHref('#')
793 ->setOnClick($onClick)
794 ->setTitle($lang->getLL('newRecordGeneral'))
795 ->setIcon($this->iconFactory->getIcon('actions-add', Icon::SIZE_SMALL));
796 $buttonBar->addButton($newRecordButton, ButtonBar::BUTTON_POSITION_LEFT, 10);
797 }
798 if (!in_array($this->pageRow['doktype'], $noViewDokTypes)) {
799 $onClick = BackendUtility::viewOnClick($this->id, '', BackendUtility::BEgetRootLine($this->id));
800 $viewButton = $buttonBar->makeLinkButton()
801 ->setHref('#')
802 ->setOnClick($onClick)
803 ->setTitle($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.showPage'))
804 ->setIcon($this->iconFactory->getIcon('actions-view-page', Icon::SIZE_SMALL));
805 $buttonBar->addButton($viewButton, ButtonBar::BUTTON_POSITION_LEFT, 20);
806 }
807 // If edit permissions are set, see
808 // \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
809 if ($localCalcPerms & Permission::PAGE_EDIT && !empty($this->id) && $this->editLockPermissions()) {
810 // Edit
811 $params = '&edit[pages][' . $this->pageRow['uid'] . ']=edit';
812 $onClick = BackendUtility::editOnClick($params, '', -1);
813 $editButton = $buttonBar->makeLinkButton()
814 ->setHref('#')
815 ->setOnClick($onClick)
816 ->setTitle($lang->getLL('editPage'))
817 ->setIcon($this->iconFactory->getIcon('actions-page-open', Icon::SIZE_SMALL));
818 $buttonBar->addButton($editButton, ButtonBar::BUTTON_POSITION_LEFT, 20);
819 }
820 // Paste
821 if ($this->showClipboard && ($localCalcPerms & Permission::PAGE_NEW || $localCalcPerms & Permission::CONTENT_EDIT) && $this->editLockPermissions()) {
822 $elFromTable = $this->clipObj->elFromTable('');
823 if (!empty($elFromTable)) {
824 $confirmMessage = $this->clipObj->confirmMsgText('pages', $this->pageRow, 'into', $elFromTable);
825 $pasteButton = $buttonBar->makeLinkButton()
826 ->setHref($this->clipObj->pasteUrl('', $this->id))
827 ->setTitle($lang->getLL('clip_paste'))
828 ->setClasses('t3js-modal-trigger')
829 ->setDataAttributes([
830 'severity' => 'warning',
831 'content' => $confirmMessage,
832 'title' => $lang->getLL('clip_paste')
833 ])
834 ->setIcon($this->iconFactory->getIcon('actions-document-paste-into', Icon::SIZE_SMALL));
835 $buttonBar->addButton($pasteButton, ButtonBar::BUTTON_POSITION_LEFT, 40);
836 }
837 }
838 // Cache
839 $clearCacheButton = $buttonBar->makeLinkButton()
840 ->setHref($this->listURL() . '&clear_cache=1')
841 ->setTitle($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.clear_cache'))
842 ->setIcon($this->iconFactory->getIcon('actions-system-cache-clear', Icon::SIZE_SMALL));
843 $buttonBar->addButton($clearCacheButton, ButtonBar::BUTTON_POSITION_RIGHT);
844 if ($this->table && (!isset($module->modTSconfig['properties']['noExportRecordsLinks'])
845 || (isset($module->modTSconfig['properties']['noExportRecordsLinks'])
846 && !$module->modTSconfig['properties']['noExportRecordsLinks']))
847 ) {
848 // CSV
849 $csvButton = $buttonBar->makeLinkButton()
850 ->setHref($this->listURL() . '&csv=1')
851 ->setTitle($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.csv'))
852 ->setIcon($this->iconFactory->getIcon('actions-document-export-csv', Icon::SIZE_SMALL));
853 $buttonBar->addButton($csvButton, ButtonBar::BUTTON_POSITION_LEFT, 40);
854 // Export
855 if (ExtensionManagementUtility::isLoaded('impexp')) {
856 $url = (string)$uriBuilder->buildUriFromRoute('xMOD_tximpexp', ['tx_impexp[action]' => 'export']);
857 $exportButton = $buttonBar->makeLinkButton()
858 ->setHref($url . '&tx_impexp[list][]=' . rawurlencode($this->table . ':' . $this->id))
859 ->setTitle($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:rm.export'))
860 ->setIcon($this->iconFactory->getIcon('actions-document-export-t3d', Icon::SIZE_SMALL));
861 $buttonBar->addButton($exportButton, ButtonBar::BUTTON_POSITION_LEFT, 40);
862 }
863 }
864 // Reload
865 $reloadButton = $buttonBar->makeLinkButton()
866 ->setHref($this->listURL())
867 ->setTitle($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.reload'))
868 ->setIcon($this->iconFactory->getIcon('actions-refresh', Icon::SIZE_SMALL));
869 $buttonBar->addButton($reloadButton, ButtonBar::BUTTON_POSITION_RIGHT);
870 // Shortcut
871 if ($backendUser->mayMakeShortcut()) {
872 $shortCutButton = $buttonBar->makeShortcutButton()
873 ->setModuleName('web_list')
874 ->setGetVariables([
875 'id',
876 'route',
877 'imagemode',
878 'pointer',
879 'table',
880 'search_field',
881 'search_levels',
882 'showLimit',
883 'sortField',
884 'sortRev'
885 ])
886 ->setSetVariables(array_keys($this->MOD_MENU));
887 $buttonBar->addButton($shortCutButton, ButtonBar::BUTTON_POSITION_RIGHT);
888 }
889 // Back
890 if ($this->returnUrl) {
891 $backButton = $buttonBar->makeLinkButton()
892 ->setHref($this->returnUrl)
893 ->setTitle($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.goBack'))
894 ->setIcon($this->iconFactory->getIcon('actions-view-go-back', Icon::SIZE_SMALL));
895 $buttonBar->addButton($backButton, ButtonBar::BUTTON_POSITION_LEFT);
896 }
897 }
898 }
899
900 /**
901 * Creates the listing of records from a single table
902 *
903 * @param string $table Table name
904 * @param int $id Page id
905 * @param string $rowList List of fields to show in the listing. Pseudo fields will be added including the record header.
906 * @throws \UnexpectedValueException
907 * @return string HTML table with the listing for the record.
908 */
909 public function getTable($table, $id, $rowList = '')
910 {
911 $rowListArray = GeneralUtility::trimExplode(',', $rowList, true);
912 // if no columns have been specified, show description (if configured)
913 if (!empty($GLOBALS['TCA'][$table]['ctrl']['descriptionColumn']) && empty($rowListArray)) {
914 $rowListArray[] = $GLOBALS['TCA'][$table]['ctrl']['descriptionColumn'];
915 }
916 $backendUser = $this->getBackendUserAuthentication();
917 $lang = $this->getLanguageService();
918 // Init
919 $addWhere = '';
920 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($table);
921 $titleCol = $GLOBALS['TCA'][$table]['ctrl']['label'];
922 $thumbsCol = $GLOBALS['TCA'][$table]['ctrl']['thumbnail'];
923 $l10nEnabled = $GLOBALS['TCA'][$table]['ctrl']['languageField']
924 && $GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField'];
925 $tableCollapsed = (bool)$this->tablesCollapsed[$table];
926 // prepare space icon
927 $this->spaceIcon = '<span class="btn btn-default disabled">' . $this->iconFactory->getIcon('empty-empty', Icon::SIZE_SMALL)->render() . '</span>';
928 // Cleaning rowlist for duplicates and place the $titleCol as the first column always!
929 $this->fieldArray = [];
930 // title Column
931 // Add title column
932 $this->fieldArray[] = $titleCol;
933 // Control-Panel
934 if (!GeneralUtility::inList($rowList, '_CONTROL_')) {
935 $this->fieldArray[] = '_CONTROL_';
936 }
937 // Clipboard
938 if ($this->showClipboard) {
939 $this->fieldArray[] = '_CLIPBOARD_';
940 }
941 // Ref
942 if (!$this->dontShowClipControlPanels) {
943 $this->fieldArray[] = '_REF_';
944 }
945 // Path
946 if ($this->searchLevels) {
947 $this->fieldArray[] = '_PATH_';
948 }
949 // Localization
950 if ($l10nEnabled) {
951 $this->fieldArray[] = '_LOCALIZATION_';
952 // Do not show the "Localize to:" field when only translated records should be shown
953 if (!$this->showOnlyTranslatedRecords) {
954 $this->fieldArray[] = '_LOCALIZATION_b';
955 }
956 // Only restrict to the default language if no search request is in place
957 // And if only translations should be shown
958 if ($this->searchString === '' && !$this->showOnlyTranslatedRecords) {
959 $addWhere = (string)$queryBuilder->expr()->orX(
960 $queryBuilder->expr()->lte($GLOBALS['TCA'][$table]['ctrl']['languageField'], 0),
961 $queryBuilder->expr()->eq($GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField'], 0)
962 );
963 }
964 }
965 // Cleaning up:
966 $this->fieldArray = array_unique(array_merge($this->fieldArray, $rowListArray));
967 if ($this->noControlPanels) {
968 $tempArray = array_flip($this->fieldArray);
969 unset($tempArray['_CONTROL_']);
970 unset($tempArray['_CLIPBOARD_']);
971 $this->fieldArray = array_keys($tempArray);
972 }
973 // Creating the list of fields to include in the SQL query:
974 $selectFields = $this->fieldArray;
975 $selectFields[] = 'uid';
976 $selectFields[] = 'pid';
977 // adding column for thumbnails
978 if ($thumbsCol) {
979 $selectFields[] = $thumbsCol;
980 }
981 if ($table === 'pages') {
982 $selectFields[] = 'module';
983 $selectFields[] = 'extendToSubpages';
984 $selectFields[] = 'nav_hide';
985 $selectFields[] = 'doktype';
986 $selectFields[] = 'shortcut';
987 $selectFields[] = 'shortcut_mode';
988 $selectFields[] = 'mount_pid';
989 }
990 if (is_array($GLOBALS['TCA'][$table]['ctrl']['enablecolumns'])) {
991 $selectFields = array_merge($selectFields, $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']);
992 }
993 foreach (['type', 'typeicon_column', 'editlock'] as $field) {
994 if ($GLOBALS['TCA'][$table]['ctrl'][$field]) {
995 $selectFields[] = $GLOBALS['TCA'][$table]['ctrl'][$field];
996 }
997 }
998 if ($GLOBALS['TCA'][$table]['ctrl']['versioningWS']) {
999 $selectFields[] = 't3ver_id';
1000 $selectFields[] = 't3ver_state';
1001 $selectFields[] = 't3ver_wsid';
1002 }
1003 if ($l10nEnabled) {
1004 $selectFields[] = $GLOBALS['TCA'][$table]['ctrl']['languageField'];
1005 $selectFields[] = $GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField'];
1006 }
1007 if ($GLOBALS['TCA'][$table]['ctrl']['label_alt']) {
1008 $selectFields = array_merge(
1009 $selectFields,
1010 GeneralUtility::trimExplode(',', $GLOBALS['TCA'][$table]['ctrl']['label_alt'], true)
1011 );
1012 }
1013 // Unique list!
1014 $selectFields = array_unique($selectFields);
1015 $fieldListFields = $this->makeFieldList($table, 1);
1016 if (empty($fieldListFields) && $GLOBALS['TYPO3_CONF_VARS']['BE']['debug']) {
1017 $message = sprintf($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_mod_web_list.xlf:missingTcaColumnsMessage'), $table, $table);
1018 $messageTitle = $lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_mod_web_list.xlf:missingTcaColumnsMessageTitle');
1019 /** @var FlashMessage $flashMessage */
1020 $flashMessage = GeneralUtility::makeInstance(
1021 FlashMessage::class,
1022 $message,
1023 $messageTitle,
1024 FlashMessage::WARNING,
1025 true
1026 );
1027 /** @var $flashMessageService FlashMessageService */
1028 $flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class);
1029 /** @var $defaultFlashMessageQueue \TYPO3\CMS\Core\Messaging\FlashMessageQueue */
1030 $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
1031 $defaultFlashMessageQueue->enqueue($flashMessage);
1032 }
1033 // Making sure that the fields in the field-list ARE in the field-list from TCA!
1034 $selectFields = array_intersect($selectFields, $fieldListFields);
1035 // Implode it into a list of fields for the SQL-statement.
1036 $selFieldList = implode(',', $selectFields);
1037 $this->selFieldList = $selFieldList;
1038 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.db_list_extra.inc']['getTable'] ?? [] as $className) {
1039 $hookObject = GeneralUtility::makeInstance($className);
1040 if (!$hookObject instanceof RecordListGetTableHookInterface) {
1041 throw new \UnexpectedValueException($className . ' must implement interface ' . RecordListGetTableHookInterface::class, 1195114460);
1042 }
1043 $hookObject->getDBlistQuery($table, $id, $addWhere, $selFieldList, $this);
1044 }
1045 $additionalConstraints = empty($addWhere) ? [] : [QueryHelper::stripLogicalOperatorPrefix($addWhere)];
1046 $selFieldList = GeneralUtility::trimExplode(',', $selFieldList, true);
1047
1048 // Create the SQL query for selecting the elements in the listing:
1049 // do not do paging when outputting as CSV
1050 if ($this->csvOutput) {
1051 $this->iLimit = 0;
1052 }
1053 if ($this->firstElementNumber > 2 && $this->iLimit > 0) {
1054 // Get the two previous rows for sorting if displaying page > 1
1055 $this->firstElementNumber -= 2;
1056 $this->iLimit += 2;
1057 // (API function from TYPO3\CMS\Recordlist\RecordList\AbstractDatabaseRecordList)
1058 $queryBuilder = $this->getQueryBuilder($table, $id, $additionalConstraints);
1059 $this->firstElementNumber += 2;
1060 $this->iLimit -= 2;
1061 } else {
1062 // (API function from TYPO3\CMS\Recordlist\RecordList\AbstractDatabaseRecordList)
1063 $queryBuilder = $this->getQueryBuilder($table, $id, $additionalConstraints);
1064 }
1065
1066 // Finding the total amount of records on the page
1067 // (API function from TYPO3\CMS\Recordlist\RecordList\AbstractDatabaseRecordList)
1068 $this->setTotalItems($table, $id, $additionalConstraints);
1069
1070 // Init:
1071 $queryResult = $queryBuilder->execute();
1072 $dbCount = 0;
1073 $out = '';
1074 $tableHeader = '';
1075 $listOnlyInSingleTableMode = $this->listOnlyInSingleTableMode && !$this->table;
1076 // If the count query returned any number of records, we perform the real query,
1077 // selecting records.
1078 if ($this->totalItems) {
1079 // Fetch records only if not in single table mode
1080 if ($listOnlyInSingleTableMode) {
1081 $dbCount = $this->totalItems;
1082 } else {
1083 // Set the showLimit to the number of records when outputting as CSV
1084 if ($this->csvOutput) {
1085 $this->showLimit = $this->totalItems;
1086 $this->iLimit = $this->totalItems;
1087 }
1088 $dbCount = $queryResult->rowCount();
1089 }
1090 }
1091 // If any records was selected, render the list:
1092 if ($dbCount) {
1093 // Use a custom table title for translated pages
1094 if ($table == 'pages' && $this->showOnlyTranslatedRecords) {
1095 $tableTitle = htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:pageTranslation'));
1096 } else {
1097 $tableTitle = htmlspecialchars($lang->sL($GLOBALS['TCA'][$table]['ctrl']['title']));
1098 if ($tableTitle === '') {
1099 $tableTitle = $table;
1100 }
1101 }
1102 // Header line is drawn
1103 $theData = [];
1104 if ($this->disableSingleTableView) {
1105 $theData[$titleCol] = '<span class="c-table">' . BackendUtility::wrapInHelp($table, '', $tableTitle)
1106 . '</span> (<span class="t3js-table-total-items">' . $this->totalItems . '</span>)';
1107 } else {
1108 $icon = $this->table
1109 ? '<span title="' . htmlspecialchars($lang->getLL('contractView')) . '">' . $this->iconFactory->getIcon('actions-view-table-collapse', Icon::SIZE_SMALL)->render() . '</span>'
1110 : '<span title="' . htmlspecialchars($lang->getLL('expandView')) . '">' . $this->iconFactory->getIcon('actions-view-table-expand', Icon::SIZE_SMALL)->render() . '</span>';
1111 $theData[$titleCol] = $this->linkWrapTable($table, $tableTitle . ' (<span class="t3js-table-total-items">' . $this->totalItems . '</span>) ' . $icon);
1112 }
1113 if ($listOnlyInSingleTableMode) {
1114 $tableHeader .= BackendUtility::wrapInHelp($table, '', $theData[$titleCol]);
1115 } else {
1116 // Render collapse button if in multi table mode
1117 $collapseIcon = '';
1118 if (!$this->table) {
1119 $href = htmlspecialchars(($this->listURL() . '&collapse[' . $table . ']=' . ($tableCollapsed ? '0' : '1')));
1120 $title = $tableCollapsed
1121 ? htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.expandTable'))
1122 : htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.collapseTable'));
1123 $icon = '<span class="collapseIcon">' . $this->iconFactory->getIcon(($tableCollapsed ? 'actions-view-list-expand' : 'actions-view-list-collapse'), Icon::SIZE_SMALL)->render() . '</span>';
1124 $collapseIcon = '<a href="' . $href . '" title="' . $title . '" class="pull-right t3js-toggle-recordlist" data-table="' . htmlspecialchars($table) . '" data-toggle="collapse" data-target="#recordlist-' . htmlspecialchars($table) . '">' . $icon . '</a>';
1125 }
1126 $tableHeader .= $theData[$titleCol] . $collapseIcon;
1127 }
1128 // Render table rows only if in multi table view or if in single table view
1129 $rowOutput = '';
1130 if (!$listOnlyInSingleTableMode || $this->table) {
1131 // Fixing an order table for sortby tables
1132 $this->currentTable = [];
1133 $currentIdList = [];
1134 $doSort = $GLOBALS['TCA'][$table]['ctrl']['sortby'] && !$this->sortField;
1135 $prevUid = 0;
1136 $prevPrevUid = 0;
1137 // Get first two rows and initialize prevPrevUid and prevUid if on page > 1
1138 if ($this->firstElementNumber > 2 && $this->iLimit > 0) {
1139 $row = $queryResult->fetch();
1140 $prevPrevUid = -((int)$row['uid']);
1141 $row = $queryResult->fetch();
1142 $prevUid = $row['uid'];
1143 }
1144 $accRows = [];
1145 // Accumulate rows here
1146 while ($row = $queryResult->fetch()) {
1147 if (!$this->isRowListingConditionFulfilled($table, $row)) {
1148 continue;
1149 }
1150 // In offline workspace, look for alternative record:
1151 BackendUtility::workspaceOL($table, $row, $backendUser->workspace, true);
1152 if (is_array($row)) {
1153 $accRows[] = $row;
1154 $currentIdList[] = $row['uid'];
1155 if ($doSort) {
1156 if ($prevUid) {
1157 $this->currentTable['prev'][$row['uid']] = $prevPrevUid;
1158 $this->currentTable['next'][$prevUid] = '-' . $row['uid'];
1159 $this->currentTable['prevUid'][$row['uid']] = $prevUid;
1160 }
1161 $prevPrevUid = isset($this->currentTable['prev'][$row['uid']]) ? -$prevUid : $row['pid'];
1162 $prevUid = $row['uid'];
1163 }
1164 }
1165 }
1166 $this->totalRowCount = count($accRows);
1167 // CSV initiated
1168 if ($this->csvOutput) {
1169 $this->initCSV();
1170 }
1171 // Render items:
1172 $this->CBnames = [];
1173 $this->duplicateStack = [];
1174 $this->eCounter = $this->firstElementNumber;
1175 $cc = 0;
1176 foreach ($accRows as $row) {
1177 // Render item row if counter < limit
1178 if ($cc < $this->iLimit) {
1179 $cc++;
1180 $this->translations = false;
1181 $rowOutput .= $this->renderListRow($table, $row, $cc, $titleCol, $thumbsCol);
1182 // If no search happened it means that the selected
1183 // records are either default or All language and here we will not select translations
1184 // which point to the main record:
1185 if ($l10nEnabled && $this->searchString === '') {
1186 // For each available translation, render the record:
1187 if (is_array($this->translations)) {
1188 foreach ($this->translations as $lRow) {
1189 // $lRow isn't always what we want - if record was moved we've to work with the
1190 // placeholder records otherwise the list is messed up a bit
1191 if ($row['_MOVE_PLH_uid'] && $row['_MOVE_PLH_pid']) {
1192 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
1193 ->getQueryBuilderForTable($table);
1194 $queryBuilder->getRestrictions()
1195 ->removeAll()
1196 ->add(GeneralUtility::makeInstance(DeletedRestriction::class));
1197 $predicates = [
1198 $queryBuilder->expr()->eq(
1199 't3ver_move_id',
1200 $queryBuilder->createNamedParameter((int)$lRow['uid'], \PDO::PARAM_INT)
1201 ),
1202 $queryBuilder->expr()->eq(
1203 'pid',
1204 $queryBuilder->createNamedParameter((int)$row['_MOVE_PLH_pid'], \PDO::PARAM_INT)
1205 ),
1206 $queryBuilder->expr()->eq(
1207 't3ver_wsid',
1208 $queryBuilder->createNamedParameter((int)$row['t3ver_wsid'], \PDO::PARAM_INT)
1209 ),
1210 ];
1211
1212 $tmpRow = $queryBuilder
1213 ->select(...$selFieldList)
1214 ->from($table)
1215 ->andWhere(...$predicates)
1216 ->execute()
1217 ->fetch();
1218
1219 $lRow = is_array($tmpRow) ? $tmpRow : $lRow;
1220 }
1221 // In offline workspace, look for alternative record:
1222 BackendUtility::workspaceOL($table, $lRow, $backendUser->workspace, true);
1223 if (is_array($lRow) && $backendUser->checkLanguageAccess($lRow[$GLOBALS['TCA'][$table]['ctrl']['languageField']])) {
1224 $currentIdList[] = $lRow['uid'];
1225 $rowOutput .= $this->renderListRow($table, $lRow, $cc, $titleCol, $thumbsCol, 18);
1226 }
1227 }
1228 }
1229 }
1230 }
1231 // Counter of total rows incremented:
1232 $this->eCounter++;
1233 }
1234 // Record navigation is added to the beginning and end of the table if in single
1235 // table mode
1236 if ($this->table) {
1237 $rowOutput = $this->renderListNavigation('top') . $rowOutput . $this->renderListNavigation('bottom');
1238 } else {
1239 // Show that there are more records than shown
1240 if ($this->totalItems > $this->itemsLimitPerTable) {
1241 $countOnFirstPage = $this->totalItems > $this->itemsLimitSingleTable ? $this->itemsLimitSingleTable : $this->totalItems;
1242 $hasMore = $this->totalItems > $this->itemsLimitSingleTable;
1243 $colspan = $this->showIcon ? count($this->fieldArray) + 1 : count($this->fieldArray);
1244 $rowOutput .= '<tr><td colspan="' . $colspan . '">
1245 <a href="' . htmlspecialchars(($this->listURL() . '&table=' . rawurlencode($table))) . '" class="btn btn-default">'
1246 . '<span class="t3-icon fa fa-chevron-down"></span> <i>[1 - ' . $countOnFirstPage . ($hasMore ? '+' : '') . ']</i></a>
1247 </td></tr>';
1248 }
1249 }
1250 // The header row for the table is now created:
1251 $out .= $this->renderListHeader($table, $currentIdList);
1252 }
1253
1254 $collapseClass = $tableCollapsed && !$this->table ? 'collapse' : 'collapse in';
1255 $dataState = $tableCollapsed && !$this->table ? 'collapsed' : 'expanded';
1256
1257 // The list of records is added after the header:
1258 $out .= $rowOutput;
1259 // ... and it is all wrapped in a table:
1260 $out = '
1261
1262
1263
1264 <!--
1265 DB listing of elements: "' . htmlspecialchars($table) . '"
1266 -->
1267 <div class="panel panel-space panel-default recordlist">
1268 <div class="panel-heading">
1269 ' . $tableHeader . '
1270 </div>
1271 <div class="' . $collapseClass . '" data-state="' . $dataState . '" id="recordlist-' . htmlspecialchars($table) . '">
1272 <div class="table-fit">
1273 <table data-table="' . htmlspecialchars($table) . '" class="table table-striped table-hover' . ($listOnlyInSingleTableMode ? ' typo3-dblist-overview' : '') . '">
1274 ' . $out . '
1275 </table>
1276 </div>
1277 </div>
1278 </div>
1279 ';
1280 // Output csv if...
1281 // This ends the page with exit.
1282 if ($this->csvOutput) {
1283 $this->outputCSV($table);
1284 }
1285 }
1286 // Return content:
1287 return $out;
1288 }
1289
1290 /**
1291 * Get viewOnClick link for pages or tt_content records
1292 *
1293 * @param string $table
1294 * @param array $row
1295 *
1296 * @return string
1297 */
1298 protected function getOnClickForRow(string $table, array $row): string
1299 {
1300 if ($table === 'tt_content') {
1301 // Link to a content element
1302 $onClick = BackendUtility::viewOnClick($this->id, '', null, '#' . $row['uid']);
1303 } elseif ($table === 'pages' && $row[$GLOBALS['TCA']['pages']['ctrl']['transOrigPointerField']] > 0) {
1304 // Link to a page translation
1305 $onClick = BackendUtility::viewOnClick(
1306 $row[$GLOBALS['TCA']['pages']['ctrl']['transOrigPointerField']],
1307 '',
1308 null,
1309 '',
1310 '',
1311 '&L=' . $row[$GLOBALS['TCA']['pages']['ctrl']['languageField']]
1312 );
1313 } else {
1314 // Link to a page in the default language
1315 $onClick = BackendUtility::viewOnClick($row['uid']);
1316 }
1317 return $onClick;
1318 }
1319
1320 /**
1321 * Check if all row listing conditions are fulfilled.
1322 *
1323 * This function serves as a dummy method to be overridden in extending classes.
1324 *
1325 * @param string $table Table name
1326 * @param string[] $row Record
1327 * @return bool True, if all conditions are fulfilled.
1328 */
1329 protected function isRowListingConditionFulfilled($table, $row)
1330 {
1331 return true;
1332 }
1333
1334 /**
1335 * Rendering a single row for the list
1336 *
1337 * @param string $table Table name
1338 * @param mixed[] $row Current record
1339 * @param int $cc Counter, counting for each time an element is rendered (used for alternating colors)
1340 * @param string $titleCol Table field (column) where header value is found
1341 * @param string $thumbsCol Table field (column) where (possible) thumbnails can be found
1342 * @param int $indent Indent from left.
1343 * @return string Table row for the element
1344 * @access private
1345 * @see getTable()
1346 */
1347 public function renderListRow($table, $row, $cc, $titleCol, $thumbsCol, $indent = 0)
1348 {
1349 if (!is_array($row)) {
1350 return '';
1351 }
1352 $rowOutput = '';
1353 $id_orig = null;
1354 // If in search mode, make sure the preview will show the correct page
1355 if ((string)$this->searchString !== '') {
1356 $id_orig = $this->id;
1357 $this->id = $row['pid'];
1358 }
1359
1360 $tagAttributes = [
1361 'class' => ['t3js-entity'],
1362 'data-table' => $table,
1363 'title' => 'id=' . $row['uid'],
1364 ];
1365
1366 // Add special classes for first and last row
1367 if ($cc == 1 && $indent == 0) {
1368 $tagAttributes['class'][] = 'firstcol';
1369 }
1370 if ($cc == $this->totalRowCount || $cc == $this->iLimit) {
1371 $tagAttributes['class'][] = 'lastcol';
1372 }
1373 // Overriding with versions background color if any:
1374 if (!empty($row['_CSSCLASS'])) {
1375 $tagAttributes['class'] = [$row['_CSSCLASS']];
1376 }
1377 // Incr. counter.
1378 $this->counter++;
1379 // The icon with link
1380 $toolTip = BackendUtility::getRecordToolTip($row, $table);
1381 $additionalStyle = $indent ? ' style="margin-left: ' . $indent . 'px;"' : '';
1382 $iconImg = '<span ' . $toolTip . ' ' . $additionalStyle . '>'
1383 . $this->iconFactory->getIconForRecord($table, $row, Icon::SIZE_SMALL)->render()
1384 . '</span>';
1385 $theIcon = $this->clickMenuEnabled ? BackendUtility::wrapClickMenuOnIcon($iconImg, $table, $row['uid']) : $iconImg;
1386 // Preparing and getting the data-array
1387 $theData = [];
1388 $localizationMarkerClass = '';
1389 foreach ($this->fieldArray as $fCol) {
1390 if ($fCol == $titleCol) {
1391 $recTitle = BackendUtility::getRecordTitle($table, $row, false, true);
1392 $warning = '';
1393 // If the record is edit-locked by another user, we will show a little warning sign:
1394 $lockInfo = BackendUtility::isRecordLocked($table, $row['uid']);
1395 if ($lockInfo) {
1396 $warning = '<span data-toggle="tooltip" data-placement="right" data-title="' . htmlspecialchars($lockInfo['msg']) . '">'
1397 . $this->iconFactory->getIcon('warning-in-use', Icon::SIZE_SMALL)->render() . '</span>';
1398 }
1399 $theData[$fCol] = $theData['__label'] = $warning . $this->linkWrapItems($table, $row['uid'], $recTitle, $row);
1400 // Render thumbnails, if:
1401 // - a thumbnail column exists
1402 // - there is content in it
1403 // - the thumbnail column is visible for the current type
1404 $type = 0;
1405 if (isset($GLOBALS['TCA'][$table]['ctrl']['type'])) {
1406 $typeColumn = $GLOBALS['TCA'][$table]['ctrl']['type'];
1407 $type = $row[$typeColumn];
1408 }
1409 // If current type doesn't exist, set it to 0 (or to 1 for historical reasons,
1410 // if 0 doesn't exist)
1411 if (!isset($GLOBALS['TCA'][$table]['types'][$type])) {
1412 $type = isset($GLOBALS['TCA'][$table]['types'][0]) ? 0 : 1;
1413 }
1414 $visibleColumns = $GLOBALS['TCA'][$table]['types'][$type]['showitem'];
1415
1416 if ($this->thumbs &&
1417 trim($row[$thumbsCol]) &&
1418 preg_match('/(^|(.*(;|,)?))' . $thumbsCol . '(((;|,).*)|$)/', $visibleColumns) === 1
1419 ) {
1420 $thumbCode = '<br />' . $this->thumbCode($row, $table, $thumbsCol);
1421 $theData[$fCol] .= $thumbCode;
1422 $theData['__label'] .= $thumbCode;
1423 }
1424 if (isset($GLOBALS['TCA'][$table]['ctrl']['languageField'])
1425 && $row[$GLOBALS['TCA'][$table]['ctrl']['languageField']] != 0
1426 && $row[$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']] != 0
1427 ) {
1428 // It's a translated record with a language parent
1429 $localizationMarkerClass = ' localization';
1430 }
1431 } elseif ($fCol === 'pid') {
1432 $theData[$fCol] = $row[$fCol];
1433 } elseif ($fCol === '_PATH_') {
1434 $theData[$fCol] = $this->recPath($row['pid']);
1435 } elseif ($fCol === '_REF_') {
1436 $theData[$fCol] = $this->createReferenceHtml($table, $row['uid']);
1437 } elseif ($fCol === '_CONTROL_') {
1438 $theData[$fCol] = $this->makeControl($table, $row);
1439 } elseif ($fCol === '_CLIPBOARD_') {
1440 $theData[$fCol] = $this->makeClip($table, $row);
1441 } elseif ($fCol === '_LOCALIZATION_') {
1442 list($lC1, $lC2) = $this->makeLocalizationPanel($table, $row);
1443 $theData[$fCol] = $lC1;
1444 $theData[$fCol . 'b'] = '<div class="btn-group">' . $lC2 . '</div>';
1445 } elseif ($fCol === '_LOCALIZATION_b') {
1446 // deliberately empty
1447 } else {
1448 $pageId = $table === 'pages' ? $row['uid'] : $row['pid'];
1449 $tmpProc = BackendUtility::getProcessedValueExtra($table, $fCol, $row[$fCol], 100, $row['uid'], true, $pageId);
1450 $theData[$fCol] = $this->linkUrlMail(htmlspecialchars($tmpProc), $row[$fCol]);
1451 if ($this->csvOutput) {
1452 $row[$fCol] = BackendUtility::getProcessedValueExtra($table, $fCol, $row[$fCol], 0, $row['uid']);
1453 }
1454 }
1455 }
1456 // Reset the ID if it was overwritten
1457 if ((string)$this->searchString !== '') {
1458 $this->id = $id_orig;
1459 }
1460 // Add row to CSV list:
1461 if ($this->csvOutput) {
1462 $this->addToCSV($row);
1463 }
1464 // Add classes to table cells
1465 $this->addElement_tdCssClass[$titleCol] = 'col-title col-responsive' . $localizationMarkerClass;
1466 $this->addElement_tdCssClass['__label'] = $this->addElement_tdCssClass[$titleCol];
1467 $this->addElement_tdCssClass['_CONTROL_'] = 'col-control';
1468 if ($this->getModule()->MOD_SETTINGS['clipBoard']) {
1469 $this->addElement_tdCssClass['_CLIPBOARD_'] = 'col-clipboard';
1470 }
1471 $this->addElement_tdCssClass['_PATH_'] = 'col-path';
1472 $this->addElement_tdCssClass['_LOCALIZATION_'] = 'col-localizationa';
1473 $this->addElement_tdCssClass['_LOCALIZATION_b'] = 'col-localizationb';
1474 // Create element in table cells:
1475 $theData['uid'] = $row['uid'];
1476 if (isset($GLOBALS['TCA'][$table]['ctrl']['languageField'])
1477 && isset($GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField'])
1478 ) {
1479 $theData['_l10nparent_'] = $row[$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']];
1480 }
1481
1482 $tagAttributes = array_map(
1483 function ($attributeValue) {
1484 if (is_array($attributeValue)) {
1485 return implode(' ', $attributeValue);
1486 }
1487 return $attributeValue;
1488 },
1489 $tagAttributes
1490 );
1491
1492 $rowOutput .= $this->addElement(1, $theIcon, $theData, GeneralUtility::implodeAttributes($tagAttributes, true));
1493 // Finally, return table row element:
1494 return $rowOutput;
1495 }
1496
1497 /**
1498 * Gets the number of records referencing the record with the UID $uid in
1499 * the table $tableName.
1500 *
1501 * @param string $tableName
1502 * @param int $uid
1503 * @return int The number of references to record $uid in table
1504 */
1505 protected function getReferenceCount($tableName, $uid)
1506 {
1507 if (!isset($this->referenceCount[$tableName][$uid])) {
1508 $numberOfReferences = GeneralUtility::makeInstance(ConnectionPool::class)
1509 ->getConnectionForTable('sys_refindex')
1510 ->count(
1511 '*',
1512 'sys_refindex',
1513 [
1514 'ref_table' => $tableName,
1515 'ref_uid' => (int)$uid,
1516 'deleted' => 0
1517 ]
1518 );
1519 $this->referenceCount[$tableName][$uid] = $numberOfReferences;
1520 }
1521 return $this->referenceCount[$tableName][$uid];
1522 }
1523
1524 /**
1525 * Rendering the header row for a table
1526 *
1527 * @param string $table Table name
1528 * @param int[] $currentIdList Array of the currently displayed uids of the table
1529 * @throws \UnexpectedValueException
1530 * @return string Header table row
1531 * @access private
1532 * @see getTable()
1533 */
1534 public function renderListHeader($table, $currentIdList)
1535 {
1536 $lang = $this->getLanguageService();
1537 // Init:
1538 $theData = [];
1539 $icon = '';
1540 /** @var \TYPO3\CMS\Backend\Routing\UriBuilder $uriBuilder */
1541 $uriBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Routing\UriBuilder::class);
1542 // Traverse the fields:
1543 foreach ($this->fieldArray as $fCol) {
1544 // Calculate users permissions to edit records in the table:
1545 $permsEdit = $this->calcPerms & ($table === 'pages' ? 2 : 16) && $this->overlayEditLockPermissions($table);
1546 switch ((string)$fCol) {
1547 case '_PATH_':
1548 // Path
1549 $theData[$fCol] = '<i>[' . htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels._PATH_')) . ']</i>';
1550 break;
1551 case '_REF_':
1552 // References
1553 $theData[$fCol] = '<i>[' . htmlspecialchars($lang->sL('LLL:EXT:filelist/Resources/Private/Language/locallang_mod_file_list.xlf:c__REF_')) . ']</i>';
1554 break;
1555 case '_LOCALIZATION_':
1556 // Path
1557 $theData[$fCol] = '<i>[' . htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels._LOCALIZATION_')) . ']</i>';
1558 break;
1559 case '_LOCALIZATION_b':
1560 // Path
1561 $theData[$fCol] = htmlspecialchars($lang->getLL('Localize'));
1562 break;
1563 case '_CLIPBOARD_':
1564 if (!$this->getModule()->MOD_SETTINGS['clipBoard']) {
1565 break;
1566 }
1567 // Clipboard:
1568 $cells = [];
1569 // If there are elements on the clipboard for this table, and the parent page is not locked by editlock
1570 // then display the "paste into" icon:
1571 $elFromTable = $this->clipObj->elFromTable($table);
1572 if (!empty($elFromTable) && $this->overlayEditLockPermissions($table)) {
1573 $href = htmlspecialchars($this->clipObj->pasteUrl($table, $this->id));
1574 $confirmMessage = $this->clipObj->confirmMsgText('pages', $this->pageRow, 'into', $elFromTable);
1575 $cells['pasteAfter'] = '<a class="btn btn-default t3js-modal-trigger"'
1576 . ' href="' . $href . '"'
1577 . ' title="' . htmlspecialchars($lang->getLL('clip_paste')) . '"'
1578 . ' data-title="' . htmlspecialchars($lang->getLL('clip_paste')) . '"'
1579 . ' data-content="' . htmlspecialchars($confirmMessage) . '"'
1580 . ' data-severity="warning">'
1581 . $this->iconFactory->getIcon('actions-document-paste-into', Icon::SIZE_SMALL)->render()
1582 . '</a>';
1583 }
1584 // If the numeric clipboard pads are enabled, display the control icons for that:
1585 if ($this->clipObj->current !== 'normal') {
1586 // The "select" link:
1587 $spriteIcon = $this->iconFactory->getIcon('actions-edit-copy', Icon::SIZE_SMALL)->render();
1588 $cells['copyMarked'] = $this->linkClipboardHeaderIcon($spriteIcon, $table, 'setCB', '', $lang->getLL('clip_selectMarked'));
1589 // The "edit marked" link:
1590 $editUri = (string)$uriBuilder->buildUriFromRoute('record_edit')
1591 . '&edit[' . $table . '][{entityIdentifiers:editList}]=edit'
1592 . '&returnUrl={T3_THIS_LOCATION}';
1593 $cells['edit'] = '<a class="btn btn-default t3js-record-edit-multiple" href="#"'
1594 . ' data-uri="' . htmlspecialchars($editUri) . '"'
1595 . ' title="' . htmlspecialchars($lang->getLL('clip_editMarked')) . '">'
1596 . $this->iconFactory->getIcon('actions-document-open', Icon::SIZE_SMALL)->render() . '</a>';
1597 // The "Delete marked" link:
1598 $cells['delete'] = $this->linkClipboardHeaderIcon(
1599 $this->iconFactory->getIcon('actions-edit-delete', Icon::SIZE_SMALL)->render(),
1600 $table,
1601 'delete',
1602 sprintf($lang->getLL('clip_deleteMarkedWarning'), $lang->sL($GLOBALS['TCA'][$table]['ctrl']['title'])),
1603 $lang->getLL('clip_deleteMarked')
1604 );
1605 // The "Select all" link:
1606 $onClick = htmlspecialchars(('checkOffCB(' . GeneralUtility::quoteJSvalue(implode(',', $this->CBnames)) . ', this); return false;'));
1607 $cells['markAll'] = '<a class="btn btn-default" rel="" href="#" onclick="' . $onClick . '" title="'
1608 . htmlspecialchars($lang->getLL('clip_markRecords')) . '">'
1609 . $this->iconFactory->getIcon('actions-document-select', Icon::SIZE_SMALL)->render() . '</a>';
1610 } else {
1611 $cells['empty'] = '';
1612 }
1613 /*
1614 * hook: renderListHeaderActions: Allows to change the clipboard icons of the Web>List table headers
1615 * usage: Above each listed table in Web>List a header row is shown.
1616 * This hook allows to modify the icons responsible for the clipboard functions
1617 * (shown above the clipboard checkboxes when a clipboard other than "Normal" is selected),
1618 * or other "Action" functions which perform operations on the listed records.
1619 */
1620 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.db_list_extra.inc']['actions'] ?? [] as $className) {
1621 $hookObject = GeneralUtility::makeInstance($className);
1622 if (!$hookObject instanceof RecordListHookInterface) {
1623 throw new \UnexpectedValueException($className . ' must implement interface ' . RecordListHookInterface::class, 1195567850);
1624 }
1625 $cells = $hookObject->renderListHeaderActions($table, $currentIdList, $cells, $this);
1626 }
1627 $theData[$fCol] = '';
1628 if (isset($cells['edit']) && isset($cells['delete'])) {
1629 $theData[$fCol] .= '<div class="btn-group" role="group">' . $cells['edit'] . $cells['delete'] . '</div>';
1630 unset($cells['edit'], $cells['delete']);
1631 }
1632 $theData[$fCol] .= '<div class="btn-group" role="group">' . implode('', $cells) . '</div>';
1633 break;
1634 case '_CONTROL_':
1635 // Control panel:
1636 if ($this->isEditable($table)) {
1637 // If new records can be created on this page, add links:
1638 $permsAdditional = ($table === 'pages' ? 8 : 16);
1639 if ($this->calcPerms & $permsAdditional && $this->showNewRecLink($table)) {
1640 $spriteIcon = $table === 'pages'
1641 ? $this->iconFactory->getIcon('actions-page-new', Icon::SIZE_SMALL)
1642 : $this->iconFactory->getIcon('actions-add', Icon::SIZE_SMALL);
1643 if ($table === 'tt_content' && $this->newWizards) {
1644 // If mod.newContentElementWizard.override is set, use that extension's create new content wizard instead:
1645 $tmpTSc = BackendUtility::getModTSconfig($this->pageinfo['uid'], 'mod');
1646 $newContentElementWizard = isset($tmpTSc['properties']['newContentElementWizard.']['override'])
1647 ? $tmpTSc['properties']['newContentElementWizard.']['override']
1648 : 'new_content_element';
1649 $newContentWizScriptPath = (string)$uriBuilder->buildUriFromRoute($newContentElementWizard, ['id' => $this->id]);
1650
1651 $onClick = 'return jumpExt(' . GeneralUtility::quoteJSvalue($newContentWizScriptPath) . ');';
1652 $icon = '<a class="btn btn-default" href="#" onclick="' . htmlspecialchars($onClick) . '" title="'
1653 . htmlspecialchars($lang->getLL('new')) . '">' . $spriteIcon->render() . '</a>';
1654 } elseif ($table === 'pages' && $this->newWizards) {
1655 $parameters = ['id' => $this->id, 'pagesOnly' => 1, 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')];
1656 $href = (string)$uriBuilder->buildUriFromRoute('db_new', $parameters);
1657 $icon = '<a class="btn btn-default" href="' . htmlspecialchars($href) . '" title="' . htmlspecialchars($lang->getLL('new')) . '">'
1658 . $spriteIcon->render() . '</a>';
1659 } else {
1660 $params = '&edit[' . $table . '][' . $this->id . ']=new';
1661 if ($table === 'pages') {
1662 $params .= '&overrideVals[pages][doktype]=' . (int)$this->pageRow['doktype'];
1663 }
1664 $icon = '<a class="btn btn-default" href="#" onclick="' . htmlspecialchars(BackendUtility::editOnClick($params, '', -1))
1665 . '" title="' . htmlspecialchars($lang->getLL('new')) . '">' . $spriteIcon->render() . '</a>';
1666 }
1667 }
1668 // If the table can be edited, add link for editing ALL SHOWN fields for all listed records:
1669 if ($permsEdit && $this->table && is_array($currentIdList)) {
1670 $entityIdentifiers = 'entityIdentifiers';
1671 if ($this->clipNumPane()) {
1672 $entityIdentifiers .= ':editList';
1673 }
1674 $editUri = (string)$uriBuilder->buildUriFromRoute('record_edit')
1675 . '&edit[' . $table . '][{' . $entityIdentifiers . '}]=edit'
1676 . '&columnsOnly=' . implode(',', $this->fieldArray)
1677 . '&returnUrl={T3_THIS_LOCATION}';
1678 $icon .= '<a class="btn btn-default t3js-record-edit-multiple" href="#"'
1679 . ' data-uri="' . htmlspecialchars($editUri) . '"'
1680 . ' title="' . htmlspecialchars($lang->getLL('editShownColumns')) . '">'
1681 . $this->iconFactory->getIcon('actions-document-open', Icon::SIZE_SMALL)->render() . '</a>';
1682 $icon = '<div class="btn-group" role="group">' . $icon . '</div>';
1683 }
1684 // Add an empty entry, so column count fits again after moving this into $icon
1685 $theData[$fCol] = '&nbsp;';
1686 }
1687 break;
1688 default:
1689 // Regular fields header:
1690 $theData[$fCol] = '';
1691
1692 // Check if $fCol is really a field and get the label and remove the colons
1693 // at the end
1694 $sortLabel = BackendUtility::getItemLabel($table, $fCol);
1695 if ($sortLabel !== null) {
1696 $sortLabel = htmlspecialchars($lang->sL($sortLabel));
1697 $sortLabel = rtrim(trim($sortLabel), ':');
1698 } else {
1699 // No TCA field, only output the $fCol variable with square brackets []
1700 $sortLabel = htmlspecialchars($fCol);
1701 $sortLabel = '<i>[' . rtrim(trim($sortLabel), ':') . ']</i>';
1702 }
1703
1704 if ($this->table && is_array($currentIdList)) {
1705 // If the numeric clipboard pads are selected, show duplicate sorting link:
1706 if ($this->clipNumPane()) {
1707 $theData[$fCol] .= '<a class="btn btn-default" href="' . htmlspecialchars($this->listURL('', '-1') . '&duplicateField=' . $fCol)
1708 . '" title="' . htmlspecialchars($lang->getLL('clip_duplicates')) . '">'
1709 . $this->iconFactory->getIcon('actions-document-duplicates-select', Icon::SIZE_SMALL)->render() . '</a>';
1710 }
1711 // If the table can be edited, add link for editing THIS field for all
1712 // listed records:
1713 if ($this->isEditable($table) && $permsEdit && $GLOBALS['TCA'][$table]['columns'][$fCol]) {
1714 $entityIdentifiers = 'entityIdentifiers';
1715 if ($this->clipNumPane()) {
1716 $entityIdentifiers .= ':editList';
1717 }
1718 $editUri = (string)$uriBuilder->buildUriFromRoute('record_edit')
1719 . '&edit[' . $table . '][{' . $entityIdentifiers . '}]=edit'
1720 . '&columnsOnly=' . $fCol
1721 . '&returnUrl={T3_THIS_LOCATION}';
1722 $iTitle = sprintf($lang->getLL('editThisColumn'), $sortLabel);
1723 $theData[$fCol] .= '<a class="btn btn-default t3js-record-edit-multiple" href="#"'
1724 . ' data-uri="' . htmlspecialchars($editUri) . '"'
1725 . ' title="' . htmlspecialchars($iTitle) . '">'
1726 . $this->iconFactory->getIcon('actions-document-open', Icon::SIZE_SMALL)->render() . '</a>';
1727 }
1728 if (strlen($theData[$fCol]) > 0) {
1729 $theData[$fCol] = '<div class="btn-group" role="group">' . $theData[$fCol] . '</div> ';
1730 }
1731 }
1732 $theData[$fCol] .= $this->addSortLink($sortLabel, $fCol, $table);
1733 }
1734 }
1735 /*
1736 * hook: renderListHeader: Allows to change the contents of columns/cells of the Web>List table headers
1737 * usage: Above each listed table in Web>List a header row is shown.
1738 * Containing the labels of all shown fields and additional icons to create new records for this
1739 * table or perform special clipboard tasks like mark and copy all listed records to clipboard, etc.
1740 */
1741 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.db_list_extra.inc']['actions'] ?? [] as $className) {
1742 $hookObject = GeneralUtility::makeInstance($className);
1743 if (!$hookObject instanceof RecordListHookInterface) {
1744 throw new \UnexpectedValueException($className . ' must implement interface ' . RecordListHookInterface::class, 1195567855);
1745 }
1746 $theData = $hookObject->renderListHeader($table, $currentIdList, $theData, $this);
1747 }
1748
1749 // Create and return header table row:
1750 return '<thead>' . $this->addElement(1, $icon, $theData, '', '', '', 'th') . '</thead>';
1751 }
1752
1753 /**
1754 * Get pointer for first element on the page
1755 *
1756 * @param int $page Page number starting with 1
1757 * @return int Pointer to first element on the page (starting with 0)
1758 */
1759 protected function getPointerForPage($page)
1760 {
1761 return ($page - 1) * $this->iLimit;
1762 }
1763
1764 /**
1765 * Creates a page browser for tables with many records
1766 *
1767 * @param string $renderPart Distinguish between 'top' and 'bottom' part of the navigation (above or below the records)
1768 * @return string Navigation HTML
1769 */
1770 protected function renderListNavigation($renderPart = 'top')
1771 {
1772 $totalPages = ceil($this->totalItems / $this->iLimit);
1773 // Show page selector if not all records fit into one page
1774 if ($totalPages <= 1) {
1775 return '';
1776 }
1777 $content = '';
1778 $listURL = $this->listURL('', $this->table);
1779 // 1 = first page
1780 // 0 = first element
1781 $currentPage = floor($this->firstElementNumber / $this->iLimit) + 1;
1782 // Compile first, previous, next, last and refresh buttons
1783 if ($currentPage > 1) {
1784 $labelFirst = htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_common.xlf:first'));
1785 $labelPrevious = htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_common.xlf:previous'));
1786 $first = '<li><a href="' . $listURL . '&pointer=' . $this->getPointerForPage(1) . '" title="' . $labelFirst . '">'
1787 . $this->iconFactory->getIcon('actions-view-paging-first', Icon::SIZE_SMALL)->render() . '</a></li>';
1788 $previous = '<li><a href="' . $listURL . '&pointer=' . $this->getPointerForPage($currentPage - 1) . '" title="' . $labelPrevious . '">'
1789 . $this->iconFactory->getIcon('actions-view-paging-previous', Icon::SIZE_SMALL)->render() . '</a></li>';
1790 } else {
1791 $first = '<li class="disabled"><span>' . $this->iconFactory->getIcon('actions-view-paging-first', Icon::SIZE_SMALL)->render() . '</span></li>';
1792 $previous = '<li class="disabled"><span>' . $this->iconFactory->getIcon('actions-view-paging-previous', Icon::SIZE_SMALL)->render() . '</span></li>';
1793 }
1794 if ($currentPage < $totalPages) {
1795 $labelNext = htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_common.xlf:next'));
1796 $labelLast = htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_common.xlf:last'));
1797 $next = '<li><a href="' . $listURL . '&pointer=' . $this->getPointerForPage($currentPage + 1) . '" title="' . $labelNext . '">'
1798 . $this->iconFactory->getIcon('actions-view-paging-next', Icon::SIZE_SMALL)->render() . '</a></li>';
1799 $last = '<li><a href="' . $listURL . '&pointer=' . $this->getPointerForPage($totalPages) . '" title="' . $labelLast . '">'
1800 . $this->iconFactory->getIcon('actions-view-paging-last', Icon::SIZE_SMALL)->render() . '</a></li>';
1801 } else {
1802 $next = '<li class="disabled"><span>' . $this->iconFactory->getIcon('actions-view-paging-next', Icon::SIZE_SMALL)->render() . '</span></li>';
1803 $last = '<li class="disabled"><span>' . $this->iconFactory->getIcon('actions-view-paging-last', Icon::SIZE_SMALL)->render() . '</span></li>';
1804 }
1805 $reload = '<li><a href="#" onclick="document.dblistForm.action=' . GeneralUtility::quoteJSvalue($listURL
1806 . '&pointer=') . '+calculatePointer(document.getElementById(' . GeneralUtility::quoteJSvalue('jumpPage-' . $renderPart)
1807 . ').value); document.dblistForm.submit(); return true;" title="'
1808 . htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_common.xlf:reload')) . '">'
1809 . $this->iconFactory->getIcon('actions-refresh', Icon::SIZE_SMALL)->render() . '</a></li>';
1810 if ($renderPart === 'top') {
1811 // Add js to traverse a page select input to a pointer value
1812 $content = '
1813 <script type="text/javascript">
1814 /*<![CDATA[*/
1815 function calculatePointer(page) {
1816 if (page > ' . $totalPages . ') {
1817 page = ' . $totalPages . ';
1818 }
1819 if (page < 1) {
1820 page = 1;
1821 }
1822 return (page - 1) * ' . $this->iLimit . ';
1823 }
1824 /*]]>*/
1825 </script>
1826 ';
1827 }
1828 $pageNumberInput = '
1829 <input type="number" min="1" max="' . $totalPages . '" value="' . $currentPage . '" size="3" class="form-control input-sm paginator-input" id="jumpPage-' . $renderPart . '" name="jumpPage-'
1830 . $renderPart . '" onkeyup="if (event.keyCode == 13) { document.dblistForm.action=' . GeneralUtility::quoteJSvalue($listURL
1831 . '&pointer=') . '+calculatePointer(this.value); document.dblistForm.submit(); } return true;" />
1832 ';
1833 $pageIndicatorText = sprintf(
1834 $this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_mod_web_list.xlf:pageIndicator'),
1835 $pageNumberInput,
1836 $totalPages
1837 );
1838 $pageIndicator = '<li><span>' . $pageIndicatorText . '</span></li>';
1839 if ($this->totalItems > $this->firstElementNumber + $this->iLimit) {
1840 $lastElementNumber = $this->firstElementNumber + $this->iLimit;
1841 } else {
1842 $lastElementNumber = $this->totalItems;
1843 }
1844 $rangeIndicator = '<li><span>' . sprintf($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_mod_web_list.xlf:rangeIndicator'), ($this->firstElementNumber + 1), $lastElementNumber) . '</span></li>';
1845
1846 $titleColumn = $this->fieldArray[0];
1847 $data = [
1848 $titleColumn => $content . '
1849 <nav class="pagination-wrap">
1850 <ul class="pagination pagination-block">
1851 ' . $first . '
1852 ' . $previous . '
1853 ' . $rangeIndicator . '
1854 ' . $pageIndicator . '
1855 ' . $next . '
1856 ' . $last . '
1857 ' . $reload . '
1858 </ul>
1859 </nav>
1860 '
1861 ];
1862 return $this->addElement(1, '', $data);
1863 }
1864
1865 /*********************************
1866 *
1867 * Rendering of various elements
1868 *
1869 *********************************/
1870
1871 /**
1872 * Creates the control panel for a single record in the listing.
1873 *
1874 * @param string $table The table
1875 * @param mixed[] $row The record for which to make the control panel.
1876 * @throws \UnexpectedValueException
1877 * @return string HTML table with the control panel (unless disabled)
1878 */
1879 public function makeControl($table, $row)
1880 {
1881 $module = $this->getModule();
1882 $rowUid = $row['uid'];
1883 if (ExtensionManagementUtility::isLoaded('workspaces') && isset($row['_ORIG_uid'])) {
1884 $rowUid = $row['_ORIG_uid'];
1885 }
1886 $cells = [
1887 'primary' => [],
1888 'secondary' => []
1889 ];
1890 // Enables to hide the move elements for localized records - doesn't make much sense to perform these options for them
1891 // For page translations these icons should never be shown
1892 $isL10nOverlay = $table === 'pages' && $row[$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']] != 0;
1893 // If the listed table is 'pages' we have to request the permission settings for each page:
1894 $localCalcPerms = 0;
1895 if ($table === 'pages') {
1896 $localCalcPerms = $this->getBackendUserAuthentication()->calcPerms(BackendUtility::getRecord('pages', $row['uid']));
1897 }
1898 $permsEdit = $table === 'pages'
1899 && $this->getBackendUserAuthentication()->checkLanguageAccess(0)
1900 && $localCalcPerms & Permission::PAGE_EDIT
1901 || $table !== 'pages'
1902 && $this->calcPerms & Permission::CONTENT_EDIT
1903 && $this->getBackendUserAuthentication()->recordEditAccessInternals($table, $row);
1904 $permsEdit = $this->overlayEditLockPermissions($table, $row, $permsEdit);
1905 // "Show" link (only pages and tt_content elements)
1906 /** @var \TYPO3\CMS\Backend\Routing\UriBuilder $uriBuilder */
1907 $uriBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Routing\UriBuilder::class);
1908
1909 if ($table === 'pages' || $table === 'tt_content') {
1910 $onClick = $this->getOnClickForRow($table, $row);
1911 $viewAction = '<a class="btn btn-default" href="#" onclick="'
1912 . htmlspecialchars(
1913 $onClick
1914 ) . '" title="' . htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.showPage')) . '">';
1915 if ($table === 'pages') {
1916 $viewAction .= $this->iconFactory->getIcon('actions-view-page', Icon::SIZE_SMALL)->render();
1917 } else {
1918 $viewAction .= $this->iconFactory->getIcon('actions-view', Icon::SIZE_SMALL)->render();
1919 }
1920 $viewAction .= '</a>';
1921 $this->addActionToCellGroup($cells, $viewAction, 'view');
1922 }
1923 // "Edit" link: ( Only if permissions to edit the page-record of the content of the parent page ($this->id)
1924 if ($permsEdit) {
1925 $params = '&edit[' . $table . '][' . $row['uid'] . ']=edit';
1926 $iconIdentifier = 'actions-open';
1927 if ($table === 'pages') {
1928 $iconIdentifier = 'actions-page-open';
1929 }
1930 $overlayIdentifier = !$this->isEditable($table) ? 'overlay-readonly' : null;
1931 $editAction = '<a class="btn btn-default" href="#" onclick="' . htmlspecialchars(BackendUtility::editOnClick($params, '', -1))
1932 . '" title="' . htmlspecialchars($this->getLanguageService()->getLL('edit')) . '">' . $this->iconFactory->getIcon($iconIdentifier, Icon::SIZE_SMALL, $overlayIdentifier)->render() . '</a>';
1933 } else {
1934 $editAction = $this->spaceIcon;
1935 }
1936 $this->addActionToCellGroup($cells, $editAction, 'edit');
1937 // "Info": (All records)
1938 $onClick = 'top.launchView(' . GeneralUtility::quoteJSvalue($table) . ', ' . (int)$row['uid'] . '); return false;';
1939 $viewBigAction = '<a class="btn btn-default" href="#" onclick="' . htmlspecialchars($onClick) . '" title="' . htmlspecialchars($this->getLanguageService()->getLL('showInfo')) . '">'
1940 . $this->iconFactory->getIcon('actions-document-info', Icon::SIZE_SMALL)->render() . '</a>';
1941 $this->addActionToCellGroup($cells, $viewBigAction, 'viewBig');
1942 // "Move" wizard link for pages/tt_content elements:
1943 if ($permsEdit && ($table === 'tt_content' || $table === 'pages')) {
1944 if ($isL10nOverlay) {
1945 $moveAction = $this->spaceIcon;
1946 } else {
1947 $onClick = 'return jumpExt(' . GeneralUtility::quoteJSvalue((string)$uriBuilder->buildUriFromRoute('move_element') . '&table=' . $table . '&uid=' . $row['uid']) . ');';
1948 $linkTitleLL = htmlspecialchars($this->getLanguageService()->getLL('move_' . ($table === 'tt_content' ? 'record' : 'page')));
1949 $icon = ($table === 'pages' ? $this->iconFactory->getIcon('actions-page-move', Icon::SIZE_SMALL) : $this->iconFactory->getIcon('actions-document-move', Icon::SIZE_SMALL));
1950 $moveAction = '<a class="btn btn-default" href="#" onclick="' . htmlspecialchars($onClick) . '" title="' . $linkTitleLL . '">' . $icon->render() . '</a>';
1951 }
1952 $this->addActionToCellGroup($cells, $moveAction, 'move');
1953 }
1954 // If the table is NOT a read-only table, then show these links:
1955 if ($this->isEditable($table)) {
1956 // "Revert" link (history/undo)
1957 $moduleUrl = (string)$uriBuilder->buildUriFromRoute('record_history', ['element' => $table . ':' . $row['uid']]);
1958 $onClick = 'return jumpExt(' . GeneralUtility::quoteJSvalue($moduleUrl) . ',\'#latest\');';
1959 $historyAction = '<a class="btn btn-default" href="#" onclick="' . htmlspecialchars($onClick) . '" title="'
1960 . htmlspecialchars($this->getLanguageService()->getLL('history')) . '">'
1961 . $this->iconFactory->getIcon('actions-document-history-open', Icon::SIZE_SMALL)->render() . '</a>';
1962 $this->addActionToCellGroup($cells, $historyAction, 'history');
1963 // "Edit Perms" link:
1964 if ($table === 'pages' && $this->getBackendUserAuthentication()->check('modules', 'system_BeuserTxPermission') && ExtensionManagementUtility::isLoaded('beuser')) {
1965 if ($isL10nOverlay) {
1966 $permsAction = $this->spaceIcon;
1967 } else {
1968 $href = (string)$uriBuilder->buildUriFromRoute('system_BeuserTxPermission') . '&id=' . $row['uid'] . '&tx_beuser_system_beusertxpermission[action]=edit' . $this->makeReturnUrl();
1969 $permsAction = '<a class="btn btn-default" href="' . htmlspecialchars($href) . '" title="'
1970 . htmlspecialchars($this->getLanguageService()->getLL('permissions')) . '">'
1971 . $this->iconFactory->getIcon('actions-lock', Icon::SIZE_SMALL)->render() . '</a>';
1972 }
1973 $this->addActionToCellGroup($cells, $permsAction, 'perms');
1974 }
1975 // "New record after" link (ONLY if the records in the table are sorted by a "sortby"-row
1976 // or if default values can depend on previous record):
1977 if (($GLOBALS['TCA'][$table]['ctrl']['sortby'] || $GLOBALS['TCA'][$table]['ctrl']['useColumnsForDefaultValues']) && $permsEdit) {
1978 if ($table !== 'pages' && $this->calcPerms & Permission::CONTENT_EDIT || $table === 'pages' && $this->calcPerms & Permission::PAGE_NEW) {
1979 if ($table === 'pages' && $isL10nOverlay) {
1980 $this->addActionToCellGroup($cells, $this->spaceIcon, 'new');
1981 } elseif ($this->showNewRecLink($table)) {
1982 $params = '&edit[' . $table . '][' . -($row['_MOVE_PLH'] ? $row['_MOVE_PLH_uid'] : $row['uid']) . ']=new';
1983 $icon = ($table === 'pages' ? $this->iconFactory->getIcon('actions-page-new', Icon::SIZE_SMALL) : $this->iconFactory->getIcon('actions-add', Icon::SIZE_SMALL));
1984 $titleLabel = 'new';
1985 if ($GLOBALS['TCA'][$table]['ctrl']['sortby']) {
1986 $titleLabel .= ($table === 'pages' ? 'Page' : 'Record');
1987 }
1988 $newAction = '<a class="btn btn-default" href="#" onclick="' . htmlspecialchars(BackendUtility::editOnClick($params, '', -1))
1989 . '" title="' . htmlspecialchars($this->getLanguageService()->getLL($titleLabel)) . '">'
1990 . $icon->render() . '</a>';
1991 $this->addActionToCellGroup($cells, $newAction, 'new');
1992 }
1993 }
1994 }
1995 // "Up/Down" links
1996 if ($permsEdit && $GLOBALS['TCA'][$table]['ctrl']['sortby'] && !$this->sortField && !$this->searchLevels) {
1997 if (!$isL10nOverlay && isset($this->currentTable['prev'][$row['uid']])) {
1998 // Up
1999 $params = '&cmd[' . $table . '][' . $row['uid'] . '][move]=' . $this->currentTable['prev'][$row['uid']];
2000 $moveUpAction = '<a class="btn btn-default" href="#" onclick="'
2001 . htmlspecialchars('return jumpToUrl(' . BackendUtility::getLinkToDataHandlerAction($params, -1) . ');')
2002 . '" title="' . htmlspecialchars($this->getLanguageService()->getLL('moveUp')) . '">'
2003 . $this->iconFactory->getIcon('actions-move-up', Icon::SIZE_SMALL)->render() . '</a>';
2004 } else {
2005 $moveUpAction = $this->spaceIcon;
2006 }
2007 $this->addActionToCellGroup($cells, $moveUpAction, 'moveUp');
2008
2009 if (!$isL10nOverlay && $this->currentTable['next'][$row['uid']]) {
2010 // Down
2011 $params = '&cmd[' . $table . '][' . $row['uid'] . '][move]=' . $this->currentTable['next'][$row['uid']];
2012 $moveDownAction = '<a class="btn btn-default" href="#" onclick="'
2013 . htmlspecialchars('return jumpToUrl(' . BackendUtility::getLinkToDataHandlerAction($params, -1) . ');')
2014 . '" title="' . htmlspecialchars($this->getLanguageService()->getLL('moveDown')) . '">'
2015 . $this->iconFactory->getIcon('actions-move-down', Icon::SIZE_SMALL)->render() . '</a>';
2016 } else {
2017 $moveDownAction = $this->spaceIcon;
2018 }
2019 $this->addActionToCellGroup($cells, $moveDownAction, 'moveDown');
2020 }
2021 // "Hide/Unhide" links:
2022 $hiddenField = $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['disabled'];
2023
2024 if (
2025 !empty($GLOBALS['TCA'][$table]['columns'][$hiddenField])
2026 && (empty($GLOBALS['TCA'][$table]['columns'][$hiddenField]['exclude'])
2027 || $this->getBackendUserAuthentication()->check('non_exclude_fields', $table . ':' . $hiddenField))
2028 ) {
2029 if (!$permsEdit || $this->isRecordCurrentBackendUser($table, $row)) {
2030 $hideAction = $this->spaceIcon;
2031 } else {
2032 $hideTitle = htmlspecialchars($this->getLanguageService()->getLL('hide' . ($table === 'pages' ? 'Page' : '')));
2033 $unhideTitle = htmlspecialchars($this->getLanguageService()->getLL('unHide' . ($table === 'pages' ? 'Page' : '')));
2034 if ($row[$hiddenField]) {
2035 $params = 'data[' . $table . '][' . $rowUid . '][' . $hiddenField . ']=0';
2036 $hideAction = '<a class="btn btn-default t3js-record-hide" data-state="hidden" href="#"'
2037 . ' data-params="' . htmlspecialchars($params) . '"'
2038 . ' title="' . $unhideTitle . '"'
2039 . ' data-toggle-title="' . $hideTitle . '">'
2040 . $this->iconFactory->getIcon('actions-edit-unhide', Icon::SIZE_SMALL)->render() . '</a>';
2041 } else {
2042 $params = 'data[' . $table . '][' . $rowUid . '][' . $hiddenField . ']=1';
2043 $hideAction = '<a class="btn btn-default t3js-record-hide" data-state="visible" href="#"'
2044 . ' data-params="' . htmlspecialchars($params) . '"'
2045 . ' title="' . $hideTitle . '"'
2046 . ' data-toggle-title="' . $unhideTitle . '">'
2047 . $this->iconFactory->getIcon('actions-edit-hide', Icon::SIZE_SMALL)->render() . '</a>';
2048 }
2049 }
2050 $this->addActionToCellGroup($cells, $hideAction, 'hide');
2051 }
2052 // "Delete" link:
2053 $disableDeleteTS = $this->getBackendUserAuthentication()->getTSConfig('options.disableDelete');
2054 $disableDelete = (bool) trim(isset($disableDeleteTS['properties'][$table]) ? $disableDeleteTS['properties'][$table] : $disableDeleteTS['value']);
2055 if ($permsEdit && !$disableDelete && ($table === 'pages' && $localCalcPerms & Permission::PAGE_DELETE || $table !== 'pages' && $this->calcPerms & Permission::CONTENT_EDIT)) {
2056 // Check if the record version is in "deleted" state, because that will switch the action to "restore"
2057 if ($this->getBackendUserAuthentication()->workspace > 0 && isset($row['t3ver_state']) && (int)$row['t3ver_state'] === 2) {
2058 $actionName = 'restore';
2059 $refCountMsg = '';
2060 } else {
2061 $actionName = 'delete';
2062 $refCountMsg = BackendUtility::referenceCount(
2063 $table,
2064 $row['uid'],
2065 ' ' . $this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.referencesToRecord'),
2066 $this->getReferenceCount($table, $row['uid'])
2067 ) . BackendUtility::translationCount(
2068 $table,
2069 $row['uid'],
2070 ' ' . $this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.translationsOfRecord')
2071 );
2072 }
2073
2074 if ($this->isRecordCurrentBackendUser($table, $row)) {
2075 $deleteAction = $this->spaceIcon;
2076 } else {
2077 $title = BackendUtility::getRecordTitle($table, $row);
2078 $warningText = $this->getLanguageService()->getLL($actionName . 'Warning') . ' "' . $title . '" ' . '[' . $table . ':' . $row['uid'] . ']' . $refCountMsg;
2079
2080 $params = 'cmd[' . $table . '][' . $row['uid'] . '][delete]=1';
2081 $icon = $this->iconFactory->getIcon('actions-edit-' . $actionName, Icon::SIZE_SMALL)->render();
2082 $linkTitle = htmlspecialchars($this->getLanguageService()->getLL($actionName));
2083 $l10nParentField = $GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField'] ?? '';
2084 $deleteAction = '<a class="btn btn-default t3js-record-delete" href="#" '
2085 . ' data-l10parent="' . ($l10nParentField ? htmlspecialchars($row[$l10nParentField]) : '') . '"'
2086 . ' data-params="' . htmlspecialchars($params) . '" data-title="' . htmlspecialchars($title) . '"'
2087 . ' data-message="' . htmlspecialchars($warningText) . '" title="' . $linkTitle . '"'
2088 . '>' . $icon . '</a>';
2089 }
2090 } else {
2091 $deleteAction = $this->spaceIcon;
2092 }
2093 $this->addActionToCellGroup($cells, $deleteAction, 'delete');
2094 // "Levels" links: Moving pages into new levels...
2095 if ($permsEdit && $table === 'pages' && !$this->searchLevels) {
2096 // Up (Paste as the page right after the current parent page)
2097 if ($this->calcPerms & Permission::PAGE_NEW) {
2098 $params = '&cmd[' . $table . '][' . $row['uid'] . '][move]=' . -$this->id;
2099 $moveLeftAction = '<a class="btn btn-default" href="#" onclick="'
2100 . htmlspecialchars('return jumpToUrl(' . BackendUtility::getLinkToDataHandlerAction($params, -1) . ');')
2101 . '" title="' . htmlspecialchars($this->getLanguageService()->getLL('prevLevel')) . '">'
2102 . $this->iconFactory->getIcon('actions-move-left', Icon::SIZE_SMALL)->render() . '</a>';
2103 $this->addActionToCellGroup($cells, $isL10nOverlay ? $this->spaceIcon : $moveLeftAction, 'moveLeft');
2104 }
2105 // Down (Paste as subpage to the page right above)
2106 if (!$isL10nOverlay && $this->currentTable['prevUid'][$row['uid']]) {
2107 $localCalcPerms = $this->getBackendUserAuthentication()->calcPerms(BackendUtility::getRecord('pages', $this->currentTable['prevUid'][$row['uid']]));
2108 if ($localCalcPerms & Permission::PAGE_NEW) {
2109 $params = '&cmd[' . $table . '][' . $row['uid'] . '][move]=' . $this->currentTable['prevUid'][$row['uid']];
2110 $moveRightAction = '<a class="btn btn-default" href="#" onclick="'
2111 . htmlspecialchars('return jumpToUrl(' . BackendUtility::getLinkToDataHandlerAction($params, -1) . ');')
2112 . '" title="' . htmlspecialchars($this->getLanguageService()->getLL('nextLevel')) . '">'
2113 . $this->iconFactory->getIcon('actions-move-right', Icon::SIZE_SMALL)->render() . '</a>';
2114 } else {
2115 $moveRightAction = $this->spaceIcon;
2116 }
2117 } else {
2118 $moveRightAction = $this->spaceIcon;
2119 }
2120 $this->addActionToCellGroup($cells, $moveRightAction, 'moveRight');
2121 }
2122 }
2123 /*
2124 * hook: recStatInfoHooks: Allows to insert HTML before record icons on various places
2125 */
2126 $hooks = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['recStatInfoHooks'] ?? [];
2127 if (!empty($hooks)) {
2128 $stat = '';
2129 $_params = [$table, $row['uid']];
2130 foreach ($hooks as $_funcRef) {
2131 $stat .= GeneralUtility::callUserFunction($_funcRef, $_params, $this);
2132 }
2133 $this->addActionToCellGroup($cells, $stat, 'stat');
2134 }
2135 /*
2136 * hook: makeControl: Allows to change control icons of records in list-module
2137 * usage: This hook method gets passed the current $cells array as third parameter.
2138 * This array contains values for the icons/actions generated for each record in Web>List.
2139 * Each array entry is accessible by an index-key.
2140 * The order of the icons is depending on the order of those array entries.
2141 */
2142 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.db_list_extra.inc']['actions'] ?? false)) {
2143 // for compatibility reason, we move all icons to the rootlevel
2144 // before calling the hooks
2145 foreach ($cells as $section => $actions) {
2146 foreach ($actions as $actionKey => $action) {
2147 $cells[$actionKey] = $action;
2148 }
2149 }
2150 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.db_list_extra.inc']['actions'] as $className) {
2151 $hookObject = GeneralUtility::makeInstance($className);
2152 if (!$hookObject instanceof RecordListHookInterface) {
2153 throw new \UnexpectedValueException($className . ' must implement interface ' . RecordListHookInterface::class, 1195567840);
2154 }
2155 $cells = $hookObject->makeControl($table, $row, $cells, $this);
2156 }
2157 // now sort icons again into primary and secondary sections
2158 // after all hooks are processed
2159 $hookCells = $cells;
2160 foreach ($hookCells as $key => $value) {
2161 if ($key === 'primary' || $key === 'secondary') {
2162 continue;
2163 }
2164 $this->addActionToCellGroup($cells, $value, $key);
2165 }
2166 }
2167 $output = '<!-- CONTROL PANEL: ' . $table . ':' . $row['uid'] . ' -->';
2168 foreach ($cells as $classification => $actions) {
2169 $visibilityClass = ($classification !== 'primary' && !$module->MOD_SETTINGS['bigControlPanel'] ? 'collapsed' : 'expanded');
2170 if ($visibilityClass === 'collapsed') {
2171 $cellOutput = '';
2172 foreach ($actions as $action) {
2173 $cellOutput .= $action;
2174 }
2175 $output .= ' <div class="btn-group">' .
2176 '<span id="actions_' . $table . '_' . $row['uid'] . '" class="btn-group collapse collapse-horizontal width">' . $cellOutput . '</span>' .
2177 '<a href="#actions_' . $table . '_' . $row['uid'] . '" class="btn btn-default collapsed" data-toggle="collapse" aria-expanded="false"><span class="t3-icon fa fa-ellipsis-h"></span></a>' .
2178 '</div>';
2179 } else {
2180 $output .= ' <div class="btn-group" role="group">' . implode('', $actions) . '</div>';
2181 }
2182 }
2183 return $output;
2184 }
2185
2186 /**
2187 * Creates the clipboard panel for a single record in the listing.
2188 *
2189 * @param string $table The table
2190 * @param mixed[] $row The record for which to make the clipboard panel.
2191 * @throws \UnexpectedValueException
2192 * @return string HTML table with the clipboard panel (unless disabled)
2193 */
2194 public function makeClip($table, $row)
2195 {
2196 // Return blank, if disabled:
2197 if (!$this->getModule()->MOD_SETTINGS['clipBoard']) {
2198 return '';
2199 }
2200 $cells = [];
2201 $cells['pasteAfter'] = ($cells['pasteInto'] = $this->spaceIcon);
2202 // Enables to hide the copy, cut and paste icons for localized records - doesn't make much sense to perform these options for them
2203 // For page translations these icons should never be shown
2204 $isL10nOverlay = $table === 'pages' && $row[$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']] != 0;
2205 // Return blank, if disabled:
2206 // Whether a numeric clipboard pad is active or the normal pad we will see different content of the panel:
2207 // For the "Normal" pad:
2208 if ($this->clipObj->current === 'normal') {
2209 // Show copy/cut icons:
2210 $isSel = (string)$this->clipObj->isSelected($table, $row['uid']);
2211 if ($isL10nOverlay || !$this->overlayEditLockPermissions($table, $row)) {
2212 $cells['copy'] = $this->spaceIcon;
2213 $cells['cut'] = $this->spaceIcon;
2214 } else {
2215 $copyIcon = $this->iconFactory->getIcon('actions-edit-copy', Icon::SIZE_SMALL);
2216 $cutIcon = $this->iconFactory->getIcon('actions-edit-cut', Icon::SIZE_SMALL);
2217
2218 if ($isSel === 'copy') {
2219 $copyIcon = $this->iconFactory->getIcon('actions-edit-copy-release', Icon::SIZE_SMALL);
2220 } elseif ($isSel === 'cut') {
2221 $cutIcon = $this->iconFactory->getIcon('actions-edit-cut-release', Icon::SIZE_SMALL);
2222 }
2223
2224 $cells['copy'] = '<a class="btn btn-default" href="#" onclick="'
2225 . htmlspecialchars('return jumpSelf(' . GeneralUtility::quoteJSvalue($this->clipObj->selUrlDB($table, $row['uid'], 1, ($isSel === 'copy'), ['returnUrl' => ''])) . ');')
2226 . '" title="' . htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:cm.copy')) . '">'
2227 . $copyIcon->render() . '</a>';
2228
2229 // Check permission to cut page or content
2230 if ($table === 'pages') {
2231 $localCalcPerms = $this->getBackendUserAuthentication()->calcPerms(BackendUtility::getRecord('pages', $row['uid']));
2232 $permsEdit = $localCalcPerms & Permission::PAGE_EDIT;
2233 } else {
2234 $permsEdit = $this->calcPerms & Permission::CONTENT_EDIT;
2235 }
2236 $permsEdit = $this->overlayEditLockPermissions($table, $row, $permsEdit);
2237
2238 // If the listed table is 'pages' we have to request the permission settings for each page:
2239 if ($table === 'pages') {
2240 if ($permsEdit) {
2241 $cells['cut'] = '<a class="btn btn-default" href="#" onclick="'
2242 . htmlspecialchars('return jumpSelf(' . GeneralUtility::quoteJSvalue($this->clipObj->selUrlDB($table, $row['uid'], 0, ($isSel === 'cut'), ['returnUrl' => ''])) . ');')
2243 . '" title="' . htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:cm.cut')) . '">'
2244 . $cutIcon->render() . '</a>';
2245 } else {
2246 $cells['cut'] = $this->spaceIcon;
2247 }
2248 } else {
2249 if ($this->calcPerms & Permission::CONTENT_EDIT) {
2250 $cells['cut'] = '<a class="btn btn-default" href="#" onclick="'
2251 . htmlspecialchars('return jumpSelf(' . GeneralUtility::quoteJSvalue($this->clipObj->selUrlDB($table, $row['uid'], 0, ($isSel === 'cut'), ['returnUrl' => ''])) . ');')
2252 . '" title="' . htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:cm.cut')) . '">'
2253 . $cutIcon->render() . '</a>';
2254 } else {
2255 $cells['cut'] = $this->spaceIcon;
2256 }
2257 }
2258 }
2259 } else {
2260 // For the numeric clipboard pads (showing checkboxes where one can select elements on/off)
2261 // Setting name of the element in ->CBnames array:
2262 $n = $table . '|' . $row['uid'];
2263 $this->CBnames[] = $n;
2264 // Check if the current element is selected and if so, prepare to set the checkbox as selected:
2265 $checked = $this->clipObj->isSelected($table, $row['uid']) ? 'checked="checked" ' : '';
2266 // If the "duplicateField" value is set then select all elements which are duplicates...
2267 if ($this->duplicateField && isset($row[$this->duplicateField])) {
2268 $checked = '';
2269 if (in_array($row[$this->duplicateField], $this->duplicateStack)) {
2270 $checked = 'checked="checked" ';
2271 }
2272 $this->duplicateStack[] = $row[$this->duplicateField];
2273 }
2274 // Adding the checkbox to the panel:
2275 $cells['select'] = $isL10nOverlay
2276 ? $this->spaceIcon
2277 : '<input type="hidden" name="CBH[' . $n . ']" value="0" /><label class="btn btn-default btn-checkbox"><input type="checkbox"'
2278 . ' name="CBC[' . $n . ']" value="1" ' . $checked . '/><span class="t3-icon fa"></span></label>';
2279 }
2280 // Now, looking for selected elements from the current table:
2281 $elFromTable = $this->clipObj->elFromTable($table);
2282 if (!empty($elFromTable) && $GLOBALS['TCA'][$table]['ctrl']['sortby']) {
2283 // IF elements are found, they can be individually ordered and are not locked by editlock, then add a "paste after" icon:
2284 $cells['pasteAfter'] = $isL10nOverlay || !$this->overlayEditLockPermissions($table, $row)
2285 ? $this->spaceIcon
2286 : '<a class="btn btn-default t3js-modal-trigger"'
2287 . ' href="' . htmlspecialchars($this->clipObj->pasteUrl($table, -$row['uid'])) . '"'
2288 . ' title="' . htmlspecialchars($this->getLanguageService()->getLL('clip_pasteAfter')) . '"'
2289 . ' data-title="' . htmlspecialchars($this->getLanguageService()->getLL('clip_pasteAfter')) . '"'
2290 . ' data-content="' . htmlspecialchars($this->clipObj->confirmMsgText($table, $row, 'after', $elFromTable)) . '"'
2291 . ' data-severity="warning">'
2292 . $this->iconFactory->getIcon('actions-document-paste-after', Icon::SIZE_SMALL)->render() . '</a>';
2293 }
2294 // Now, looking for elements in general:
2295 $elFromTable = $this->clipObj->elFromTable('');
2296 if ($table === 'pages' && !$isL10nOverlay && !empty($elFromTable)) {
2297 $cells['pasteInto'] = '<a class="btn btn-default t3js-modal-trigger"'
2298 . ' href="' . htmlspecialchars($this->clipObj->pasteUrl('', $row['uid'])) . '"'
2299 . ' title="' . htmlspecialchars($this->getLanguageService()->getLL('clip_pasteInto')) . '"'
2300 . ' data-title="' . htmlspecialchars($this->getLanguageService()->getLL('clip_pasteInto')) . '"'
2301 . ' data-content="' . htmlspecialchars($this->clipObj->confirmMsgText($table, $row, 'into', $elFromTable)) . '"'
2302 . ' data-severity="warning">'
2303 . $this->iconFactory->getIcon('actions-document-paste-into', Icon::SIZE_SMALL)->render() . '</a>';
2304 }
2305 /*
2306 * hook: makeClip: Allows to change clip-icons of records in list-module
2307 * usage: This hook method gets passed the current $cells array as third parameter.
2308 * This array contains values for the clipboard icons generated for each record in Web>List.
2309 * Each array entry is accessible by an index-key.
2310 * The order of the icons is depending on the order of those array entries.
2311 */
2312 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.db_list_extra.inc']['actions'] ?? [] as $className) {
2313 $hookObject = GeneralUtility::makeInstance($className);
2314 if (!$hookObject instanceof RecordListHookInterface) {
2315 throw new \UnexpectedValueException($className . ' must implement interface ' . RecordListHookInterface::class, 1195567845);
2316 }
2317 $cells = $hookObject->makeClip($table, $row, $cells, $this);
2318 }
2319 return '<div class="btn-group" role="group">' . implode('', $cells) . '</div>';
2320 }
2321
2322 /**
2323 * Creates the HTML for a reference count for the record with the UID $uid
2324 * in the table $tableName.
2325 *
2326 * @param string $tableName
2327 * @param int $uid
2328 * @return string HTML of reference a link, will be empty if there are no
2329 */
2330 protected function createReferenceHtml($tableName, $uid)
2331 {
2332 $referenceCount = GeneralUtility::makeInstance(ConnectionPool::class)
2333 ->getConnectionForTable('sys_refindex')
2334 ->count(
2335 '*',
2336 'sys_refindex',
2337 [
2338 'ref_table' => $tableName,
2339 'ref_uid' => (int)$uid,
2340 'deleted' => 0,
2341 ]
2342 );
2343
2344 return $this->generateReferenceToolTip(
2345 $referenceCount,
2346 GeneralUtility::quoteJSvalue($tableName) . ', ' . GeneralUtility::quoteJSvalue($uid)
2347 );
2348 }
2349
2350 /**
2351 * Creates the localization panel
2352 *
2353 * @param string $table The table
2354 * @param mixed[] $row The record for which to make the localization panel.
2355 * @return string[] Array with key 0/1 with content for column 1 and 2
2356 */
2357 public function makeLocalizationPanel($table, $row)
2358 {
2359 $out = [
2360 0 => '',
2361 1 => ''
2362 ];
2363 // Reset translations
2364 $this->translations = [];
2365
2366 // Language title and icon:
2367 $out[0] = $this->languageFlag($row[$GLOBALS['TCA'][$table]['ctrl']['languageField']]);
2368 // Guard clause so we can quickly return if a record is localized to "all languages"
2369 // It should only be possible to localize a record off default (uid 0)
2370 // Reasoning: The Parent is for ALL languages... why overlay with a localization?
2371 if ((int)$row[$GLOBALS['TCA'][$table]['ctrl']['languageField']] === -1) {
2372 return $out;
2373 }
2374
2375 $translations = $this->translateTools->translationInfo($table, $row['uid'], 0, $row, $this->selFieldList);
2376 if (is_array($translations)) {
2377 $this->translations = $translations['translations'];
2378 // Traverse page translations and add icon for each language that does NOT yet exist:
2379 $lNew = '';
2380 foreach ($this->pageOverlays as $lUid_OnPage => $lsysRec) {
2381 if ($this->isEditable($table) && !isset($translations['translations'][$lUid_OnPage]) && $this->getBackendUserAuthentication()->checkLanguageAccess($lUid_OnPage)) {
2382 $url = $this->listURL();
2383 $href = BackendUtility::getLinkToDataHandlerAction(
2384 '&cmd[' . $table . '][' . $row['uid'] . '][localize]=' . $lUid_OnPage,
2385 $url . '&justLocalized=' . rawurlencode($table . ':' . $row['uid'] . ':' . $lUid_OnPage)
2386 );
2387 $language = BackendUtility::getRecord('sys_language', $lUid_OnPage, 'title');
2388 if ($this->languageIconTitles[$lUid_OnPage]['flagIcon']) {
2389 $lC = $this->iconFactory->getIcon($this->languageIconTitles[$lUid_OnPage]['flagIcon'], Icon::SIZE_SMALL)->render();
2390 } else {
2391 $lC = $this->languageIconTitles[$lUid_OnPage]['title'];
2392 }
2393 $lC = '<a href="' . htmlspecialchars($href) . '" title="'
2394 . htmlspecialchars($language['title']) . '" class="btn btn-default">' . $lC . '</a> ';
2395 $lNew .= $lC;
2396 }
2397 }
2398 if ($lNew) {
2399 $out[1] .= $lNew;
2400 }
2401 } elseif ($row['l18n_parent']) {
2402 $out[0] = '&nbsp;&nbsp;&nbsp;&nbsp;' . $out[0];
2403 }
2404 return $out;
2405 }
2406
2407 /**
2408 * Creates a checkbox list for selecting fields to display from a table:
2409 *
2410 * @param string $table Table name
2411 * @param bool $formFields If TRUE, form-fields will be wrapped around the table.
2412 * @return string HTML table with the selector check box (name: displayFields['.$table.'][])
2413 */
2414 public function fieldSelectBox($table, $formFields = true)
2415 {
2416 $lang = $this->getLanguageService();
2417 // Init:
2418 $formElements = ['', ''];
2419 if ($formFields) {
2420 $formElements = ['<form action="' . htmlspecialchars($this->listURL()) . '" method="post" name="fieldSelectBox">', '</form>'];
2421 }
2422 // Load already selected fields, if any:
2423 $setFields = is_array($this->setFields[$table]) ? $this->setFields[$table] : [];
2424 // Request fields from table:
2425 $fields = $this->makeFieldList($table, false, true);
2426 // Add pseudo "control" fields
2427 $fields[] = '_PATH_';
2428 $fields[] = '_REF_';
2429 $fields[] = '_LOCALIZATION_';
2430 $fields[] = '_CONTROL_';
2431 $fields[] = '_CLIPBOARD_';
2432 // Create a checkbox for each field:
2433 $checkboxes = [];
2434 $checkAllChecked = true;
2435 $tsConfig = BackendUtility::getPagesTSconfig($this->id);
2436 $tsConfigOfTable = is_array($tsConfig['TCEFORM.'][$table . '.']) ? $tsConfig['TCEFORM.'][$table . '.'] : null;
2437 foreach ($fields as $fieldName) {
2438 // Hide field if hidden
2439 if ($tsConfigOfTable && is_array($tsConfigOfTable[$fieldName . '.']) && isset($tsConfigOfTable[$fieldName . '.']['disabled']) && (int)$tsConfigOfTable[$fieldName . '.']['disabled'] === 1) {
2440 continue;
2441 }
2442 // Determine, if checkbox should be checked
2443 if (in_array($fieldName, $setFields, true) || $fieldName === $this->fieldArray[0]) {
2444 $checked = ' checked="checked"';
2445 } else {
2446 $checkAllChecked = false;
2447 $checked = '';
2448 }
2449 // Field label
2450 $fieldLabel = is_array($GLOBALS['TCA'][$table]['columns'][$fieldName])
2451 ? rtrim($lang->sL($GLOBALS['TCA'][$table]['columns'][$fieldName]['label']), ':')
2452 : '';
2453 $checkboxes[] = '<tr><td class="col-checkbox"><input type="checkbox" id="check-' . $fieldName . '" name="displayFields['
2454 . $table . '][]" value="' . $fieldName . '" ' . $checked
2455 . ($fieldName === $this->fieldArray[0] ? ' disabled="disabled"' : '') . '></td><td class="col-title">'
2456 . '<label class="label-block" for="check-' . $fieldName . '">' . htmlspecialchars($fieldLabel) . ' <span class="text-muted text-monospace">[' . htmlspecialchars($fieldName) . ']</span></label></td></tr>';
2457 }
2458 // Table with the field selector::
2459 $content = $formElements[0] . '
2460 <input type="hidden" name="displayFields[' . $table . '][]" value="">
2461 <div class="table-fit table-scrollable">
2462 <table border="0" cellpadding="0" cellspacing="0" class="table table-transparent table-hover">
2463 <thead>
2464 <tr>
2465 <th class="col-checkbox checkbox" colspan="2">
2466 <label><input type="checkbox" class="checkbox checkAll" ' . ($checkAllChecked ? ' checked="checked"' : '') . '>
2467 ' . htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.toggleall')) . '</label>
2468 </th>
2469 </tr>
2470 </thead>
2471 <tbody>
2472 ' . implode('', $checkboxes) . '
2473 </tbody>
2474 </table>
2475 </div>
2476 <input type="submit" name="search" class="btn btn-default" value="'
2477 . htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.setFields')) . '"/>
2478 ' . $formElements[1];
2479 return '<div class="fieldSelectBox">' . $content . '</div>';
2480 }
2481
2482 /*********************************
2483 *
2484 * Helper functions
2485 *
2486 *********************************/
2487 /**
2488 * Creates a link around $string. The link contains an onclick action
2489 * which submits the script with some clipboard action.
2490 * Currently, this is used for setting elements / delete elements.
2491 *
2492 * @param string $string The HTML content to link (image/text)
2493 * @param string $table Table name
2494 * @param string $cmd Clipboard command (eg. "setCB" or "delete")
2495 * @param string $warning Warning text, if any ("delete" uses this for confirmation
2496 * @param string $title title attribute for the anchor
2497 * @return string <a> tag wrapped link.
2498 */
2499 public function linkClipboardHeaderIcon($string, $table, $cmd, $warning = '', $title = '')
2500 {
2501 $jsCode = 'document.dblistForm.cmd.value=' . GeneralUtility::quoteJSvalue($cmd)
2502 . ';document.dblistForm.cmd_table.value='
2503 . GeneralUtility::quoteJSvalue($table)
2504 . ';document.dblistForm.submit();';
2505
2506 $attributes = [];
2507 if ($title !== '') {
2508 $attributes['title'] = $title;
2509 }
2510 if ($warning) {
2511 $attributes['class'] = 'btn btn-default t3js-modal-trigger';
2512 $attributes['data-href'] = 'javascript:' . $jsCode;
2513 $attributes['data-severity'] = 'warning';
2514 $attributes['data-title'] = $title;
2515 $attributes['data-content'] = $warning;
2516 } else {
2517 $attributes['class'] = 'btn btn-default';
2518 $attributes['onclick'] = $jsCode . 'return false;';
2519 }
2520
2521 $attributesString = '';
2522 foreach ($attributes as $key => $value) {
2523 $attributesString .= ' ' . $key . '="' . htmlspecialchars($value) . '"';
2524 }
2525 return '<a href="#" ' . $attributesString . '>' . $string . '</a>';
2526 }
2527
2528 /**
2529 * Returns TRUE if a numeric clipboard pad is selected/active
2530 *
2531 * @return bool
2532 */
2533 public function clipNumPane()
2534 {
2535 return in_array('_CLIPBOARD_', $this->fieldArray) && $this->clipObj->current !== 'normal';
2536 }
2537
2538 /**
2539 * Creates a sort-by link on the input string ($code).
2540 * It will automatically detect if sorting should be ascending or descending depending on $this->sortRev.
2541 * Also some fields will not be possible to sort (including if single-table-view is disabled).
2542 *
2543 * @param string $code The string to link (text)
2544 * @param string $field The fieldname represented by the title ($code)
2545 * @param string $table Table name
2546 * @return string Linked $code variable
2547 */
2548 public function addSortLink($code, $field, $table)
2549 {
2550 // Certain circumstances just return string right away (no links):
2551 if ($field === '_CONTROL_' || $field === '_LOCALIZATION_' || $field === '_CLIPBOARD_' || $field === '_REF_' || $this->disableSingleTableView) {
2552 return $code;
2553 }
2554 // If "_PATH_" (showing record path) is selected, force sorting by pid field (will at least group the records!)
2555 if ($field === '_PATH_') {
2556 $field = 'pid';
2557 }
2558 // Create the sort link:
2559 $sortUrl = $this->listURL('', '-1', 'sortField,sortRev,table,firstElementNumber') . '&table=' . $table
2560 . '&sortField=' . $field . '&sortRev=' . ($this->sortRev || $this->sortField != $field ? 0 : 1);
2561 $sortArrow = $this->sortField === $field
2562 ? $this->iconFactory->getIcon('status-status-sorting-' . ($this->sortRev ? 'desc' : 'asc'), Icon::SIZE_SMALL)->render()
2563 : '';
2564 // Return linked field:
2565 return '<a href="' . htmlspecialchars($sortUrl) . '">' . $code . $sortArrow . '</a>';
2566 }
2567
2568 /**
2569 * Returns the path for a certain pid
2570 * The result is cached internally for the session, thus you can call
2571 * this function as much as you like without performance problems.
2572 *
2573 * @param int $pid The page id for which to get the path
2574 * @return mixed[] The path.
2575 */
2576 public function recPath($pid)
2577 {
2578 if (!isset($this->recPath_cache[$pid])) {
2579 $this->recPath_cache[$pid] = BackendUtility::getRecordPath($pid, $this->perms_clause, 20);
2580 }
2581 return $this->recPath_cache[$pid];
2582 }
2583
2584 /**
2585 * Returns TRUE if a link for creating new records should be displayed for $table
2586 *
2587 * @param string $table Table name
2588 * @return bool Returns TRUE if a link for creating new records should be displayed for $table
2589 * @see \TYPO3\CMS\Backend\Controller\NewRecordController::showNewRecLink
2590 */
2591 public function showNewRecLink($table)
2592 {
2593 // No deny/allow tables are set:
2594 if (empty($this->allowedNewTables) && empty($this->deniedNewTables)) {
2595 return true;
2596 }
2597 return !in_array($table, $this->deniedNewTables)
2598 && (empty($this->allowedNewTables) || in_array($table, $this->allowedNewTables));
2599 }
2600
2601 /**
2602 * Creates the "&returnUrl" parameter for links - this is used when the script links
2603 * to other scripts and passes its own URL with the link so other scripts can return to the listing again.
2604 * Uses REQUEST_URI as value.
2605 *
2606 * @return string
2607 */
2608 public function makeReturnUrl()
2609 {
2610 return '&returnUrl=' . rawurlencode(GeneralUtility::getIndpEnv('REQUEST_URI'));
2611 }
2612
2613 /************************************
2614 *
2615 * CSV related functions
2616 *
2617 ************************************/
2618 /**
2619 * Initializes internal csvLines array with the header of field names
2620 */
2621 protected function initCSV()
2622 {
2623 $this->addHeaderRowToCSV();
2624 }
2625
2626 /**
2627 * Add header line with field names as CSV line
2628 */
2629 protected function addHeaderRowToCSV()
2630 {
2631 // Add header row, control fields will be reduced inside addToCSV()
2632 $this->addToCSV(array_combine($this->fieldArray, $this->fieldArray));
2633 }
2634
2635 /**
2636 * Adds selected columns of one table row as CSV line.
2637 *
2638 * @param mixed[] $row Record array, from which the values of fields found in $this->fieldArray will be listed in the CSV output.
2639 */
2640 protected function addToCSV(array $row = [])
2641 {
2642 $rowReducedByControlFields = self::removeControlFieldsFromFieldRow($row);
2643 // Get an field array without control fields but in the expected order
2644 $fieldArray = array_intersect_key(array_flip($this->fieldArray), $rowReducedByControlFields);
2645 // Overwrite fieldArray to keep the order with an array of needed fields
2646 $rowReducedToSelectedColumns = array_replace($fieldArray, array_intersect_key($rowReducedByControlFields, $fieldArray));
2647 $this->setCsvRow($rowReducedToSelectedColumns);
2648 }
2649
2650 /**
2651 * Remove control fields from row for CSV export
2652 *
2653 * @param mixed[] $row fieldNames => fieldValues
2654 * @return mixed[] Input array reduces by control fields
2655 */
2656 protected static function removeControlFieldsFromFieldRow(array $row = [])
2657 {
2658 // Possible control fields in a list row
2659 $controlFields = [
2660 '_PATH_',
2661 '_REF_',
2662 '_CONTROL_',
2663 '_CLIPBOARD_',
2664 '_LOCALIZATION_',