‪TYPO3CMS  10.4
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;
27 
33 {
34 
38  protected ‪$pObj;
39 
44  protected ‪$templateRow;
45 
49  protected ‪$templateService;
50 
54  protected ‪$constants;
55 
59  protected ‪$id;
60 
64  protected ‪$request;
65 
72  public function ‪init(‪$pObj, ServerRequestInterface ‪$request)
73  {
74  $this->pObj = ‪$pObj;
75  $this->request = ‪$request;
76  $this->id = (int)(‪$request->getParsedBody()['id'] ?? ‪$request->getQueryParams()['id'] ?? 0);
77  }
78 
89  protected function ‪initialize_editor($pageId, $template_uid = 0)
90  {
91  $this->templateService = GeneralUtility::makeInstance(ExtendedTemplateService::class);
92 
93  // Get the row of the first VISIBLE template of the page. whereclause like the frontend.
94  $this->templateRow = $this->templateService->ext_getFirstTemplate($pageId, $template_uid);
95  // IF there was a template...
96  if (is_array($this->templateRow)) {
97  // Gets the rootLine
98  $rootlineUtility = GeneralUtility::makeInstance(RootlineUtility::class, $pageId);
99  $rootLine = $rootlineUtility->get();
100  // This generates the constants/config + hierarchy info for the template.
101  $this->templateService->runThroughTemplates($rootLine, $template_uid);
102  // The editable constants are returned in an array.
103  $this->constants = $this->templateService->generateConfig_constants();
104  // The returned constants are sorted in categories, that goes into the $tmpl->categories array
105  $this->templateService->ext_categorizeEditableConstants($this->constants);
106  // This array will contain key=[expanded constant name], value=line number in template.
107  $this->templateService->ext_regObjectPositions($this->templateRow['constants']);
108  return true;
109  }
110  return false;
111  }
112 
118  public function ‪main()
119  {
120  $assigns = [];
121  $assigns['LLPrefix'] = 'LLL:EXT:tstemplate/Resources/Private/Language/locallang_ceditor.xlf:';
122  // Create extension template
123  $this->pObj->createTemplate($this->id);
124  // Checking for more than one template an if, set a menu...
125  $manyTemplatesMenu = $this->pObj->templateMenu($this->request);
126  $template_uid = 0;
127  if ($manyTemplatesMenu) {
128  $template_uid = $this->pObj->MOD_SETTINGS['templatesOnPage'];
129  }
130 
131  // initialize
132  $existTemplate = $this->‪initialize_editor($this->id, $template_uid);
133  if ($existTemplate) {
134  $assigns['siteTitle'] = trim($this->templateRow['sitetitle']);
135  $assigns['templateRecord'] = ‪$this->templateRow;
136  if ($manyTemplatesMenu) {
137  $assigns['manyTemplatesMenu'] = $manyTemplatesMenu;
138  }
139 
140  $saveId = $this->templateRow['_ORIG_uid'] ?: $this->templateRow['uid'];
141  // Update template ?
142  if ($this->request->getParsedBody()['_savedok'] ?? false) {
143  $this->templateService->changed = 0;
144  $this->templateService->ext_procesInput($this->request->getParsedBody(), [], $this->constants, $this->templateRow);
145  if ($this->templateService->changed) {
146  // Set the data to be saved
147  $recData = [];
148  $recData['sys_template'][$saveId]['constants'] = implode(LF, $this->templateService->raw);
149  // Create new tce-object
150  $tce = GeneralUtility::makeInstance(DataHandler::class);
151  $tce->start($recData, []);
152  $tce->process_datamap();
153  // re-read the template ...
154  // re-read the constants as they have changed
155  $this->‪initialize_editor($this->id, $template_uid);
156  }
157  }
158  // 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.
159  $this->pObj->MOD_MENU['constant_editor_cat'] = $this->templateService->ext_getCategoryLabelArray();
160  $this->pObj->MOD_SETTINGS = ‪BackendUtility::getModuleData($this->pObj->MOD_MENU, $this->request->getParsedBody()['SET'] ?? $this->request->getQueryParams()['SET'] ?? [], 'web_ts');
161  // Resetting the menu (stop)
162  $assigns['title'] = $this->pObj->linkWrapTemplateTitle($this->templateRow['title'], 'constants');
163  if (!empty($this->pObj->MOD_MENU['constant_editor_cat'])) {
164  $assigns['constantsMenu'] = ‪BackendUtility::getDropdownMenu($this->id, 'SET[constant_editor_cat]', $this->pObj->MOD_SETTINGS['constant_editor_cat'], $this->pObj->MOD_MENU['constant_editor_cat']);
165  }
166  // Category and constant editor config:
167  $category = $this->pObj->MOD_SETTINGS['constant_editor_cat'];
168 
169  $printFields = trim($this->templateService->ext_printFields($this->constants, $category));
170  foreach ($this->templateService->getInlineJavaScript() as $name => $inlineJavaScript) {
171  $this->‪getPageRenderer()->‪addJsInlineCode($name, $inlineJavaScript);
172  }
173 
174  if ($printFields) {
175  $assigns['printFields'] = $printFields;
176  }
177  // Rendering of the output via fluid
178  $view = GeneralUtility::makeInstance(StandaloneView::class);
179  $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName(
180  'EXT:tstemplate/Resources/Private/Templates/ConstantEditor.html'
181  ));
182  $view->assignMultiple($assigns);
183  $theOutput = $view->render();
184  } else {
185  $theOutput = $this->pObj->noTemplate(1);
186  }
187  return $theOutput;
188  }
189 
193  protected function ‪getLanguageService(): ‪LanguageService
194  {
195  return ‪$GLOBALS['LANG'];
196  }
197 
201  protected function ‪getPageRenderer(): ‪PageRenderer
202  {
203  return GeneralUtility::makeInstance(PageRenderer::class);
204  }
205 }
‪TYPO3\CMS\Core\DataHandling\DataHandler
Definition: DataHandler.php:84
‪TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateConstantEditorModuleFunctionController\initialize_editor
‪bool initialize_editor($pageId, $template_uid=0)
Definition: TypoScriptTemplateConstantEditorModuleFunctionController.php:84
‪TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateConstantEditorModuleFunctionController\$templateRow
‪array $templateRow
Definition: TypoScriptTemplateConstantEditorModuleFunctionController.php:42
‪TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateConstantEditorModuleFunctionController\$pObj
‪TypoScriptTemplateModuleController $pObj
Definition: TypoScriptTemplateConstantEditorModuleFunctionController.php:37
‪TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateConstantEditorModuleFunctionController\$constants
‪array $constants
Definition: TypoScriptTemplateConstantEditorModuleFunctionController.php:50
‪TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateConstantEditorModuleFunctionController\$id
‪$id
Definition: TypoScriptTemplateConstantEditorModuleFunctionController.php:55
‪TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateConstantEditorModuleFunctionController\main
‪string main()
Definition: TypoScriptTemplateConstantEditorModuleFunctionController.php:113
‪TYPO3\CMS\Core\Utility\RootlineUtility
Definition: RootlineUtility.php:39
‪TYPO3\CMS\Tstemplate\Controller
Definition: TemplateAnalyzerModuleFunctionController.php:16
‪TYPO3\CMS\Core\TypoScript\ExtendedTemplateService
Definition: ExtendedTemplateService.php:43
‪TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateConstantEditorModuleFunctionController\init
‪init($pObj, ServerRequestInterface $request)
Definition: TypoScriptTemplateConstantEditorModuleFunctionController.php:67
‪TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateConstantEditorModuleFunctionController\$request
‪ServerRequestInterface $request
Definition: TypoScriptTemplateConstantEditorModuleFunctionController.php:59
‪TYPO3\CMS\Core\Page\PageRenderer
Definition: PageRenderer.php:42
‪TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateConstantEditorModuleFunctionController
Definition: TypoScriptTemplateConstantEditorModuleFunctionController.php:33
‪TYPO3\CMS\Backend\Utility\BackendUtility\getDropdownMenu
‪static string getDropdownMenu( $mainParams, $elementName, $currentValue, $menuItems, $script='', $addParams='')
Definition: BackendUtility.php:2653
‪TYPO3\CMS\Backend\Utility\BackendUtility\getModuleData
‪static array getModuleData( $MOD_MENU, $CHANGED_SETTINGS, $modName, $type='', $dontValidateList='', $setDefaultList='')
Definition: BackendUtility.php:2893
‪TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateModuleController
Definition: TypoScriptTemplateModuleController.php:48
‪TYPO3\CMS\Backend\Utility\BackendUtility
Definition: BackendUtility.php:75
‪TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateConstantEditorModuleFunctionController\$templateService
‪ExtendedTemplateService $templateService
Definition: TypoScriptTemplateConstantEditorModuleFunctionController.php:46
‪TYPO3\CMS\Fluid\View\StandaloneView
Definition: StandaloneView.php:34
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:42
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Core\Page\PageRenderer\addJsInlineCode
‪addJsInlineCode($name, $block, $compress=true, $forceOnTop=false)
Definition: PageRenderer.php:1155
‪TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateConstantEditorModuleFunctionController\getLanguageService
‪LanguageService getLanguageService()
Definition: TypoScriptTemplateConstantEditorModuleFunctionController.php:188
‪TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateConstantEditorModuleFunctionController\getPageRenderer
‪PageRenderer getPageRenderer()
Definition: TypoScriptTemplateConstantEditorModuleFunctionController.php:196