2 namespace TYPO3\CMS\Tstemplate\Controller
;
5 * This file is part of the TYPO3 CMS project.
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.
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
14 * The TYPO3 project - inspiring people to share!
17 use TYPO3\CMS\Backend\Module\AbstractFunctionModule
;
18 use TYPO3\CMS\Backend\Utility\BackendUtility
;
19 use TYPO3\CMS\Backend\Utility\IconUtility
;
20 use TYPO3\CMS\Core\DataHandling\DataHandler
;
21 use TYPO3\CMS\Core\TypoScript\ExtendedTemplateService
;
22 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility
;
23 use TYPO3\CMS\Core\Utility\GeneralUtility
;
24 use TYPO3\CMS\Core\Utility\MathUtility
;
25 use TYPO3\CMS\Frontend\Page\PageRepository
;
28 * TypoScript Constant editor
32 * $GLOBALS['TYPO3_CONF_VARS']['MODS']['web_ts']['onlineResourceDir'] = 'fileadmin/fonts/';
33 * // This is the path (must be in "fileadmin/" !!) where the web_ts/constant-editor submodule fetches online resources.
34 * Put fonts (ttf) and standard images here!
36 class TypoScriptTemplateConstantEditorModuleFunctionController
extends AbstractFunctionModule
{
39 * @var TypoScriptTemplateModuleController
46 * Initializes the module.
47 * Done in this function because we may need to re-initialize if data is submitted!
50 * @param int $template_uid
53 public function initialize_editor($pageId, $template_uid = 0) {
54 $templateService = GeneralUtility
::makeInstance(ExtendedTemplateService
::class);
55 $GLOBALS['tmpl'] = $templateService;
57 // Do not log time-performance information
58 $templateService->tt_track
= FALSE;
60 $templateService->init();
61 $templateService->ext_localGfxPrefix
= ExtensionManagementUtility
::extPath('tstemplate');
62 $templateService->ext_localWebGfxPrefix
= ExtensionManagementUtility
::extRelPath('tstemplate') . 'Resources/Public/';
64 // Get the row of the first VISIBLE template of the page. whereclause like the frontend.
65 $GLOBALS['tplRow'] = $templateService->ext_getFirstTemplate($pageId, $template_uid);
66 // IF there was a template...
67 if (is_array($GLOBALS['tplRow'])) {
69 $sys_page = GeneralUtility
::makeInstance(PageRepository
::class);
70 $rootLine = $sys_page->getRootLine($pageId);
71 // This generates the constants/config + hierarchy info for the template.
72 $templateService->runThroughTemplates($rootLine, $template_uid);
73 // The editable constants are returned in an array.
74 $GLOBALS['theConstants'] = $templateService->generateConfig_constants();
75 // The returned constants are sorted in categories, that goes into the $tmpl->categories array
76 $templateService->ext_categorizeEditableConstants($GLOBALS['theConstants']);
77 // This array will contain key=[expanded constant name], value=line number in template. (after edit_divider, if any)
78 $templateService->ext_regObjectPositions($GLOBALS['tplRow']['constants']);
87 * @param string $theOutput
90 public function displayExample($theOutput) {
91 $templateService = $this->getExtendedTemplateService();
92 if ($templateService->helpConfig
['imagetag'] ||
$templateService->helpConfig
['description'] ||
$templateService->helpConfig
['header']) {
93 $theOutput .= $this->pObj
->doc
->spacer(30);
94 $theOutput .= $this->pObj
->doc
->section($templateService->helpConfig
['header'], '<div align="center">' . $templateService->helpConfig
['imagetag'] . '</div><BR>' . ($templateService->helpConfig
['description'] ?
implode(explode('//', $templateService->helpConfig
['description']), '<BR>') . '<BR>' : '') . ($templateService->helpConfig
['bulletlist'] ?
'<ul><li>' . implode(explode('//', $templateService->helpConfig
['bulletlist']), '<li>') . '</ul>' : '<BR>'));
104 public function main() {
105 $lang = $this->getLanguageService();
107 $lang->includeLLFile('EXT:tstemplate/Resources/Private/Language/locallang_ceditor.xlf');
109 // Create extension template
110 $this->pObj
->createTemplate($this->pObj
->id
);
111 // Checking for more than one template an if, set a menu...
112 $manyTemplatesMenu = $this->pObj
->templateMenu();
114 if ($manyTemplatesMenu) {
115 $template_uid = $this->pObj
->MOD_SETTINGS
['templatesOnPage'];
119 $existTemplate = $this->initialize_editor($this->pObj
->id
, $template_uid);
120 if ($existTemplate) {
121 $templateService = $this->getExtendedTemplateService();
122 $tplRow = $this->getTemplateRow();
123 $theConstants = $this->getConstants();
125 $this->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Tstemplate/ConstantEditor');
126 $saveId = $tplRow['_ORIG_uid'] ?
$tplRow['_ORIG_uid'] : $tplRow['uid'];
128 if (GeneralUtility
::_POST('submit') ) {
129 $templateService->changed
= 0;
130 $templateService->ext_procesInput(GeneralUtility
::_POST(), array(), $theConstants, $tplRow);
131 if ($templateService->changed
) {
132 // Set the data to be saved
134 $recData['sys_template'][$saveId]['constants'] = implode($templateService->raw
, LF
);
135 // Create new tce-object
136 $tce = GeneralUtility
::makeInstance(DataHandler
::class);
137 $tce->stripslashes_values
= FALSE;
138 $tce->start($recData, array());
139 $tce->process_datamap();
140 // Clear the cache (note: currently only admin-users can clear the cache in tce_main.php)
141 $tce->clear_cacheCmd('all');
142 // re-read the template ...
143 $this->initialize_editor($this->pObj
->id
, $template_uid);
144 // re-read the constants as they have changed
145 $theConstants = $this->getConstants();
148 // 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.
149 $this->pObj
->MOD_MENU
['constant_editor_cat'] = $templateService->ext_getCategoryLabelArray();
150 $this->pObj
->MOD_SETTINGS
= BackendUtility
::getModuleData($this->pObj
->MOD_MENU
, GeneralUtility
::_GP('SET'), $this->pObj
->MCONF
['name']);
151 // Resetting the menu (stop)
152 $content = IconUtility
::getSpriteIconForRecord('sys_template', $tplRow) . '<strong>' . $this->pObj
->linkWrapTemplateTitle($tplRow['title'], 'constants') . '</strong>' . htmlspecialchars((trim($tplRow['sitetitle']) ?
' (' . $tplRow['sitetitle'] . ')' : ''));
153 $theOutput .= $this->pObj
->doc
->section($lang->getLL('editConstants', TRUE), $content, FALSE, TRUE);
154 if ($manyTemplatesMenu) {
155 $theOutput .= $this->pObj
->doc
->section('', $manyTemplatesMenu);
157 $theOutput .= $this->pObj
->doc
->spacer(10);
158 if (!empty($this->pObj
->MOD_MENU
['constant_editor_cat'])) {
159 $menu = '<div class="form-inline form-inline-spaced">';
160 $menu .= BackendUtility
::getDropdownMenu($this->pObj
->id
, 'SET[constant_editor_cat]', $this->pObj
->MOD_SETTINGS
['constant_editor_cat'], $this->pObj
->MOD_MENU
['constant_editor_cat']);
162 $theOutput .= $this->pObj
->doc
->section($lang->getLL('category', TRUE), '<span class="text-nowrap">' . $menu . '</span>', FALSE);
164 $theOutput .= $this->pObj
->doc
->section($lang->getLL('noConstants', TRUE), $lang->getLL('noConstantsDescription', TRUE), FALSE, FALSE, 1);
166 $theOutput .= $this->pObj
->doc
->spacer(15);
167 // Category and constant editor config:
168 $category = $this->pObj
->MOD_SETTINGS
['constant_editor_cat'];
169 $templateService->ext_getTSCE_config($category);
171 $printFields = trim($templateService->ext_printFields($theConstants, $category));
173 $theOutput .= $this->pObj
->doc
->section('', $printFields);
175 $BE_USER_modOptions = BackendUtility
::getModTSconfig(0, 'mod.' . $this->pObj
->MCONF
['name']);
176 if ($BE_USER_modOptions['properties']['constantEditor.']['example'] != 'top') {
177 $theOutput = $this->displayExample($theOutput);
180 $theOutput .= $this->pObj
->noTemplate(1);
186 * @return ExtendedTemplateService
188 protected function getExtendedTemplateService() {
189 return $GLOBALS['tmpl'];
195 protected function getTemplateRow() {
196 return $GLOBALS['tplRow'];
202 protected function getConstants() {
203 return $GLOBALS['theConstants'];