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