44ef896167d9f91954edce8ec0163ebb31632390
[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\Localization\LanguageService;
22 use TYPO3\CMS\Core\Utility\GeneralUtility;
23 use TYPO3\CMS\Fluid\View\StandaloneView;
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">' . htmlspecialchars($languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.new')) . '</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 = htmlspecialchars($languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.createNewPage'));
79 $pageTitle = sprintf($label, $tableTitle);
80 } else {
81 $label = htmlspecialchars($languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.createNewRecord'));
82 if ($this->data['effectivePid'] === 0) {
83 $label = htmlspecialchars($languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.createNewRecordRootLevel'));
84 }
85 $pageTitle = sprintf($label, $tableTitle, $pageTitle);
86 }
87 } else {
88 $icon = BackendUtility::wrapClickMenuOnIcon($icon, $table, $row['uid']);
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 = htmlspecialchars($languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.editPage'));
95 $pageTitle = sprintf($label, $tableTitle, $recordLabel);
96 } else {
97 $label = htmlspecialchars($languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.editRecord'));
98 $workspacedPageRecord = BackendUtility::getRecordWSOL('pages', $row['pid'], 'uid,title');
99 $pageTitle = BackendUtility::getRecordTitle('pages', $workspacedPageRecord, true, false);
100 if (empty($recordLabel)) {
101 $label = htmlspecialchars($languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.editRecordNoTitle'));
102 }
103 if ($this->data['effectivePid'] === 0) {
104 $label = htmlspecialchars($languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.editRecordRootLevel'));
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/Resources/Private/Language/locallang_core.xlf:labels.recordInformation');
125 $content = $this->data['databaseRow'][$descriptionColumn];
126 $view->assignMultiple([
127 'infoBoxMessageTitle' => $title,
128 'infoBoxMessage' => $content
129 ]);
130 }
131
132 $fieldInformationResult = $this->renderFieldInformation();
133 $fieldInformationHtml = $fieldInformationResult['html'];
134 $result = $this->mergeChildReturnIntoExistingResult($result, $fieldInformationResult, false);
135
136 $fieldWizardResult = $this->renderFieldWizard();
137 $fieldWizardHtml = $fieldWizardResult['html'];
138 $result = $this->mergeChildReturnIntoExistingResult($result, $fieldWizardResult, false);
139
140 $view->assignMultiple([
141 'pageTitle' => $pageTitle,
142 'fieldInformationHtml' => $fieldInformationHtml,
143 'fieldWizardHtml' => $fieldWizardHtml,
144 'childHtml' => $childHtml,
145 'icon' => $icon,
146 'tableTitle' => $tableTitle,
147 'newOrUid' => $newOrUid
148 ]);
149 $result['html'] = $view->render();
150 return $result;
151 }
152
153 /**
154 * @return LanguageService
155 */
156 protected function getLanguageService()
157 {
158 return $GLOBALS['LANG'];
159 }
160
161 /**
162 * @return BackendUserAuthentication
163 */
164 protected function getBackendUserAuthentication()
165 {
166 return $GLOBALS['BE_USER'];
167 }
168 }