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