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