[TASK] Optimize record description handling
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Form / Container / OuterWrapContainer.php
1 <?php
2 namespace TYPO3\CMS\Backend\Form\Container;
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\Utility\BackendUtility;
18 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
19 use TYPO3\CMS\Core\Imaging\Icon;
20 use TYPO3\CMS\Core\Imaging\IconFactory;
21 use TYPO3\CMS\Core\Utility\GeneralUtility;
22 use TYPO3\CMS\Fluid\View\StandaloneView;
23 use TYPO3\CMS\Lang\LanguageService;
24
25 /**
26 * Render header and footer row.
27 *
28 * This is an entry container called from controllers.
29 * It wraps the title and a footer around the main html.
30 * It either calls a FullRecordContainer or ListOfFieldsContainer to render
31 * a full record or only some fields from a full record.
32 */
33 class OuterWrapContainer extends AbstractContainer
34 {
35 /**
36 * Entry method
37 *
38 * @return array As defined in initializeResultArray() of AbstractNode
39 */
40 public function render()
41 {
42 $languageService = $this->getLanguageService();
43 $backendUser = $this->getBackendUserAuthentication();
44
45 $table = $this->data['tableName'];
46 $row = $this->data['databaseRow'];
47
48 $options = $this->data;
49 if (empty($this->data['fieldListToRender'])) {
50 $options['renderType'] = 'fullRecordContainer';
51 } else {
52 $options['renderType'] = 'listOfFieldsContainer';
53 }
54 $result = $this->nodeFactory->create($options)->render();
55
56 $childHtml = $result['html'];
57
58 $recordPath = '';
59 // @todo: what is this >= 0 check for? wsol cases?!
60 if ($this->data['effectivePid'] >= 0) {
61 $permissionsClause = $backendUser->getPagePermsClause(1);
62 $recordPath = BackendUtility::getRecordPath($this->data['effectivePid'], $permissionsClause, 15);
63 }
64
65 $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
66 $icon = '<span title="' . htmlspecialchars($recordPath) . '">' . $iconFactory->getIconForRecord($table, $row, Icon::SIZE_SMALL)->render() . '</span>';
67
68 // @todo: Could this be done in a more clever way? Does it work at all?
69 $tableTitle = $languageService->sL($this->data['processedTca']['ctrl']['title']);
70
71 if ($this->data['command'] === 'new') {
72 $newOrUid = ' <span class="typo3-TCEforms-newToken">' . $languageService->sL('LLL:EXT:lang/locallang_core.xlf:labels.new', true) . '</span>';
73
74 // @todo: There is quite some stuff do to for WS overlays ...
75 $workspacedPageRecord = BackendUtility::getRecordWSOL('pages', $this->data['effectivePid'], 'title');
76 $pageTitle = BackendUtility::getRecordTitle('pages', $workspacedPageRecord, true, false);
77 if ($table === 'pages') {
78 $label = $languageService->sL('LLL:EXT:lang/locallang_core.xlf:labels.createNewPage', true);
79 $pageTitle = sprintf($label, $tableTitle);
80 } else {
81 $label = $languageService->sL('LLL:EXT:lang/locallang_core.xlf:labels.createNewRecord', true);
82 if ($this->data['effectivePid'] === 0) {
83 $label = $languageService->sL('LLL:EXT:lang/locallang_core.xlf:labels.createNewRecordRootLevel', true);
84 }
85 $pageTitle = sprintf($label, $tableTitle, $pageTitle);
86 }
87 } else {
88 $icon = BackendUtility::wrapClickMenuOnIcon($icon, $table, $row['uid'], 1, '', '+copy,info,edit,view');
89 $newOrUid = ' <span class="typo3-TCEforms-recUid">[' . htmlspecialchars($row['uid']) . ']</span>';
90
91 // @todo: getRecordTitlePrep applies an htmlspecialchars here
92 $recordLabel = BackendUtility::getRecordTitlePrep($this->data['recordTitle']);
93 if ($table === 'pages') {
94 $label = $languageService->sL('LLL:EXT:lang/locallang_core.xlf:labels.editPage', true);
95 $pageTitle = sprintf($label, $tableTitle, $recordLabel);
96 } else {
97 $label = $languageService->sL('LLL:EXT:lang/locallang_core.xlf:labels.editRecord', true);
98 $workspacedPageRecord = BackendUtility::getRecordWSOL('pages', $row['pid'], 'uid,title');
99 $pageTitle = BackendUtility::getRecordTitle('pages', $workspacedPageRecord, true, false);
100 if (empty($recordLabel)) {
101 $label = $languageService->sL('LLL:EXT:lang/locallang_core.xlf:labels.editRecordNoTitle', true);
102 }
103 if ($this->data['effectivePid'] === 0) {
104 $label = $languageService->sL('LLL:EXT:lang/locallang_core.xlf:labels.editRecordRootLevel', true);
105 }
106 if (!empty($recordLabel)) {
107 // Use record title and prepend an edit label.
108 $pageTitle = sprintf($label, $tableTitle, $recordLabel, $pageTitle);
109 } else {
110 // Leave out the record title since it is not set.
111 $pageTitle = sprintf($label, $tableTitle, $pageTitle);
112 }
113 }
114 }
115
116 $view = GeneralUtility::makeInstance(StandaloneView::class);
117 $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName(
118 'EXT:backend/Resources/Private/Templates/OuterWrapContainer.html'
119 ));
120
121 $descriptionColumn = !empty($this->data['processedTca']['ctrl']['descriptionColumn'])
122 ? $this->data['processedTca']['ctrl']['descriptionColumn'] : null;
123 if ($descriptionColumn !== null) {
124 $title = $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.recordInformation');
125 $content = $this->data['databaseRow'][$descriptionColumn];
126 $view->assignMultiple([
127 'infoBoxMessageTitle' => $title,
128 'infoBoxMessage' => $content
129 ]);
130 }
131
132 $view->assignMultiple(array(
133 'pageTitle' => $pageTitle,
134 'childHtml' => $childHtml,
135 'icon' => $icon,
136 'tableTitle' => $tableTitle,
137 'newOrUid' => $newOrUid
138 ));
139 $result['html'] = $view->render();
140 return $result;
141 }
142
143 /**
144 * @return LanguageService
145 */
146 protected function getLanguageService()
147 {
148 return $GLOBALS['LANG'];
149 }
150
151 /**
152 * @return BackendUserAuthentication
153 */
154 protected function getBackendUserAuthentication()
155 {
156 return $GLOBALS['BE_USER'];
157 }
158 }