‪TYPO3CMS  9.5
TypoScriptTemplateConstantEditorModuleFunctionController.php
Go to the documentation of this file.
1 <?php
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 
27 
33 {
36 
41  'pObj' => 'Using TypoScriptTemplateConstantEditorModuleFunctionController::$pObj is deprecated and will not be possible anymore in TYPO3 v10.0.',
42  'function_key' => 'Using TypoScriptTemplateConstantEditorModuleFunctionController::$function_key is deprecated, property will be removed in TYPO3 v10.0.',
43  'extClassConf' => 'Using TypoScriptTemplateConstantEditorModuleFunctionController::$extClassConf is deprecated, property will be removed in TYPO3 v10.0.',
44  'localLangFile' => 'Using TypoScriptTemplateConstantEditorModuleFunctionController::$localLangFile is deprecated, property will be removed in TYPO3 v10.0.',
45  ];
46 
50  private ‪$deprecatedPublicMethods = [
51  'initialize_editor' => 'Using TypoScriptTemplateConstantEditorModuleFunctionController::initialize_editor() is deprecated and will not be possible anymore in TYPO3 v10.0.',
52  'handleExternalFunctionValue' => 'Using TypoScriptTemplateConstantEditorModuleFunctionController::handleExternalFunctionValue() is deprecated, method will be removed in TYPO3 v10.0.',
53  ];
54 
58  protected ‪$pObj;
59 
64  protected ‪$templateRow;
65 
69  protected ‪$templateService;
70 
74  protected ‪$constants;
75 
79  protected ‪$id;
80 
89  protected ‪$localLangFile = '';
90 
98  protected ‪$extClassConf;
99 
108  protected ‪$function_key = '';
109 
115  public function ‪init(‪$pObj)
116  {
117  $this->pObj = ‪$pObj;
118  // Local lang:
119  if (!empty($this->localLangFile)) {
120  // @deprecated since TYPO3 v9, will be removed in TYPO3 v10.0.
121  $this->‪getLanguageService()->‪includeLLFile($this->localLangFile);
122  }
123  $this->id = (int)GeneralUtility::_GP('id');
124  }
125 
136  protected function ‪initialize_editor($pageId, $template_uid = 0)
137  {
138  $this->templateService = GeneralUtility::makeInstance(ExtendedTemplateService::class);
139 
140  // Get the row of the first VISIBLE template of the page. whereclause like the frontend.
141  $this->templateRow = $this->templateService->ext_getFirstTemplate($pageId, $template_uid);
142  // IF there was a template...
143  if (is_array($this->templateRow)) {
144  // Gets the rootLine
145  $rootlineUtility = GeneralUtility::makeInstance(RootlineUtility::class, $pageId);
146  $rootLine = $rootlineUtility->get();
147  // This generates the constants/config + hierarchy info for the template.
148  $this->templateService->runThroughTemplates($rootLine, $template_uid);
149  // The editable constants are returned in an array.
150  $this->constants = $this->templateService->generateConfig_constants();
151  // The returned constants are sorted in categories, that goes into the $tmpl->categories array
152  $this->templateService->ext_categorizeEditableConstants($this->constants);
153  // This array will contain key=[expanded constant name], value=line number in template.
154  $this->templateService->ext_regObjectPositions($this->templateRow['constants']);
155  return true;
156  }
157  return false;
158  }
159 
165  public function ‪main()
166  {
167  $assigns = [];
168  $assigns['LLPrefix'] = 'LLL:EXT:tstemplate/Resources/Private/Language/locallang_ceditor.xlf:';
169  // Create extension template
170  $this->pObj->createTemplate($this->id);
171  // Checking for more than one template an if, set a menu...
172  $manyTemplatesMenu = $this->pObj->templateMenu();
173  $template_uid = 0;
174  if ($manyTemplatesMenu) {
175  $template_uid = $this->pObj->MOD_SETTINGS['templatesOnPage'];
176  }
177 
178  // initialize
179  $existTemplate = $this->‪initialize_editor($this->id, $template_uid);
180  if ($existTemplate) {
181  $assigns['siteTitle'] = trim($this->templateRow['sitetitle']);
182  $assigns['templateRecord'] = ‪$this->templateRow;
183  if ($manyTemplatesMenu) {
184  $assigns['manyTemplatesMenu'] = $manyTemplatesMenu;
185  }
186 
187  $saveId = $this->templateRow['_ORIG_uid'] ?: $this->templateRow['uid'];
188  // Update template ?
189  if (GeneralUtility::_POST('_savedok')) {
190  $this->templateService->changed = 0;
191  $this->templateService->ext_procesInput(GeneralUtility::_POST(), [], $this->constants, $this->templateRow);
192  if ($this->templateService->changed) {
193  // Set the data to be saved
194  $recData = [];
195  $recData['sys_template'][$saveId]['constants'] = implode(LF, $this->templateService->raw);
196  // Create new tce-object
197  $tce = GeneralUtility::makeInstance(DataHandler::class);
198  $tce->start($recData, []);
199  $tce->process_datamap();
200  // Clear the cache (note: currently only admin-users can clear the cache in tce_main.php)
201  $tce->clear_cacheCmd('all');
202  // re-read the template ...
203  // re-read the constants as they have changed
204  $this->‪initialize_editor($this->id, $template_uid);
205  }
206  }
207  // 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.
208  $this->pObj->MOD_MENU['constant_editor_cat'] = $this->templateService->ext_getCategoryLabelArray();
209  $this->pObj->MOD_SETTINGS = ‪BackendUtility::getModuleData($this->pObj->MOD_MENU, GeneralUtility::_GP('SET'), 'web_ts');
210  // Resetting the menu (stop)
211  $assigns['title'] = $this->pObj->linkWrapTemplateTitle($this->templateRow['title'], 'constants');
212  if (!empty($this->pObj->MOD_MENU['constant_editor_cat'])) {
213  $assigns['constantsMenu'] = ‪BackendUtility::getDropdownMenu($this->id, 'SET[constant_editor_cat]', $this->pObj->MOD_SETTINGS['constant_editor_cat'], $this->pObj->MOD_MENU['constant_editor_cat']);
214  }
215  // Category and constant editor config:
216  $category = $this->pObj->MOD_SETTINGS['constant_editor_cat'];
217 
218  $printFields = trim($this->templateService->ext_printFields($this->constants, $category));
219  foreach ($this->templateService->getInlineJavaScript() as $name => $inlineJavaScript) {
220  $this->‪getPageRenderer()->‪addJsInlineCode($name, $inlineJavaScript);
221  }
222 
223  if ($printFields) {
224  $assigns['printFields'] = $printFields;
225  }
226  // Rendering of the output via fluid
227  $view = GeneralUtility::makeInstance(StandaloneView::class);
228  $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName(
229  'EXT:tstemplate/Resources/Private/Templates/ConstantEditor.html'
230  ));
231  $view->assignMultiple($assigns);
232  $theOutput = $view->render();
233  } else {
234  $theOutput = $this->pObj->noTemplate(1);
235  }
236  return $theOutput;
237  }
238 
245  protected function ‪handleExternalFunctionValue()
246  {
247  // Must clean first to make sure the correct key is set...
248  $this->pObj->MOD_SETTINGS = ‪BackendUtility::getModuleData($this->pObj->MOD_MENU, GeneralUtility::_GP('SET'), 'web_ts');
249  if ($this->function_key) {
250  $this->extClassConf = $this->pObj->getExternalItemConfig('web_ts', $this->function_key, $this->pObj->MOD_SETTINGS[$this->function_key]);
251  }
252  }
253 
257  protected function ‪getLanguageService(): ‪LanguageService
258  {
259  return ‪$GLOBALS['LANG'];
260  }
261 
265  protected function ‪getPageRenderer(): PageRenderer
266  {
267  return GeneralUtility::makeInstance(PageRenderer::class);
268  }
269 }
‪TYPO3\CMS\Core\DataHandling\DataHandler
Definition: DataHandler.php:81
‪TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateConstantEditorModuleFunctionController\initialize_editor
‪bool initialize_editor($pageId, $template_uid=0)
Definition: TypoScriptTemplateConstantEditorModuleFunctionController.php:125
‪TYPO3\CMS\Core\Localization\LanguageService\includeLLFile
‪mixed includeLLFile($fileRef, $setGlobal=true, $mergeLocalOntoDefault=false)
Definition: LanguageService.php:260
‪TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateConstantEditorModuleFunctionController\$templateRow
‪array $templateRow
Definition: TypoScriptTemplateConstantEditorModuleFunctionController.php:58
‪TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateConstantEditorModuleFunctionController\$pObj
‪TypoScriptTemplateModuleController $pObj
Definition: TypoScriptTemplateConstantEditorModuleFunctionController.php:53
‪TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateConstantEditorModuleFunctionController\$constants
‪array $constants
Definition: TypoScriptTemplateConstantEditorModuleFunctionController.php:66
‪TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateConstantEditorModuleFunctionController\$extClassConf
‪array $extClassConf
Definition: TypoScriptTemplateConstantEditorModuleFunctionController.php:88
‪TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateConstantEditorModuleFunctionController\$id
‪$id
Definition: TypoScriptTemplateConstantEditorModuleFunctionController.php:71
‪TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateConstantEditorModuleFunctionController\main
‪string main()
Definition: TypoScriptTemplateConstantEditorModuleFunctionController.php:154
‪TYPO3\CMS\Core\Utility\RootlineUtility
Definition: RootlineUtility.php:36
‪TYPO3\CMS\Tstemplate\Controller
Definition: TemplateAnalyzerModuleFunctionController.php:2
‪TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateConstantEditorModuleFunctionController\$localLangFile
‪string $localLangFile
Definition: TypoScriptTemplateConstantEditorModuleFunctionController.php:80
‪TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateConstantEditorModuleFunctionController\$deprecatedPublicProperties
‪array $deprecatedPublicProperties
Definition: TypoScriptTemplateConstantEditorModuleFunctionController.php:37
‪TYPO3\CMS\Core\TypoScript\ExtendedTemplateService
Definition: ExtendedTemplateService.php:39
‪TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateConstantEditorModuleFunctionController\handleExternalFunctionValue
‪handleExternalFunctionValue()
Definition: TypoScriptTemplateConstantEditorModuleFunctionController.php:234
‪TYPO3\CMS\Core\Page\PageRenderer
Definition: PageRenderer.php:35
‪TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateConstantEditorModuleFunctionController\init
‪init($pObj)
Definition: TypoScriptTemplateConstantEditorModuleFunctionController.php:104
‪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:3005
‪TYPO3\CMS\Backend\Utility\BackendUtility\getModuleData
‪static array getModuleData( $MOD_MENU, $CHANGED_SETTINGS, $modName, $type='', $dontValidateList='', $setDefaultList='')
Definition: BackendUtility.php:3259
‪TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateModuleController
Definition: TypoScriptTemplateModuleController.php:50
‪TYPO3\CMS\Core\Compatibility\PublicMethodDeprecationTrait
Definition: PublicMethodDeprecationTrait.php:68
‪TYPO3\CMS\Backend\Utility\BackendUtility
Definition: BackendUtility.php:72
‪TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateConstantEditorModuleFunctionController\$templateService
‪ExtendedTemplateService $templateService
Definition: TypoScriptTemplateConstantEditorModuleFunctionController.php:62
‪TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateConstantEditorModuleFunctionController\$function_key
‪string $function_key
Definition: TypoScriptTemplateConstantEditorModuleFunctionController.php:97
‪TYPO3\CMS\Fluid\View\StandaloneView
Definition: StandaloneView.php:32
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:29
‪TYPO3\CMS\Core\Compatibility\PublicPropertyDeprecationTrait
Definition: PublicPropertyDeprecationTrait.php:66
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Core\Page\PageRenderer\addJsInlineCode
‪addJsInlineCode($name, $block, $compress=true, $forceOnTop=false)
Definition: PageRenderer.php:1226
‪TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateConstantEditorModuleFunctionController\$deprecatedPublicMethods
‪array $deprecatedPublicMethods
Definition: TypoScriptTemplateConstantEditorModuleFunctionController.php:46
‪TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateConstantEditorModuleFunctionController\getLanguageService
‪LanguageService getLanguageService()
Definition: TypoScriptTemplateConstantEditorModuleFunctionController.php:246
‪TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateConstantEditorModuleFunctionController\getPageRenderer
‪PageRenderer getPageRenderer()
Definition: TypoScriptTemplateConstantEditorModuleFunctionController.php:254