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