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