TYPO3 CMS  TYPO3_8-7
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 
24 
29 {
33  public $pObj;
34 
39  protected $templateRow;
40 
44  protected $templateService;
45 
49  protected $constants;
50 
61  public function initialize_editor($pageId, $template_uid = 0)
62  {
63  $this->templateService = GeneralUtility::makeInstance(ExtendedTemplateService::class);
64  $this->templateService->init();
65 
66  // Get the row of the first VISIBLE template of the page. whereclause like the frontend.
67  $this->templateRow = $this->templateService->ext_getFirstTemplate($pageId, $template_uid);
68  // IF there was a template...
69  if (is_array($this->templateRow)) {
70  // Gets the rootLine
71  $rootlineUtility = GeneralUtility::makeInstance(RootlineUtility::class, $pageId);
72  $rootLine = $rootlineUtility->get();
73  // This generates the constants/config + hierarchy info for the template.
74  $this->templateService->runThroughTemplates($rootLine, $template_uid);
75  // The editable constants are returned in an array.
76  $this->constants = $this->templateService->generateConfig_constants();
77  // The returned constants are sorted in categories, that goes into the $tmpl->categories array
78  $this->templateService->ext_categorizeEditableConstants($this->constants);
79  // This array will contain key=[expanded constant name], value=line number in template. (after edit_divider, if any)
80  $this->templateService->ext_regObjectPositions($this->templateRow['constants']);
81  return true;
82  }
83  return false;
84  }
85 
91  public function getHelpConfig()
92  {
93  $result = [];
94  if ($this->templateService->helpConfig['description'] || $this->templateService->helpConfig['header']) {
95  $result['header'] = $this->templateService->helpConfig['header'];
96  $result['description'] = explode('//', $this->templateService->helpConfig['description']);
97  $result['bulletList'] = explode('//', $this->templateService->helpConfig['bulletlist']);
98  }
99  return $result;
100  }
101 
107  public function main()
108  {
109  $assigns = [];
110  $assigns['LLPrefix'] = 'LLL:EXT:tstemplate/Resources/Private/Language/locallang_ceditor.xlf:';
111  // Create extension template
112  $this->pObj->createTemplate($this->pObj->id);
113  // Checking for more than one template an if, set a menu...
114  $manyTemplatesMenu = $this->pObj->templateMenu();
115  $template_uid = 0;
116  if ($manyTemplatesMenu) {
117  $template_uid = $this->pObj->MOD_SETTINGS['templatesOnPage'];
118  }
119 
120  // initialize
121  $existTemplate = $this->initialize_editor($this->pObj->id, $template_uid);
122  if ($existTemplate) {
123  $assigns['siteTitle'] = trim($this->templateRow['sitetitle']);
124  $assigns['templateRecord'] = $this->templateRow;
125  if ($manyTemplatesMenu) {
126  $assigns['manyTemplatesMenu'] = $manyTemplatesMenu;
127  }
128 
129  $this->getPageRenderer();
130  $saveId = $this->templateRow['_ORIG_uid'] ?: $this->templateRow['uid'];
131  // Update template ?
132  if (GeneralUtility::_POST('_savedok')) {
133  $this->templateService->changed = 0;
134  $this->templateService->ext_procesInput(GeneralUtility::_POST(), [], $this->constants, $this->templateRow);
135  if ($this->templateService->changed) {
136  // Set the data to be saved
137  $recData = [];
138  $recData['sys_template'][$saveId]['constants'] = implode(LF, $this->templateService->raw);
139  // Create new tce-object
140  $tce = GeneralUtility::makeInstance(DataHandler::class);
141  $tce->start($recData, []);
142  $tce->process_datamap();
143  // Clear the cache (note: currently only admin-users can clear the cache in tce_main.php)
144  $tce->clear_cacheCmd('all');
145  // re-read the template ...
146  // re-read the constants as they have changed
147  $this->initialize_editor($this->pObj->id, $template_uid);
148  }
149  }
150  // 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.
151  $this->pObj->MOD_MENU['constant_editor_cat'] = $this->templateService->ext_getCategoryLabelArray();
152  $this->pObj->MOD_SETTINGS = BackendUtility::getModuleData($this->pObj->MOD_MENU, GeneralUtility::_GP('SET'), $this->pObj->MCONF['name']);
153  // Resetting the menu (stop)
154  $assigns['title'] = $this->pObj->linkWrapTemplateTitle($this->templateRow['title'], 'constants');
155  if (!empty($this->pObj->MOD_MENU['constant_editor_cat'])) {
156  $assigns['constantsMenu'] = BackendUtility::getDropdownMenu($this->pObj->id, 'SET[constant_editor_cat]', $this->pObj->MOD_SETTINGS['constant_editor_cat'], $this->pObj->MOD_MENU['constant_editor_cat']);
157  }
158  // Category and constant editor config:
159  $category = $this->pObj->MOD_SETTINGS['constant_editor_cat'];
160  $this->templateService->ext_getTSCE_config($category);
161 
162  $printFields = trim($this->templateService->ext_printFields($this->constants, $category));
163  foreach ($this->templateService->getInlineJavaScript() as $name => $inlineJavaScript) {
164  $this->pageRenderer->addJsInlineCode($name, $inlineJavaScript);
165  }
166 
167  if ($printFields) {
168  $assigns['printFields'] = $printFields;
169  }
170  $BE_USER_modOptions = BackendUtility::getModTSconfig(0, 'mod.' . $this->pObj->MCONF['name']);
171  if ($BE_USER_modOptions['properties']['constantEditor.']['example'] !== 'top') {
172  $assigns['helpConfig'] = $this->getHelpConfig();
173  }
174  // Rendering of the output via fluid
175  $view = GeneralUtility::makeInstance(StandaloneView::class);
176  $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName(
177  'EXT:tstemplate/Resources/Private/Templates/ConstantEditor.html'
178  ));
179  $view->assignMultiple($assigns);
180  $theOutput = $view->render();
181  } else {
182  $theOutput = $this->pObj->noTemplate(1);
183  }
184  return $theOutput;
185  }
186 }
static getModuleData( $MOD_MENU, $CHANGED_SETTINGS, $modName, $type='', $dontValidateList='', $setDefaultList='')
static getFileAbsFileName($filename, $_=null, $_2=null)
static makeInstance($className,... $constructorArguments)
static getDropdownMenu( $mainParams, $elementName, $currentValue, $menuItems, $script='', $addParams='')