[!!!][FEATURE] FormEngine element level refactoring
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Form / FieldWizard / RecordsOverview.php
1 <?php
2 declare(strict_types=1);
3 namespace TYPO3\CMS\Backend\Form\FieldWizard;
4
5 /*
6 * This file is part of the TYPO3 CMS project.
7 *
8 * It is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU General Public License, either version 2
10 * of the License, or any later version.
11 *
12 * For the full copyright and license information, please read the
13 * LICENSE.txt file that was distributed with this source code.
14 *
15 * The TYPO3 project - inspiring people to share!
16 */
17
18 use TYPO3\CMS\Backend\Form\AbstractNode;
19 use TYPO3\CMS\Backend\Utility\BackendUtility;
20 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
21 use TYPO3\CMS\Core\Imaging\Icon;
22 use TYPO3\CMS\Core\Imaging\IconFactory;
23 use TYPO3\CMS\Core\Utility\GeneralUtility;
24 use TYPO3\CMS\Lang\LanguageService;
25
26 /**
27 * Render details of selected records,
28 * typically used with type=group and internal_type=db.
29 */
30 class RecordsOverview extends AbstractNode
31 {
32 /**
33 * Render table with record details
34 *
35 * @return array
36 */
37 public function render(): array
38 {
39 $languageService = $this->getLanguageService();
40 $backendUser = $this->getBackendUserAuthentication();
41 $result = $this->initializeResultArray();
42
43 $parameterArray = $this->data['parameterArray'];
44 $config = $parameterArray['fieldConf']['config'];
45 $selectedItems = $parameterArray['itemFormElValue'];
46 $maxTitleLength = $backendUser->uc['titleLen'];
47
48 if (!isset($config['internal_type']) || $config['internal_type'] !== 'db') {
49 // Table list makes sense on db only
50 return $result;
51 }
52
53 $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
54 $recordsOverviewHtml = [];
55 foreach ($selectedItems as $selectedItem) {
56 $title = $selectedItem['title'];
57 if (empty($title)) {
58 $title = '[' . $languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.no_title') . ']';
59 }
60 $shortenedTitle = GeneralUtility::fixed_lgd_cs($title, $maxTitleLength);
61 $linkedIcon = BackendUtility::wrapClickMenuOnIcon(
62 $iconFactory->getIconForRecord($selectedItem['table'], $selectedItem['row'], Icon::SIZE_SMALL)->render(),
63 $selectedItem['table'],
64 $selectedItem['uid'],
65 1,
66 '',
67 '+copy,info,edit,view'
68 );
69 $linkedTitle = BackendUtility::wrapClickMenuOnIcon(
70 $shortenedTitle,
71 $selectedItem['table'],
72 $selectedItem['uid'],
73 1,
74 '',
75 '+copy,info,edit,view'
76 );
77 $recordsOverviewHtml[] = '<tr>';
78 $recordsOverviewHtml[] = '<td class="col-icon">';
79 $recordsOverviewHtml[] = $linkedIcon;
80 $recordsOverviewHtml[] = '</td>';
81 $recordsOverviewHtml[] = '<td class="col-title">';
82 $recordsOverviewHtml[] = $linkedTitle;
83 $recordsOverviewHtml[] = '<span class="text-muted">';
84 $recordsOverviewHtml[] = ' [' . $selectedItem['uid'] . ']';
85 $recordsOverviewHtml[] = '</span>';
86 $recordsOverviewHtml[] = '</td>';
87 $recordsOverviewHtml[] = '</tr>';
88 }
89
90 $html = [];
91 if (!empty($recordsOverviewHtml)) {
92 $html[] = '<div class="table-fit">';
93 $html[] = '<table class="table table-white">';
94 $html[] = '<tbody>';
95 $html[] = implode(LF, $recordsOverviewHtml);
96 $html[] = '</tbody>';
97 $html[] = '</table>';
98 $html[] = '</div>';
99 }
100
101 $result['html'] = implode(LF, $html);
102 return $result;
103 }
104
105 /**
106 * @return BackendUserAuthentication
107 */
108 protected function getBackendUserAuthentication()
109 {
110 return $GLOBALS['BE_USER'];
111 }
112
113 /**
114 * @return LanguageService
115 */
116 protected function getLanguageService()
117 {
118 return $GLOBALS['LANG'];
119 }
120 }