[!!!][TASK] Remove deprecated code from EXT:tstemplate
[Packages/TYPO3.CMS.git] / typo3 / sysext / tstemplate / Classes / Controller / TypoScriptTemplateInformationModuleFunctionController.php
1 <?php
2 namespace TYPO3\CMS\Tstemplate\Controller;
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\Core\Localization\LanguageService;
18 use TYPO3\CMS\Core\TypoScript\ExtendedTemplateService;
19 use TYPO3\CMS\Core\Utility\GeneralUtility;
20 use TYPO3\CMS\Core\Utility\HttpUtility;
21 use TYPO3\CMS\Fluid\View\StandaloneView;
22
23 /**
24 * This class displays the Info/Modify screen of the Web > Template module
25 * @internal This is a specific Backend Controller implementation and is not considered part of the Public TYPO3 API.
26 */
27 class TypoScriptTemplateInformationModuleFunctionController
28 {
29
30 /**
31 * @var TypoScriptTemplateModuleController
32 */
33 protected $pObj;
34
35 /**
36 * The currently selected sys_template record
37 * @var array
38 */
39 protected $templateRow;
40
41 /**
42 * @var ExtendedTemplateService
43 */
44 protected $templateService;
45
46 /**
47 * @var int GET/POST var 'id'
48 */
49 protected $id;
50
51 /**
52 * Init, called from parent object
53 *
54 * @param TypoScriptTemplateModuleController $pObj A reference to the parent (calling) object
55 */
56 public function init($pObj)
57 {
58 $this->pObj = $pObj;
59 $this->id = (int)GeneralUtility::_GP('id');
60 }
61
62 /**
63 * Gets the data for a row of a HTML table in the fluid template
64 *
65 * @param string $label The label to be shown (e.g. 'Title:', 'Sitetitle:')
66 * @param string $data The data/information to be shown (e.g. 'Template for my site')
67 * @param string $field The field/variable to be sent on clicking the edit icon (e.g. 'title', 'sitetitle')
68 * @param int $id The field/variable to be sent on clicking the edit icon (e.g. 'title', 'sitetitle')
69 * @return array Data for a row of a HTML table
70 */
71 protected function tableRowData($label, $data, $field, $id)
72 {
73 $urlParameters = [
74 'id' => $this->id,
75 'edit' => [
76 'sys_template' => [
77 $id => 'edit'
78 ]
79 ],
80 'columnsOnly' => $field,
81 'createExtension' => 0,
82 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
83 ];
84 /** @var \TYPO3\CMS\Backend\Routing\UriBuilder $uriBuilder */
85 $uriBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Routing\UriBuilder::class);
86 $url = (string)$uriBuilder->buildUriFromRoute('record_edit', $urlParameters);
87
88 return [
89 'url' => $url,
90 'data' => $data,
91 'label' => $label
92 ];
93 }
94
95 /**
96 * Create an instance of \TYPO3\CMS\Core\TypoScript\ExtendedTemplateService
97 * and looks for the first (visible) template
98 * record. If $template_uid was given and greater than zero, this record will be checked.
99 *
100 * Initializes the module. Done in this function because we may need to re-initialize if data is submitted!
101 *
102 * @param int $pageId The uid of the current page
103 * @param int $template_uid The uid of the template record to be rendered (only if more than one template on the current page)
104 * @return bool Returns TRUE if a template record was found, otherwise FALSE
105 */
106 protected function initialize_editor($pageId, $template_uid = 0)
107 {
108 $this->templateService = GeneralUtility::makeInstance(ExtendedTemplateService::class);
109
110 // Get the row of the first VISIBLE template of the page. where clause like the frontend.
111 $this->templateRow = $this->templateService->ext_getFirstTemplate($pageId, $template_uid);
112 if (is_array($this->templateRow)) {
113 return true;
114 }
115 return false;
116 }
117
118 /**
119 * Main, called from parent object
120 *
121 * @return string Information of the template status or the taken actions as HTML string
122 */
123 public function main()
124 {
125 // Checking for more than one template an if, set a menu...
126 $manyTemplatesMenu = $this->pObj->templateMenu();
127 $template_uid = 0;
128 if ($manyTemplatesMenu) {
129 $template_uid = $this->pObj->MOD_SETTINGS['templatesOnPage'];
130 }
131 // Initialize
132 $existTemplate = $this->initialize_editor($this->id, $template_uid);
133 $saveId = 0;
134 if ($existTemplate) {
135 $saveId = $this->templateRow['_ORIG_uid'] ?: $this->templateRow['uid'];
136 }
137 /** @var \TYPO3\CMS\Backend\Routing\UriBuilder $uriBuilder */
138 $uriBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Routing\UriBuilder::class);
139 // Create extension template
140 $newId = $this->pObj->createTemplate($this->id, $saveId);
141 if ($newId) {
142 // Switch to new template
143 $urlParameters = [
144 'id' => $this->id,
145 'SET[templatesOnPage]' => $newId
146 ];
147 $url = (string)$uriBuilder->buildUriFromRoute('web_ts', $urlParameters);
148 HttpUtility::redirect($url);
149 }
150 $tce = null;
151 if ($existTemplate) {
152 $lang = $this->getLanguageService();
153 $lang->includeLLFile('EXT:tstemplate/Resources/Private/Language/locallang_info.xlf');
154 $assigns = [];
155 $assigns['LLPrefix'] = 'LLL:EXT:tstemplate/Resources/Private/Language/locallang_info.xlf:';
156
157 $assigns['title'] = trim($this->templateRow['title']);
158 $assigns['siteTitle'] = trim($this->templateRow['sitetitle']);
159 $assigns['templateRecord'] = $this->templateRow;
160 if ($manyTemplatesMenu) {
161 $assigns['manyTemplatesMenu'] = $manyTemplatesMenu;
162 }
163
164 // Processing:
165 $tableRows = [];
166 $tableRows[] = $this->tableRowData($lang->getLL('title'), $this->templateRow['title'], 'title', $this->templateRow['uid']);
167 $tableRows[] = $this->tableRowData($lang->getLL('sitetitle'), $this->templateRow['sitetitle'], 'sitetitle', $this->templateRow['uid']);
168 $tableRows[] = $this->tableRowData($lang->getLL('description'), $this->templateRow['description'], 'description', $this->templateRow['uid']);
169 $tableRows[] = $this->tableRowData($lang->getLL('constants'), sprintf($lang->getLL('editToView'), trim($this->templateRow['constants']) ? count(explode(LF, $this->templateRow['constants'])) : 0), 'constants', $this->templateRow['uid']);
170 $tableRows[] = $this->tableRowData($lang->getLL('setup'), sprintf($lang->getLL('editToView'), trim($this->templateRow['config']) ? count(explode(LF, $this->templateRow['config'])) : 0), 'config', $this->templateRow['uid']);
171 $assigns['tableRows'] = $tableRows;
172
173 // Edit all icon:
174 $urlParameters = [
175 'edit' => [
176 'sys_template' => [
177 $this->templateRow['uid'] => 'edit'
178 ]
179 ],
180 'createExtension' => 0,
181 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
182 ];
183 $assigns['editAllUrl'] = (string)$uriBuilder->buildUriFromRoute('record_edit', $urlParameters);
184
185 // Rendering of the output via fluid
186 $view = GeneralUtility::makeInstance(StandaloneView::class);
187 $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName(
188 'EXT:tstemplate/Resources/Private/Templates/InformationModule.html'
189 ));
190 $view->assignMultiple($assigns);
191 $theOutput = $view->render();
192 } else {
193 $theOutput = $this->pObj->noTemplate(1);
194 }
195 return $theOutput;
196 }
197
198 /**
199 * @return LanguageService
200 */
201 protected function getLanguageService(): LanguageService
202 {
203 return $GLOBALS['LANG'];
204 }
205 }