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