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