‪TYPO3CMS  11.5
TypoScriptTemplateConstantEditorModuleFunctionController.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
18 use Psr\Http\Message\ServerRequestInterface;
19 use TYPO3\CMS\Backend\Utility\BackendUtility;
22 use TYPO3\CMS\Core\Page\PageRenderer;
23 use TYPO3\CMS\Core\TypoScript\ExtendedTemplateService;
27 
33 {
37  protected ‪$pObj;
38 
43  protected ‪$templateRow;
44 
48  protected ‪$templateService;
49 
53  protected ‪$constants;
54 
58  protected ‪$id;
59 
63  protected ‪$request;
64 
71  public function ‪init(‪$pObj, ServerRequestInterface ‪$request)
72  {
73  $this->pObj = ‪$pObj;
74  $this->request = ‪$request;
75  $this->id = (int)(‪$request->getParsedBody()['id'] ?? ‪$request->getQueryParams()['id'] ?? 0);
76  }
77 
88  protected function ‪initialize_editor($pageId, $template_uid = 0)
89  {
90  $this->templateService = GeneralUtility::makeInstance(ExtendedTemplateService::class);
91 
92  // Get the row of the first VISIBLE template of the page. whereclause like the frontend.
93  $this->templateRow = $this->templateService->ext_getFirstTemplate($pageId, $template_uid);
94  // IF there was a template...
95  if (is_array($this->templateRow)) {
96  // Gets the rootLine
97  $rootlineUtility = GeneralUtility::makeInstance(RootlineUtility::class, $pageId);
98  $rootLine = $rootlineUtility->get();
99  // This generates the constants/config + hierarchy info for the template.
100  $this->templateService->runThroughTemplates($rootLine, $template_uid);
101  // The editable constants are returned in an array.
102  $this->constants = $this->templateService->generateConfig_constants();
103  // The returned constants are sorted in categories, that goes into the $tmpl->categories array
104  $this->templateService->ext_categorizeEditableConstants($this->constants);
105  // This array will contain key=[expanded constant name], value=line number in template.
106  $this->templateService->ext_regObjectPositions((string)$this->templateRow['constants']);
107  return true;
108  }
109  return false;
110  }
111 
117  public function ‪main()
118  {
119  $assigns = [];
120  // Create extension template
121  $this->pObj->createTemplate($this->id);
122  // Checking for more than one template an if, set a menu...
123  $manyTemplatesMenu = $this->pObj->templateMenu($this->request);
124  $template_uid = 0;
125  if ($manyTemplatesMenu) {
126  $template_uid = $this->pObj->MOD_SETTINGS['templatesOnPage'];
127  }
128 
129  // initialize
130  $existTemplate = $this->‪initialize_editor($this->id, $template_uid);
131  if ($existTemplate) {
132  $assigns['templateRecord'] = ‪$this->templateRow;
133  $assigns['manyTemplatesMenu'] = $manyTemplatesMenu;
134 
135  $saveId = empty($this->templateRow['_ORIG_uid']) ? $this->templateRow['uid'] : $this->templateRow['_ORIG_uid'];
136  // Update template ?
137  if ($this->request->getParsedBody()['_savedok'] ?? false) {
138  $this->templateService->changed = false;
139  $this->templateService->ext_procesInput($this->request->getParsedBody(), [], $this->constants, $this->templateRow);
140  if ($this->templateService->changed) {
141  // Set the data to be saved
142  $recData = [];
143  $recData['sys_template'][$saveId]['constants'] = implode(LF, $this->templateService->raw);
144  // Create new tce-object
145  $tce = GeneralUtility::makeInstance(DataHandler::class);
146  $tce->start($recData, []);
147  $tce->process_datamap();
148  // re-read the template ...
149  // re-read the constants as they have changed
150  $this->‪initialize_editor($this->id, $template_uid);
151  }
152  }
153  // Resetting the menu (start). I wonder if this in any way is a violation of the menu-system. Haven't checked. But need to do it here, because the menu is dependent on the categories available.
154  $this->pObj->MOD_MENU['constant_editor_cat'] = $this->templateService->ext_getCategoryLabelArray();
155  $this->pObj->MOD_SETTINGS = BackendUtility::getModuleData($this->pObj->MOD_MENU, $this->request->getParsedBody()['SET'] ?? $this->request->getQueryParams()['SET'] ?? [], 'web_ts');
156  // Resetting the menu (stop)
157  $assigns['title'] = $this->pObj->linkWrapTemplateTitle($this->templateRow['title'], 'constants');
158  if (!empty($this->pObj->MOD_MENU['constant_editor_cat'])) {
159  $assigns['constantsMenu'] = BackendUtility::getDropdownMenu($this->id, 'SET[constant_editor_cat]', $this->pObj->MOD_SETTINGS['constant_editor_cat'], $this->pObj->MOD_MENU['constant_editor_cat']);
160  }
161  // Category and constant editor config:
162  $category = $this->pObj->MOD_SETTINGS['constant_editor_cat'];
163 
164  $assigns['editorFields'] = $this->templateService->ext_printFields($this->constants, $category);
165  foreach ($this->templateService->getJavaScriptInstructions() as $instruction) {
166  $this->‪getPageRenderer()->getJavaScriptRenderer()->addJavaScriptModuleInstruction($instruction);
167  }
168 
169  // Rendering of the output via fluid
170  $view = GeneralUtility::makeInstance(StandaloneView::class);
171  $view->setTemplatePathAndFilename('EXT:tstemplate/Resources/Private/Templates/ConstantEditor.html');
172  $view->assignMultiple($assigns);
173  $theOutput = $view->render();
174  } else {
175  $theOutput = $this->pObj->noTemplate(1);
176  }
177  return $theOutput;
178  }
179 
183  protected function ‪getLanguageService(): ‪LanguageService
184  {
185  return ‪$GLOBALS['LANG'];
186  }
187 
191  protected function ‪getPageRenderer(): PageRenderer
192  {
193  return GeneralUtility::makeInstance(PageRenderer::class);
194  }
195 }
‪TYPO3\CMS\Core\DataHandling\DataHandler
Definition: DataHandler.php:86
‪TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateConstantEditorModuleFunctionController\initialize_editor
‪bool initialize_editor($pageId, $template_uid=0)
Definition: TypoScriptTemplateConstantEditorModuleFunctionController.php:83
‪TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateConstantEditorModuleFunctionController\$pObj
‪TypoScriptTemplateModuleController $pObj
Definition: TypoScriptTemplateConstantEditorModuleFunctionController.php:36
‪TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateConstantEditorModuleFunctionController\$constants
‪array $constants
Definition: TypoScriptTemplateConstantEditorModuleFunctionController.php:49
‪TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateConstantEditorModuleFunctionController\$id
‪$id
Definition: TypoScriptTemplateConstantEditorModuleFunctionController.php:54
‪TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateConstantEditorModuleFunctionController\main
‪string main()
Definition: TypoScriptTemplateConstantEditorModuleFunctionController.php:112
‪TYPO3\CMS\Core\Utility\RootlineUtility
Definition: RootlineUtility.php:38
‪TYPO3\CMS\Tstemplate\Controller
Definition: TemplateAnalyzerModuleFunctionController.php:16
‪TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateConstantEditorModuleFunctionController\init
‪init($pObj, ServerRequestInterface $request)
Definition: TypoScriptTemplateConstantEditorModuleFunctionController.php:66
‪TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateConstantEditorModuleFunctionController\$request
‪ServerRequestInterface $request
Definition: TypoScriptTemplateConstantEditorModuleFunctionController.php:58
‪TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateConstantEditorModuleFunctionController
Definition: TypoScriptTemplateConstantEditorModuleFunctionController.php:33
‪TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateModuleController
Definition: TypoScriptTemplateModuleController.php:51
‪TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateConstantEditorModuleFunctionController\$templateService
‪ExtendedTemplateService $templateService
Definition: TypoScriptTemplateConstantEditorModuleFunctionController.php:45
‪TYPO3\CMS\Fluid\View\StandaloneView
Definition: StandaloneView.php:31
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:42
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateConstantEditorModuleFunctionController\$templateRow
‪array null $templateRow
Definition: TypoScriptTemplateConstantEditorModuleFunctionController.php:41
‪TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateConstantEditorModuleFunctionController\getLanguageService
‪LanguageService getLanguageService()
Definition: TypoScriptTemplateConstantEditorModuleFunctionController.php:178
‪TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateConstantEditorModuleFunctionController\getPageRenderer
‪PageRenderer getPageRenderer()
Definition: TypoScriptTemplateConstantEditorModuleFunctionController.php:186