[TASK] Remove GLOBAL variables from web_ts 26/50626/3
authorBenni Mack <benni@typo3.org>
Sun, 13 Nov 2016 00:09:08 +0000 (01:09 +0100)
committerStefan Neufeind <typo3.neufeind@speedpartner.de>
Sun, 13 Nov 2016 10:23:11 +0000 (11:23 +0100)
The system extension "tstemplate" still uses a
lot of $GLOBAL objects which are only used within
the classes itself.

These are solely related to the "web_ts" (Web => Template)
module.

The code is refactored by using protected object members.

Resolves: #78675
Releases: master
Change-Id: Ic9bbcd9dfd4d9d9f9d976bead46c5d03d887aec6
Reviewed-on: https://review.typo3.org/50626
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein <markus.klein@typo3.org>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
Tested-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
typo3/sysext/tstemplate/Classes/Controller/TemplateAnalyzerModuleFunctionController.php
typo3/sysext/tstemplate/Classes/Controller/TypoScriptTemplateConstantEditorModuleFunctionController.php
typo3/sysext/tstemplate/Classes/Controller/TypoScriptTemplateInformationModuleFunctionController.php
typo3/sysext/tstemplate/Classes/Controller/TypoScriptTemplateModuleController.php
typo3/sysext/tstemplate/Classes/Controller/TypoScriptTemplateObjectBrowserModuleFunctionController.php

index cb2cc3e..6b044fa 100644 (file)
@@ -36,6 +36,17 @@ class TemplateAnalyzerModuleFunctionController extends AbstractFunctionModule
      */
     protected $localLanguageFilePath;
 
+    /**
+     * The currently selected sys_template record
+     * @var array
+     */
+    protected $templateRow;
+
+    /**
+     * @var ExtendedTemplateService
+     */
+    protected $templateService;
+
     /**
      * Init
      *
@@ -77,20 +88,19 @@ class TemplateAnalyzerModuleFunctionController extends AbstractFunctionModule
     public function initialize_editor($pageId, $templateUid = 0)
     {
         // Initializes the module. Done in this function because we may need to re-initialize if data is submitted!
-        $templateService = GeneralUtility::makeInstance(ExtendedTemplateService::class);
-        $GLOBALS['tmpl'] = $templateService;
-        $templateService->init();
+        $this->templateService = GeneralUtility::makeInstance(ExtendedTemplateService::class);
+        $this->templateService->init();
 
         // Gets the rootLine
         $sys_page = GeneralUtility::makeInstance(PageRepository::class);
-        $GLOBALS['rootLine'] = $sys_page->getRootLine($pageId);
+        $rootLine = $sys_page->getRootLine($pageId);
 
         // This generates the constants/config + hierarchy info for the template.
-        $templateService->runThroughTemplates($GLOBALS['rootLine'], $templateUid);
+        $this->templateService->runThroughTemplates($rootLine, $templateUid);
 
         // Get the row of the first VISIBLE template of the page. whereclause like the frontend.
-        $GLOBALS['tplRow'] = $templateService->ext_getFirstTemplate($pageId, $templateUid);
-        return is_array($GLOBALS['tplRow']);
+        $this->templateRow = $this->templateService->ext_getFirstTemplate($pageId, $templateUid);
+        return is_array($this->templateRow);
     }
 
     /**
@@ -113,17 +123,16 @@ class TemplateAnalyzerModuleFunctionController extends AbstractFunctionModule
 
         $assigns['existTemplate'] = $this->initialize_editor($this->pObj->id, $template_uid);
         if ($assigns['existTemplate']) {
-            $assigns['siteTitle'] = trim($GLOBALS['tplRow']['sitetitle']);
-            $assigns['templateRecord'] = $GLOBALS['tplRow'];
-            $assigns['linkWrappedTemplateTitle'] = $this->pObj->linkWrapTemplateTitle($GLOBALS['tplRow']['title']);
+            $assigns['siteTitle'] = trim($this->templateRow['sitetitle']);
+            $assigns['templateRecord'] = $this->templateRow;
+            $assigns['linkWrappedTemplateTitle'] = $this->pObj->linkWrapTemplateTitle($this->templateRow['title']);
         }
 
-        $templateService = $GLOBALS['tmpl'];
-        $templateService->clearList_const_temp = array_flip($templateService->clearList_const);
-        $templateService->clearList_setup_temp = array_flip($templateService->clearList_setup);
-        $pointer = count($templateService->hierarchyInfo);
-        $hierarchyInfo = $templateService->ext_process_hierarchyInfo([], $pointer);
-        $assigns['hierarchy'] = implode(array_reverse($templateService->ext_getTemplateHierarchyArr(
+        $this->templateService->clearList_const_temp = array_flip($this->templateService->clearList_const);
+        $this->templateService->clearList_setup_temp = array_flip($this->templateService->clearList_setup);
+        $pointer = count($this->templateService->hierarchyInfo);
+        $hierarchyInfo = $this->templateService->ext_process_hierarchyInfo([], $pointer);
+        $assigns['hierarchy'] = implode(array_reverse($this->templateService->ext_getTemplateHierarchyArr(
             $hierarchyInfo,
             '',
             [],
@@ -131,7 +140,7 @@ class TemplateAnalyzerModuleFunctionController extends AbstractFunctionModule
         )), '');
 
         $urlParameters = [
-            'id' => $GLOBALS['SOBE']->id,
+            'id' => $this->pObj->id,
             'template' => 'all'
         ];
         $assigns['moduleLink'] = BackendUtility::getModuleUrl('web_ts', $urlParameters);
@@ -172,15 +181,15 @@ class TemplateAnalyzerModuleFunctionController extends AbstractFunctionModule
         }
 
         if ($template) {
-            $templateService->ext_lineNumberOffset = 0;
-            $templateService->ext_lineNumberOffset_mode = 'const';
+            $this->templateService->ext_lineNumberOffset = 0;
+            $this->templateService->ext_lineNumberOffset_mode = 'const';
             $assigns['constants'] = [];
-            foreach ($templateService->constants as $key => $val) {
-                $currentTemplateId = $templateService->hierarchyInfo[$key]['templateID'];
+            foreach ($this->templateService->constants as $key => $val) {
+                $currentTemplateId = $this->templateService->hierarchyInfo[$key]['templateID'];
                 if ($currentTemplateId == $template || $template === 'all') {
                     $assigns['constants'][] = [
-                        'title' => $templateService->hierarchyInfo[$key]['title'],
-                        'content' => $templateService->ext_outputTS(
+                        'title' => $this->templateService->hierarchyInfo[$key]['title'],
+                        'content' => $this->templateService->ext_outputTS(
                             [$val],
                             $this->pObj->MOD_SETTINGS['ts_analyzer_checkLinenum'],
                             $this->pObj->MOD_SETTINGS['ts_analyzer_checkComments'],
@@ -193,19 +202,19 @@ class TemplateAnalyzerModuleFunctionController extends AbstractFunctionModule
                         break;
                     }
                 }
-                $templateService->ext_lineNumberOffset += count(explode(LF, $val)) + 1;
+                $this->templateService->ext_lineNumberOffset += count(explode(LF, $val)) + 1;
             }
 
             // Output Setup
-            $templateService->ext_lineNumberOffset = 0;
-            $templateService->ext_lineNumberOffset_mode = 'setup';
+            $this->templateService->ext_lineNumberOffset = 0;
+            $this->templateService->ext_lineNumberOffset_mode = 'setup';
             $assigns['setups'] = [];
-            foreach ($templateService->config as $key => $val) {
-                $currentTemplateId = $templateService->hierarchyInfo[$key]['templateID'];
+            foreach ($this->templateService->config as $key => $val) {
+                $currentTemplateId = $this->templateService->hierarchyInfo[$key]['templateID'];
                 if ($currentTemplateId == $template || $template === 'all') {
                     $assigns['setups'][] = [
-                        'title' => $templateService->hierarchyInfo[$key]['title'],
-                        'content' => $templateService->ext_outputTS(
+                        'title' => $this->templateService->hierarchyInfo[$key]['title'],
+                        'content' => $this->templateService->ext_outputTS(
                             [$val],
                             $this->pObj->MOD_SETTINGS['ts_analyzer_checkLinenum'],
                             $this->pObj->MOD_SETTINGS['ts_analyzer_checkComments'],
@@ -218,7 +227,7 @@ class TemplateAnalyzerModuleFunctionController extends AbstractFunctionModule
                         break;
                     }
                 }
-                $templateService->ext_lineNumberOffset += count(explode(LF, $val)) + 1;
+                $this->templateService->ext_lineNumberOffset += count(explode(LF, $val)) + 1;
             }
         }
 
index dcc53b9..05b4583 100644 (file)
@@ -32,6 +32,22 @@ class TypoScriptTemplateConstantEditorModuleFunctionController extends AbstractF
      */
     public $pObj;
 
+    /**
+     * The currently selected sys_template record
+     * @var array
+     */
+    protected $templateRow;
+
+    /**
+     * @var ExtendedTemplateService
+     */
+    protected $templateService;
+
+    /**
+     * @var array
+     */
+    protected $constants;
+
     /**
      * Initialize editor
      *
@@ -44,25 +60,24 @@ class TypoScriptTemplateConstantEditorModuleFunctionController extends AbstractF
      */
     public function initialize_editor($pageId, $template_uid = 0)
     {
-        $templateService = GeneralUtility::makeInstance(ExtendedTemplateService::class);
-        $GLOBALS['tmpl'] = $templateService;
-        $templateService->init();
+        $this->templateService = GeneralUtility::makeInstance(ExtendedTemplateService::class);
+        $this->templateService->init();
 
         // Get the row of the first VISIBLE template of the page. whereclause like the frontend.
-        $GLOBALS['tplRow'] = $templateService->ext_getFirstTemplate($pageId, $template_uid);
+        $this->templateRow = $this->templateService->ext_getFirstTemplate($pageId, $template_uid);
         // IF there was a template...
-        if (is_array($GLOBALS['tplRow'])) {
+        if (is_array($this->templateRow)) {
             // Gets the rootLine
             $sys_page = GeneralUtility::makeInstance(PageRepository::class);
             $rootLine = $sys_page->getRootLine($pageId);
             // This generates the constants/config + hierarchy info for the template.
-            $templateService->runThroughTemplates($rootLine, $template_uid);
+            $this->templateService->runThroughTemplates($rootLine, $template_uid);
             // The editable constants are returned in an array.
-            $GLOBALS['theConstants'] = $templateService->generateConfig_constants();
+            $this->constants = $this->templateService->generateConfig_constants();
             // The returned constants are sorted in categories, that goes into the $tmpl->categories array
-            $templateService->ext_categorizeEditableConstants($GLOBALS['theConstants']);
+            $this->templateService->ext_categorizeEditableConstants($this->constants);
             // This array will contain key=[expanded constant name], value=line number in template. (after edit_divider, if any)
-            $templateService->ext_regObjectPositions($GLOBALS['tplRow']['constants']);
+            $this->templateService->ext_regObjectPositions($this->templateRow['constants']);
             return true;
         }
         return false;
@@ -76,11 +91,10 @@ class TypoScriptTemplateConstantEditorModuleFunctionController extends AbstractF
     public function getHelpConfig()
     {
         $result = [];
-        $templateService = $this->getExtendedTemplateService();
-        if ($templateService->helpConfig['description'] || $templateService->helpConfig['header']) {
-            $result['header'] = $templateService->helpConfig['header'];
-            $result['description'] = explode('//', $templateService->helpConfig['description']);
-            $result['bulletList'] = explode('//', $templateService->helpConfig['bulletlist']);
+        if ($this->templateService->helpConfig['description'] || $this->templateService->helpConfig['header']) {
+            $result['header'] = $this->templateService->helpConfig['header'];
+            $result['description'] = explode('//', $this->templateService->helpConfig['description']);
+            $result['bulletList'] = explode('//', $this->templateService->helpConfig['bulletlist']);
         }
         return $result;
     }
@@ -106,25 +120,22 @@ class TypoScriptTemplateConstantEditorModuleFunctionController extends AbstractF
         // initialize
         $existTemplate = $this->initialize_editor($this->pObj->id, $template_uid);
         if ($existTemplate) {
-            $templateService = $this->getExtendedTemplateService();
-            $tplRow = $this->getTemplateRow();
-            $theConstants = $this->getConstants();
-            $assigns['siteTitle'] = trim($tplRow['sitetitle']);
-            $assigns['templateRecord'] = $tplRow;
+            $assigns['siteTitle'] = trim($this->templateRow['sitetitle']);
+            $assigns['templateRecord'] = $this->templateRow;
             if ($manyTemplatesMenu) {
                 $assigns['manyTemplatesMenu'] = $manyTemplatesMenu;
             }
 
             $this->getPageRenderer();
-            $saveId = $tplRow['_ORIG_uid'] ? $tplRow['_ORIG_uid'] : $tplRow['uid'];
+            $saveId = $this->templateRow['_ORIG_uid'] ?: $this->templateRow['uid'];
             // Update template ?
             if (GeneralUtility::_POST('_savedok')) {
-                $templateService->changed = 0;
-                $templateService->ext_procesInput(GeneralUtility::_POST(), [], $theConstants, $tplRow);
-                if ($templateService->changed) {
+                $this->templateService->changed = 0;
+                $this->templateService->ext_procesInput(GeneralUtility::_POST(), [], $this->constants, $this->templateRow);
+                if ($this->templateService->changed) {
                     // Set the data to be saved
                     $recData = [];
-                    $recData['sys_template'][$saveId]['constants'] = implode($templateService->raw, LF);
+                    $recData['sys_template'][$saveId]['constants'] = implode($this->templateService->raw, LF);
                     // Create new  tce-object
                     $tce = GeneralUtility::makeInstance(DataHandler::class);
                     $tce->start($recData, []);
@@ -132,27 +143,24 @@ class TypoScriptTemplateConstantEditorModuleFunctionController extends AbstractF
                     // Clear the cache (note: currently only admin-users can clear the cache in tce_main.php)
                     $tce->clear_cacheCmd('all');
                     // re-read the template ...
-                    $this->initialize_editor($this->pObj->id, $template_uid);
                     // re-read the constants as they have changed
-                    $templateService = $this->getExtendedTemplateService();
-                    $tplRow = $this->getTemplateRow();
-                    $theConstants = $this->getConstants();
+                    $this->initialize_editor($this->pObj->id, $template_uid);
                 }
             }
             // 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.
-            $this->pObj->MOD_MENU['constant_editor_cat'] = $templateService->ext_getCategoryLabelArray();
+            $this->pObj->MOD_MENU['constant_editor_cat'] = $this->templateService->ext_getCategoryLabelArray();
             $this->pObj->MOD_SETTINGS = BackendUtility::getModuleData($this->pObj->MOD_MENU, GeneralUtility::_GP('SET'), $this->pObj->MCONF['name']);
             // Resetting the menu (stop)
-            $assigns['title'] = $this->pObj->linkWrapTemplateTitle($tplRow['title'], 'constants');
+            $assigns['title'] = $this->pObj->linkWrapTemplateTitle($this->templateRow['title'], 'constants');
             if (!empty($this->pObj->MOD_MENU['constant_editor_cat'])) {
                 $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']);
             }
             // Category and constant editor config:
             $category = $this->pObj->MOD_SETTINGS['constant_editor_cat'];
-            $templateService->ext_getTSCE_config($category);
+            $this->templateService->ext_getTSCE_config($category);
 
-            $printFields = trim($templateService->ext_printFields($theConstants, $category));
-            foreach ($templateService->getInlineJavaScript() as $name => $inlineJavaScript) {
+            $printFields = trim($this->templateService->ext_printFields($this->constants, $category));
+            foreach ($this->templateService->getInlineJavaScript() as $name => $inlineJavaScript) {
                 $this->pageRenderer->addJsInlineCode($name, $inlineJavaScript);
             }
 
@@ -175,28 +183,4 @@ class TypoScriptTemplateConstantEditorModuleFunctionController extends AbstractF
         }
         return $theOutput;
     }
-
-    /**
-     * @return ExtendedTemplateService
-     */
-    protected function getExtendedTemplateService()
-    {
-        return $GLOBALS['tmpl'];
-    }
-
-    /**
-     * @return array
-     */
-    protected function getTemplateRow()
-    {
-        return $GLOBALS['tplRow'];
-    }
-
-    /**
-     * @return array
-     */
-    protected function getConstants()
-    {
-        return $GLOBALS['theConstants'];
-    }
 }
index c30e203..66fe71f 100644 (file)
@@ -41,6 +41,17 @@ class TypoScriptTemplateInformationModuleFunctionController extends AbstractFunc
      */
     public $pObj;
 
+    /**
+     * The currently selected sys_template record
+     * @var array
+     */
+    protected $templateRow;
+
+    /**
+     * @var ExtendedTemplateService
+     */
+    protected $templateService;
+
     /**
      * Gets the data for a row of a HTML table in the fluid template
      *
@@ -81,8 +92,8 @@ class TypoScriptTemplateInformationModuleFunctionController extends AbstractFunc
     }
 
     /**
-     * Create an instance of \TYPO3\CMS\Core\TypoScript\ExtendedTemplateService in
-     * $GLOBALS['tmpl'] and looks for the first (visible) template
+     * Create an instance of \TYPO3\CMS\Core\TypoScript\ExtendedTemplateService
+     * and looks for the first (visible) template
      * record. If $template_uid was given and greater than zero, this record will be checked.
      *
      * Initializes the module. Done in this function because we may need to re-initialize if data is submitted!
@@ -93,15 +104,13 @@ class TypoScriptTemplateInformationModuleFunctionController extends AbstractFunc
      */
     public function initialize_editor($pageId, $template_uid = 0)
     {
-        /** @var ExtendedTemplateService $tmpl */
-        $tmpl = GeneralUtility::makeInstance(ExtendedTemplateService::class);
-        $GLOBALS['tmpl'] = $tmpl;
-        $tmpl->init();
+        $this->templateService = GeneralUtility::makeInstance(ExtendedTemplateService::class);
+        $this->templateService->init();
 
         // Get the row of the first VISIBLE template of the page. where clause like the frontend.
-        $GLOBALS['tplRow'] = $tmpl->ext_getFirstTemplate($pageId, $template_uid);
-        if (is_array($GLOBALS['tplRow'])) {
-            $GLOBALS['tplRow'] = $this->processTemplateRowAfterLoading($GLOBALS['tplRow']);
+        $this->templateRow = $this->templateService->ext_getFirstTemplate($pageId, $template_uid);
+        if (is_array($this->templateRow)) {
+            $this->templateRow = $this->processTemplateRowAfterLoading($this->templateRow);
             return true;
         }
         return false;
@@ -163,10 +172,9 @@ class TypoScriptTemplateInformationModuleFunctionController extends AbstractFunc
         }
         // Initialize
         $existTemplate = $this->initialize_editor($this->pObj->id, $template_uid);
-        $tplRow = $GLOBALS['tplRow'];
         $saveId = 0;
         if ($existTemplate) {
-            $saveId = $tplRow['_ORIG_uid'] ? $tplRow['_ORIG_uid'] : $tplRow['uid'];
+            $saveId = $this->templateRow['_ORIG_uid'] ? : $this->templateRow['uid'];
         }
         // Create extension template
         $newId = $this->pObj->createTemplate($this->pObj->id, $saveId);
@@ -219,7 +227,6 @@ class TypoScriptTemplateInformationModuleFunctionController extends AbstractFunc
                     $this->tce_processed = true;
                     // re-read the template ...
                     $this->initialize_editor($this->pObj->id, $template_uid);
-                    $tplRow = $GLOBALS['tplRow'];
                     // reload template menu
                     $manyTemplatesMenu = $this->pObj->templateMenu();
                 }
@@ -237,9 +244,9 @@ class TypoScriptTemplateInformationModuleFunctionController extends AbstractFunc
                     }
                 }
             }
-            $assigns['title'] = trim($tplRow['title']);
-            $assigns['siteTitle'] = trim($tplRow['sitetitle']);
-            $assigns['templateRecord'] = $tplRow;
+            $assigns['title'] = trim($this->templateRow['title']);
+            $assigns['siteTitle'] = trim($this->templateRow['sitetitle']);
+            $assigns['templateRecord'] = $this->templateRow;
             if ($manyTemplatesMenu) {
                 $assigns['manyTemplatesMenu'] = $manyTemplatesMenu;
             }
@@ -251,29 +258,29 @@ class TypoScriptTemplateInformationModuleFunctionController extends AbstractFunc
             }
             if (isset($e['constants'])) {
                 $assigns['showConstantsEditor'] = true;
-                $assigns['constants'] = $tplRow['constants'];
+                $assigns['constants'] = $this->templateRow['constants'];
                 $assigns['constantsLabel'] = BackendUtility::getFuncCheck($this->pObj->id, 'SET[includeTypoScriptFileContent]', $this->pObj->MOD_SETTINGS['includeTypoScriptFileContent'], '', '&e[constants]=1', 'id="checkIncludeTypoScriptFileContent"');
             }
             if (isset($e['config'])) {
                 $assigns['showConfigEditor'] = true;
-                $assigns['config'] = $tplRow['config'];
+                $assigns['config'] = $this->templateRow['config'];
                 $assigns['configLabel'] = BackendUtility::getFuncCheck($this->pObj->id, 'SET[includeTypoScriptFileContent]', $this->pObj->MOD_SETTINGS['includeTypoScriptFileContent'], '', '&e[config]=1', 'id="checkIncludeTypoScriptFileContent"');
             }
 
             // Processing:
             $tableRows = [];
-            $tableRows[] = $this->tableRowData($lang->getLL('title'), htmlspecialchars($tplRow['title']), 'title', $tplRow['uid']);
-            $tableRows[] = $this->tableRowData($lang->getLL('sitetitle'), htmlspecialchars($tplRow['sitetitle']), 'sitetitle', $tplRow['uid']);
-            $tableRows[] = $this->tableRowData($lang->getLL('description'), nl2br(htmlspecialchars($tplRow['description'])), 'description', $tplRow['uid']);
-            $tableRows[] = $this->tableRowData($lang->getLL('constants'), sprintf($lang->getLL('editToView'), trim($tplRow['constants']) ? count(explode(LF, $tplRow['constants'])) : 0), 'constants', $tplRow['uid']);
-            $tableRows[] = $this->tableRowData($lang->getLL('setup'), sprintf($lang->getLL('editToView'), trim($tplRow['config']) ? count(explode(LF, $tplRow['config'])) : 0), 'config', $tplRow['uid']);
+            $tableRows[] = $this->tableRowData($lang->getLL('title'), htmlspecialchars($this->templateRow['title']), 'title', $this->templateRow['uid']);
+            $tableRows[] = $this->tableRowData($lang->getLL('sitetitle'), htmlspecialchars($this->templateRow['sitetitle']), 'sitetitle', $this->templateRow['uid']);
+            $tableRows[] = $this->tableRowData($lang->getLL('description'), nl2br(htmlspecialchars($this->templateRow['description'])), 'description', $this->templateRow['uid']);
+            $tableRows[] = $this->tableRowData($lang->getLL('constants'), sprintf($lang->getLL('editToView'), trim($this->templateRow['constants']) ? count(explode(LF, $this->templateRow['constants'])) : 0), 'constants', $this->templateRow['uid']);
+            $tableRows[] = $this->tableRowData($lang->getLL('setup'), sprintf($lang->getLL('editToView'), trim($this->templateRow['config']) ? count(explode(LF, $this->templateRow['config'])) : 0), 'config', $this->templateRow['uid']);
             $assigns['tableRows'] = $tableRows;
 
             // Edit all icon:
             $urlParameters = [
                 'edit' => [
                     'sys_template' => [
-                        $tplRow['uid'] => 'edit'
+                        $this->templateRow['uid'] => 'edit'
                     ]
                 ],
                 'createExtension' => 0,
@@ -297,7 +304,7 @@ class TypoScriptTemplateInformationModuleFunctionController extends AbstractFunc
                         'theOutput' => &$theOutput,
                         'POST' => $POST,
                         'e' => $e,
-                        'tplRow' => $tplRow,
+                        'tplRow' => $this->templateRow,
                         'numberOfRows' => $numberOfRows
                     ];
                     foreach ($postOutputProcessingHook as $hookFunction) {
index 84a3b31..eb05c6c 100644 (file)
@@ -100,6 +100,11 @@ class TypoScriptTemplateModuleController extends BaseScriptClass
      */
     protected $moduleTemplate;
 
+    /**
+     * @var ExtendedTemplateService
+     */
+    protected $templateService;
+
     /**
      * Constructor
      */
@@ -443,11 +448,8 @@ class TypoScriptTemplateModuleController extends BaseScriptClass
      */
     public function noTemplate($newStandardTemplate = 0)
     {
-        // Defined global here!
-        /** @var ExtendedTemplateService $tmpl */
-        $tmpl = GeneralUtility::makeInstance(ExtendedTemplateService::class);
-        $GLOBALS['tmpl'] = $tmpl;
-        $tmpl->init();
+        $this->templateService = GeneralUtility::makeInstance(ExtendedTemplateService::class);
+        $this->templateService->init();
 
         $moduleContent['state'] = InfoboxViewHelper::STATE_INFO;
 
@@ -475,7 +477,7 @@ class TypoScriptTemplateModuleController extends BaseScriptClass
             $moduleContent['selector'] = $selector;
         }
         // Go to previous Page with Template...
-        $previousPage = $tmpl->ext_prevPageWithTemplate($this->id, $this->perms_clause);
+        $previousPage = $this->templateService->ext_prevPageWithTemplate($this->id, $this->perms_clause);
         if ($previousPage) {
             $urlParameters = [
                 'id' => $previousPage['uid']
@@ -495,12 +497,10 @@ class TypoScriptTemplateModuleController extends BaseScriptClass
      */
     public function templateMenu()
     {
-        /** @var ExtendedTemplateService $tmpl */
-        $tmpl = GeneralUtility::makeInstance(ExtendedTemplateService::class);
-        $GLOBALS['tmpl'] = $tmpl;
-        $tmpl->init();
+        $this->templateService = GeneralUtility::makeInstance(ExtendedTemplateService::class);
+        $this->templateService->init();
 
-        $all = $tmpl->ext_getAllTemplates($this->id);
+        $all = $this->templateService->ext_getAllTemplates($this->id);
         if (count($all) > 1) {
             $this->MOD_MENU['templatesOnPage'] = [];
             foreach ($all as $d) {
index ba391d8..db2b456 100644 (file)
@@ -41,6 +41,17 @@ class TypoScriptTemplateObjectBrowserModuleFunctionController extends AbstractFu
      */
     public $pObj;
 
+    /**
+     * The currently selected sys_template record
+     * @var array
+     */
+    protected $templateRow;
+
+    /**
+     * @var ExtendedTemplateService
+     */
+    protected $templateService;
+
     /**
      * Init
      *
@@ -120,19 +131,18 @@ class TypoScriptTemplateObjectBrowserModuleFunctionController extends AbstractFu
     public function initialize_editor($pageId, $template_uid = 0)
     {
         // Defined global here!
-        $templateService = GeneralUtility::makeInstance(ExtendedTemplateService::class);
-        $GLOBALS['tmpl'] = $templateService;
-        $templateService->init();
+        $this->templateService = GeneralUtility::makeInstance(ExtendedTemplateService::class);
+        $this->templateService->init();
 
         // Gets the rootLine
         $sys_page = GeneralUtility::makeInstance(PageRepository::class);
         $rootLine = $sys_page->getRootLine($pageId);
         // This generates the constants/config + hierarchy info for the template.
-        $templateService->runThroughTemplates($rootLine, $template_uid);
+        $this->templateService->runThroughTemplates($rootLine, $template_uid);
 
         // Get the row of the first VISIBLE template of the page. whereclause like the frontend.
-        $GLOBALS['tplRow'] = $templateService->ext_getFirstTemplate($pageId, $template_uid);
-        return is_array($GLOBALS['tplRow']);
+        $this->templateRow = $this->templateService->ext_getFirstTemplate($pageId, $template_uid);
+        return is_array($this->templateRow);
     }
 
     /**
@@ -153,15 +163,14 @@ class TypoScriptTemplateObjectBrowserModuleFunctionController extends AbstractFu
         }
         $bType = $this->pObj->MOD_SETTINGS['ts_browser_type'];
         $existTemplate = $this->initialize_editor($this->pObj->id, $template_uid);
-        $tplRow = $this->getTemplateRow();
         // initialize
         $assigns = [];
         $assigns['LLPrefix'] = 'LLL:' . $this->localLanguageFilePath . ':';
         $assigns['existTemplate'] = $existTemplate;
         $assigns['tsBrowserType'] = $this->pObj->MOD_SETTINGS['ts_browser_type'];
         if ($existTemplate) {
-            $assigns['templateRecord'] = $tplRow;
-            $assigns['linkWrapTemplateTitle'] = $this->pObj->linkWrapTemplateTitle($tplRow['title'], ($bType == 'setup' ? 'config' : 'constants'));
+            $assigns['templateRecord'] = $this->templateRow;
+            $assigns['linkWrapTemplateTitle'] = $this->pObj->linkWrapTemplateTitle($this->templateRow['title'], ($bType == 'setup' ? 'config' : 'constants'));
             $assigns['manyTemplatesMenu'] = $manyTemplatesMenu;
 
             if ($POST['add_property'] || $POST['update_value'] || $POST['clear_object']) {
@@ -200,11 +209,11 @@ class TypoScriptTemplateObjectBrowserModuleFunctionController extends AbstractFu
                     }
                 }
                 if ($line) {
-                    $saveId = $tplRow['_ORIG_uid'] ? $tplRow['_ORIG_uid'] : $tplRow['uid'];
+                    $saveId = $this->templateRow['_ORIG_uid'] ?: $this->templateRow['uid'];
                     // Set the data to be saved
                     $recData = [];
                     $field = $bType == 'setup' ? 'config' : 'constants';
-                    $recData['sys_template'][$saveId][$field] = $tplRow[$field] . $line;
+                    $recData['sys_template'][$saveId][$field] = $this->templateRow[$field] . $line;
                     // Create new  tce-object
                     $tce = GeneralUtility::makeInstance(DataHandler::class);
                     // Initialize
@@ -219,11 +228,10 @@ class TypoScriptTemplateObjectBrowserModuleFunctionController extends AbstractFu
             }
         }
         $tsbr = GeneralUtility::_GET('tsbr');
-        $templateService = $this->getExtendedTemplateService();
         $update = 0;
         if (is_array($tsbr)) {
             // If any plus-signs were clicked, it's registred.
-            $this->pObj->MOD_SETTINGS['tsbrowser_depthKeys_' . $bType] = $templateService->ext_depthKeys($tsbr, $this->pObj->MOD_SETTINGS['tsbrowser_depthKeys_' . $bType]);
+            $this->pObj->MOD_SETTINGS['tsbrowser_depthKeys_' . $bType] = $this->templateService->ext_depthKeys($tsbr, $this->pObj->MOD_SETTINGS['tsbrowser_depthKeys_' . $bType]);
             $update = 1;
         }
         if ($POST['Submit']) {
@@ -234,34 +242,34 @@ class TypoScriptTemplateObjectBrowserModuleFunctionController extends AbstractFu
         if ($update) {
             $this->getBackendUserAuthentication()->pushModuleData($this->pObj->MCONF['name'], $this->pObj->MOD_SETTINGS);
         }
-        $templateService->matchAlternative = $this->pObj->MOD_SETTINGS['tsbrowser_conditions'];
-        $templateService->matchAlternative[] = 'dummydummydummydummydummydummydummydummydummydummydummy';
+        $this->templateService->matchAlternative = $this->pObj->MOD_SETTINGS['tsbrowser_conditions'];
+        $this->templateService->matchAlternative[] = 'dummydummydummydummydummydummydummydummydummydummydummy';
         // This is just here to make sure that at least one element is in the array so that the tsparser actually uses this array to match.
-        $templateService->constantMode = $this->pObj->MOD_SETTINGS['ts_browser_const'];
-        if ($this->pObj->sObj && $templateService->constantMode) {
-            $templateService->constantMode = 'untouched';
+        $this->templateService->constantMode = $this->pObj->MOD_SETTINGS['ts_browser_const'];
+        if ($this->pObj->sObj && $this->templateService->constantMode) {
+            $this->templateService->constantMode = 'untouched';
         }
-        $templateService->regexMode = $this->pObj->MOD_SETTINGS['ts_browser_regexsearch'];
-        $templateService->fixedLgd = $this->pObj->MOD_SETTINGS['ts_browser_fixedLgd'];
-        $templateService->linkObjects = true;
-        $templateService->ext_regLinenumbers = true;
-        $templateService->ext_regComments = $this->pObj->MOD_SETTINGS['ts_browser_showComments'];
-        $templateService->bType = $bType;
+        $this->templateService->regexMode = $this->pObj->MOD_SETTINGS['ts_browser_regexsearch'];
+        $this->templateService->fixedLgd = $this->pObj->MOD_SETTINGS['ts_browser_fixedLgd'];
+        $this->templateService->linkObjects = true;
+        $this->templateService->ext_regLinenumbers = true;
+        $this->templateService->ext_regComments = $this->pObj->MOD_SETTINGS['ts_browser_showComments'];
+        $this->templateService->bType = $bType;
         if ($this->pObj->MOD_SETTINGS['ts_browser_type'] == 'const') {
-            $templateService->ext_constants_BRP = (int)GeneralUtility::_GP('breakPointLN');
+            $this->templateService->ext_constants_BRP = (int)GeneralUtility::_GP('breakPointLN');
         } else {
-            $templateService->ext_config_BRP = (int)GeneralUtility::_GP('breakPointLN');
+            $this->templateService->ext_config_BRP = (int)GeneralUtility::_GP('breakPointLN');
         }
-        $templateService->generateConfig();
+        $this->templateService->generateConfig();
         if ($bType == 'setup') {
-            $theSetup = $templateService->setup;
+            $theSetup = $this->templateService->setup;
         } else {
-            $theSetup = $templateService->setup_constants;
+            $theSetup = $this->templateService->setup_constants;
         }
         // EDIT A VALUE:
         $assigns['typoScriptPath'] = $this->pObj->sObj;
         if ($this->pObj->sObj) {
-            list($theSetup, $theSetupValue) = $templateService->ext_getSetup($theSetup, $this->pObj->sObj ? $this->pObj->sObj : '');
+            list($theSetup, $theSetupValue) = $this->templateService->ext_getSetup($theSetup, $this->pObj->sObj ? $this->pObj->sObj : '');
             $assigns['theSetupValue'] = $theSetupValue;
             if ($existTemplate === false) {
                 $noTemplateMessage = GeneralUtility::makeInstance(FlashMessage::class, $lang->getLL('noCurrentTemplate'), $lang->getLL('edit'), FlashMessage::ERROR);
@@ -283,13 +291,13 @@ class TypoScriptTemplateObjectBrowserModuleFunctionController extends AbstractFu
                 $assigns['moduleUrlObjectListAction'] = $aHref . '&addKey[' . rawurlencode($this->pObj->sObj) . ']=0&SET[ts_browser_toplevel_' . $bType . ']=0';
             }
         } else {
-            $templateService->tsbrowser_depthKeys = $this->pObj->MOD_SETTINGS['tsbrowser_depthKeys_' . $bType];
+            $this->templateService->tsbrowser_depthKeys = $this->pObj->MOD_SETTINGS['tsbrowser_depthKeys_' . $bType];
             if (GeneralUtility::_POST('search') && GeneralUtility::_POST('search_field')) {
                 // If any POST-vars are send, update the condition array
                 $searchString = GeneralUtility::_POST('search_field');
                 try {
-                    $templateService->tsbrowser_depthKeys =
-                        $templateService->ext_getSearchKeys(
+                    $this->templateService->tsbrowser_depthKeys =
+                        $this->templateService->ext_getSearchKeys(
                             $theSetup,
                             '',
                             $searchString,
@@ -316,19 +324,19 @@ class TypoScriptTemplateObjectBrowserModuleFunctionController extends AbstractFu
             if (!$theKey || !str_replace('-', '', $theKey)) {
                 $theKey = '';
             }
-            list($theSetup, $theSetupValue) = $templateService->ext_getSetup($theSetup, $this->pObj->MOD_SETTINGS['ts_browser_toplevel_' . $bType] ? $this->pObj->MOD_SETTINGS['ts_browser_toplevel_' . $bType] : '');
-            $tree = $templateService->ext_getObjTree($theSetup, $theKey, '', '', $theSetupValue, $this->pObj->MOD_SETTINGS['ts_browser_alphaSort']);
-            $tree = $templateService->substituteCMarkers($tree);
+            list($theSetup, $theSetupValue) = $this->templateService->ext_getSetup($theSetup, $this->pObj->MOD_SETTINGS['ts_browser_toplevel_' . $bType] ? $this->pObj->MOD_SETTINGS['ts_browser_toplevel_' . $bType] : '');
+            $tree = $this->templateService->ext_getObjTree($theSetup, $theKey, '', '', $theSetupValue, $this->pObj->MOD_SETTINGS['ts_browser_alphaSort']);
+            $tree = $this->templateService->substituteCMarkers($tree);
             $urlParameters = [
                 'id' => $this->pObj->id
             ];
             $aHref = BackendUtility::getModuleUrl('web_ts', $urlParameters);
             // Parser Errors:
             $pEkey = $bType == 'setup' ? 'config' : 'constants';
-            $assigns['hasParseErrors'] = !empty($templateService->parserErrors[$pEkey]);
-            if (!empty($templateService->parserErrors[$pEkey])) {
+            $assigns['hasParseErrors'] = !empty($this->templateService->parserErrors[$pEkey]);
+            if (!empty($this->templateService->parserErrors[$pEkey])) {
                 $assigns['showErrorDetailsUri'] = $aHref . '&SET[function]=TYPO3\\CMS\\Tstemplate\\Controller\\TemplateAnalyzerModuleFunctionController&template=all&SET[ts_analyzer_checkLinenum]=1#line-';
-                $assigns['parseErrors'] = $templateService->parserErrors[$pEkey];
+                $assigns['parseErrors'] = $this->templateService->parserErrors[$pEkey];
             }
 
             if (isset($this->pObj->MOD_SETTINGS['ts_browser_TLKeys_' . $bType][$theKey])) {
@@ -354,14 +362,14 @@ class TypoScriptTemplateObjectBrowserModuleFunctionController extends AbstractFu
             }
 
             // Conditions:
-            $assigns['hasConditions'] = is_array($templateService->sections) && !empty($templateService->sections);
-            if (is_array($templateService->sections) && !empty($templateService->sections)) {
+            $assigns['hasConditions'] = is_array($this->templateService->sections) && !empty($this->templateService->sections);
+            if (is_array($this->templateService->sections) && !empty($this->templateService->sections)) {
                 $tsConditions = [];
-                foreach ($templateService->sections as $key => $val) {
+                foreach ($this->templateService->sections as $key => $val) {
                     $tsConditions[] = [
                         'key' => $key,
                         'value' => $val,
-                        'label' => $templateService->substituteCMarkers(htmlspecialchars($val)),
+                        'label' => $this->templateService->substituteCMarkers(htmlspecialchars($val)),
                         'isSet' => $this->pObj->MOD_SETTINGS['tsbrowser_conditions'][$key] ? true : false
                     ];
                 }
@@ -393,20 +401,4 @@ class TypoScriptTemplateObjectBrowserModuleFunctionController extends AbstractFu
         $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
         $defaultFlashMessageQueue->enqueue($flashMessage);
     }
-
-    /**
-     * @return ExtendedTemplateService
-     */
-    protected function getExtendedTemplateService()
-    {
-        return $GLOBALS['tmpl'];
-    }
-
-    /**
-     * @return array
-     */
-    protected function getTemplateRow()
-    {
-        return $GLOBALS['tplRow'];
-    }
 }