TYPO3 CMS  TYPO3_7-6
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 
26 
37 {
41  public $pObj;
42 
53  public function initialize_editor($pageId, $template_uid = 0)
54  {
55  $templateService = GeneralUtility::makeInstance(ExtendedTemplateService::class);
56  $GLOBALS['tmpl'] = $templateService;
57 
58  // Do not log time-performance information
59  $templateService->tt_track = false;
60 
61  $templateService->init();
62  $templateService->ext_localGfxPrefix = ExtensionManagementUtility::extPath('tstemplate');
63  $templateService->ext_localWebGfxPrefix = ExtensionManagementUtility::extRelPath('tstemplate') . 'Resources/Public/';
64 
65  // Get the row of the first VISIBLE template of the page. whereclause like the frontend.
66  $GLOBALS['tplRow'] = $templateService->ext_getFirstTemplate($pageId, $template_uid);
67  // IF there was a template...
68  if (is_array($GLOBALS['tplRow'])) {
69  // Gets the rootLine
70  $sys_page = GeneralUtility::makeInstance(PageRepository::class);
71  $rootLine = $sys_page->getRootLine($pageId);
72  // This generates the constants/config + hierarchy info for the template.
73  $templateService->runThroughTemplates($rootLine, $template_uid);
74  // The editable constants are returned in an array.
75  $GLOBALS['theConstants'] = $templateService->generateConfig_constants();
76  // The returned constants are sorted in categories, that goes into the $tmpl->categories array
77  $templateService->ext_categorizeEditableConstants($GLOBALS['theConstants']);
78  // This array will contain key=[expanded constant name], value=line number in template. (after edit_divider, if any)
79  $templateService->ext_regObjectPositions($GLOBALS['tplRow']['constants']);
80  return true;
81  }
82  return false;
83  }
84 
91  public function displayExample($theOutput)
92  {
93  $templateService = $this->getExtendedTemplateService();
94  if ($templateService->helpConfig['imagetag'] || $templateService->helpConfig['description'] || $templateService->helpConfig['header']) {
95  $theOutput .= '<div style="padding-top: 30px;"></div>';
96  $theOutput .= '<div>' . htmlspecialchars($templateService->helpConfig['header'])
97  . '<div align="center">' . $templateService->helpConfig['imagetag'] . '</div><br>'
98  . ($templateService->helpConfig['description'] ? implode(explode('//', $templateService->helpConfig['description']), '<br>') . '<br>' : '')
99  . ($templateService->helpConfig['bulletlist'] ? '<ul><li>' . implode(explode('//', $templateService->helpConfig['bulletlist']), '<li>') . '</ul>' : '<br>')
100  . '</div>';
101  }
102  return $theOutput;
103  }
104 
110  public function main()
111  {
112  $lang = $this->getLanguageService();
113 
114  $lang->includeLLFile('EXT:tstemplate/Resources/Private/Language/locallang_ceditor.xlf');
115  $theOutput = '';
116  // Create extension template
117  $this->pObj->createTemplate($this->pObj->id);
118  // Checking for more than one template an if, set a menu...
119  $manyTemplatesMenu = $this->pObj->templateMenu();
120  $template_uid = 0;
121  if ($manyTemplatesMenu) {
122  $template_uid = $this->pObj->MOD_SETTINGS['templatesOnPage'];
123  }
124 
125  // initialize
126  $existTemplate = $this->initialize_editor($this->pObj->id, $template_uid);
127  if ($existTemplate) {
128  $templateService = $this->getExtendedTemplateService();
129  $tplRow = $this->getTemplateRow();
130  $theConstants = $this->getConstants();
131 
132  $this->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Tstemplate/ConstantEditor');
133  $saveId = $tplRow['_ORIG_uid'] ? $tplRow['_ORIG_uid'] : $tplRow['uid'];
134  // Update template ?
135  if (GeneralUtility::_POST('_savedok')) {
136  $templateService->changed = 0;
137  $templateService->ext_procesInput(GeneralUtility::_POST(), [], $theConstants, $tplRow);
138  if ($templateService->changed) {
139  // Set the data to be saved
140  $recData = [];
141  $recData['sys_template'][$saveId]['constants'] = implode($templateService->raw, LF);
142  // Create new tce-object
143  $tce = GeneralUtility::makeInstance(DataHandler::class);
144  $tce->stripslashes_values = false;
145  $tce->start($recData, []);
146  $tce->process_datamap();
147  // Clear the cache (note: currently only admin-users can clear the cache in tce_main.php)
148  $tce->clear_cacheCmd('all');
149  // re-read the template ...
150  $this->initialize_editor($this->pObj->id, $template_uid);
151  // re-read the constants as they have changed
152  $templateService = $this->getExtendedTemplateService();
153  $tplRow = $this->getTemplateRow();
154  $theConstants = $this->getConstants();
155  }
156  }
157  // 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.
158  $this->pObj->MOD_MENU['constant_editor_cat'] = $templateService->ext_getCategoryLabelArray();
159  $this->pObj->MOD_SETTINGS = BackendUtility::getModuleData($this->pObj->MOD_MENU, GeneralUtility::_GP('SET'), $this->pObj->MCONF['name']);
160  // Resetting the menu (stop)
161  $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
162  $content = $iconFactory->getIconForRecord('sys_template', $tplRow, Icon::SIZE_SMALL)->render() . '<strong>' . $this->pObj->linkWrapTemplateTitle($tplRow['title'], 'constants') . '</strong>' . (trim($tplRow['sitetitle']) ? htmlspecialchars(' (' . $tplRow['sitetitle'] . ')') : '');
163  $theOutput .= '<h2>' . $lang->getLL('editConstants', true) . '</h2><div>' . $content . '</div>';
164  if ($manyTemplatesMenu) {
165  $theOutput .= '<div>' . $manyTemplatesMenu . '</div>';
166  }
167  $theOutput .= '<div style="padding-top: 10px;"></div>';
168  if (!empty($this->pObj->MOD_MENU['constant_editor_cat'])) {
169  $menu = '<div class="form-inline form-inline-spaced">';
170  $menu .= BackendUtility::getDropdownMenu($this->pObj->id, 'SET[constant_editor_cat]', $this->pObj->MOD_SETTINGS['constant_editor_cat'], $this->pObj->MOD_MENU['constant_editor_cat']);
171  $menu .= '</div>';
172  $theOutput .= '<h3>' . $lang->getLL('category', true) . '</h3><div><span class="text-nowrap">' . $menu . '</span></div>';
173  } else {
174  $theOutput .= '<h3>' . $iconFactory->getIcon('status-dialog-notification', Icon::SIZE_SMALL)->render() . $lang->getLL('noConstants', true) . '</h3><div>' . $lang->getLL('noConstantsDescription', true) . '</div>';
175  }
176  $theOutput .= '<div style="padding-top: 15px;"></div>';
177  // Category and constant editor config:
178  $category = $this->pObj->MOD_SETTINGS['constant_editor_cat'];
179  $templateService->ext_getTSCE_config($category);
180 
181  $printFields = trim($templateService->ext_printFields($theConstants, $category));
182  if ($printFields) {
183  $theOutput .= '<div>' . $printFields . '</div>';
184  }
185  $BE_USER_modOptions = BackendUtility::getModTSconfig(0, 'mod.' . $this->pObj->MCONF['name']);
186  if ($BE_USER_modOptions['properties']['constantEditor.']['example'] != 'top') {
187  $theOutput = $this->displayExample($theOutput);
188  }
189  } else {
190  $theOutput .= $this->pObj->noTemplate(1);
191  }
192  return $theOutput;
193  }
194 
198  protected function getExtendedTemplateService()
199  {
200  return $GLOBALS['tmpl'];
201  }
202 
206  protected function getTemplateRow()
207  {
208  return $GLOBALS['tplRow'];
209  }
210 
214  protected function getConstants()
215  {
216  return $GLOBALS['theConstants'];
217  }
218 }
static getModuleData($MOD_MENU, $CHANGED_SETTINGS, $modName, $type='', $dontValidateList='', $setDefaultList='')
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
static getDropdownMenu($mainParams, $elementName, $currentValue, $menuItems, $script='', $addParams='')