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