[CLEANUP] sysext:tstemplate 99/35799/7
authorMarkus Klein <klein.t3@reelworx.at>
Mon, 5 Jan 2015 19:09:26 +0000 (20:09 +0100)
committerWouter Wolters <typo3@wouterwolters.nl>
Tue, 6 Jan 2015 22:28:19 +0000 (23:28 +0100)
Resolves: #64133
Resolves: #16595
Releases: master
Change-Id: Ic6947ec59bff30a3107ceeef4d828d3742ee4ced
Reviewed-on: http://review.typo3.org/35799
Reviewed-by: Stefan Froemken <froemken@gmail.com>
Tested-by: Stefan Froemken <froemken@gmail.com>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
typo3/sysext/backend/Classes/Module/AbstractFunctionModule.php
typo3/sysext/backend/Classes/Module/BaseScriptClass.php
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 cbef745..db51efd 100644 (file)
@@ -14,7 +14,10 @@ namespace TYPO3\CMS\Backend\Module;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Backend\Template\DocumentTemplate;
 use TYPO3\CMS\Backend\Utility\BackendUtility;
+use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
+use TYPO3\CMS\Core\Database\DatabaseConnection;
 use TYPO3\CMS\Core\Utility\ArrayUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Lang\LanguageService;
@@ -256,4 +259,32 @@ abstract class AbstractFunctionModule {
                return $GLOBALS['LANG'];
        }
 
+       /**
+        * @return BackendUserAuthentication
+        */
+       protected function getBackendUserAuthentication() {
+               return $GLOBALS['BE_USER'];
+       }
+
+       /**
+        * @return DocumentTemplate
+        */
+       protected function getDocumentTemplate() {
+               return $GLOBALS['TBE_TEMPLATE'];
+       }
+
+       /**
+        * @return string
+        */
+       protected function getBackPath() {
+               return $GLOBALS['BACK_PATH'];
+       }
+
+       /**
+        * @return DatabaseConnection
+        */
+       protected function getDatabaseConnection() {
+               return $GLOBALS['TYPO3_DB'];
+       }
+
 }
index 3b42e4f..efffa66 100644 (file)
@@ -16,6 +16,7 @@ namespace TYPO3\CMS\Backend\Module;
 
 use TYPO3\CMS\Backend\Utility\BackendUtility;
 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
+use TYPO3\CMS\Core\Database\DatabaseConnection;
 use TYPO3\CMS\Core\Messaging\FlashMessage;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Lang\LanguageService;
@@ -357,4 +358,11 @@ class BaseScriptClass {
                return $GLOBALS['BE_USER'];
        }
 
+       /**
+        * @return DatabaseConnection
+        */
+       protected function getDatabaseConnection() {
+               return $GLOBALS['TYPO3_DB'];
+       }
+
 }
index d06b03c..c27fdf9 100644 (file)
@@ -14,25 +14,35 @@ namespace TYPO3\CMS\Tstemplate\Controller;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Backend\Module\AbstractFunctionModule;
 use TYPO3\CMS\Backend\Utility\BackendUtility;
+use TYPO3\CMS\Backend\Utility\IconUtility;
+use TYPO3\CMS\Core\TypoScript\ExtendedTemplateService;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Frontend\Page\PageRepository;
 
 /**
  * TypoScript template analyzer
  *
  * @author Kasper Skårhøj <kasperYYYY@typo3.com>
  */
-class TemplateAnalyzerModuleFunctionController extends \TYPO3\CMS\Backend\Module\AbstractFunctionModule {
+class TemplateAnalyzerModuleFunctionController extends AbstractFunctionModule {
+
+       /**
+        * @var TypoScriptTemplateModuleController
+        */
+       public $pObj;
 
        /**
         * Init
         *
-        * @param object $pObj
+        * @param TypoScriptTemplateModuleController $pObj
         * @param array $conf
         * @return void
         */
        public function init(&$pObj, $conf) {
                parent::init($pObj, $conf);
-               $GLOBALS['LANG']->includeLLFile('EXT:tstemplate/Resources/Private/Language/locallang_analyzer.xlf');
+               $this->getLanguageService()->includeLLFile('EXT:tstemplate/Resources/Private/Language/locallang_analyzer.xlf');
                $this->pObj->modMenu_setDefaultList .= ',ts_analyzer_checkLinenum,ts_analyzer_checkSyntax';
        }
 
@@ -57,25 +67,27 @@ class TemplateAnalyzerModuleFunctionController extends \TYPO3\CMS\Backend\Module
         *
         * @param int $pageId
         * @param int $template_uid
-        * @return int
+        * @return bool
         */
        public function initialize_editor($pageId, $template_uid = 0) {
                // Initializes the module. Done in this function because we may need to re-initialize if data is submitted!
-               $GLOBALS['tmpl'] = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\TypoScript\ExtendedTemplateService::class);
+               $templateService = GeneralUtility::makeInstance(ExtendedTemplateService::class);
+               $GLOBALS['tmpl'] = $templateService;
+
                // Do not log time-performance information
-               $GLOBALS['tmpl']->tt_track = 0;
-               $GLOBALS['tmpl']->init();
+               $templateService->tt_track = FALSE;
+               $templateService->init();
+
                // Gets the rootLine
-               $sys_page = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Frontend\Page\PageRepository::class);
+               $sys_page = GeneralUtility::makeInstance(PageRepository::class);
                $GLOBALS['rootLine'] = $sys_page->getRootLine($pageId);
+
                // This generates the constants/config + hierarchy info for the template.
-               $GLOBALS['tmpl']->runThroughTemplates($GLOBALS['rootLine'], $template_uid);
+               $templateService->runThroughTemplates($GLOBALS['rootLine'], $template_uid);
+
                // Get the row of the first VISIBLE template of the page. whereclause like the frontend.
-               $GLOBALS['tplRow'] = $GLOBALS['tmpl']->ext_getFirstTemplate($pageId, $template_uid);
-               if (is_array($GLOBALS['tplRow'])) {
-                       // IF there was a template...
-                       return 1;
-               }
+               $GLOBALS['tplRow'] = $templateService->ext_getFirstTemplate($pageId, $template_uid);
+               return is_array($GLOBALS['tplRow']);
        }
 
        /**
@@ -94,68 +106,73 @@ class TemplateAnalyzerModuleFunctionController extends \TYPO3\CMS\Backend\Module
                        $template_uid = $this->pObj->MOD_SETTINGS['templatesOnPage'];
                }
 
-               // BUGBUG: Should we check if the uset may at all read and write template-records???
                $existTemplate = $this->initialize_editor($this->pObj->id, $template_uid);
 
                // initialize
+               $lang = $this->getLanguageService();
                if ($existTemplate) {
+                       $siteTitle = trim($GLOBALS['tplRow']['sitetitle']);
                        $theOutput .= $this->pObj->doc->section(
-                               $GLOBALS['LANG']->getLL('currentTemplate', TRUE),
-                               \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForRecord('sys_template', $GLOBALS['tplRow']) . '<strong>' . $this->pObj->linkWrapTemplateTitle($GLOBALS['tplRow']['title']) . '</strong>' . htmlspecialchars((trim($GLOBALS['tplRow']['sitetitle']) ? ' (' . $GLOBALS['tplRow']['sitetitle'] . ')' : ''))
+                               $lang->getLL('currentTemplate', TRUE),
+                               IconUtility::getSpriteIconForRecord('sys_template', $GLOBALS['tplRow'])
+                                       . '<strong>' . $this->pObj->linkWrapTemplateTitle($GLOBALS['tplRow']['title']) . '</strong>'
+                                       . htmlspecialchars($siteTitle ? ' (' . $siteTitle . ')' : '')
                        );
                }
                if ($manyTemplatesMenu) {
                        $theOutput .= $this->pObj->doc->section('', $manyTemplatesMenu);
                }
-               $GLOBALS['tmpl']->clearList_const_temp = array_flip($GLOBALS['tmpl']->clearList_const);
-               $GLOBALS['tmpl']->clearList_setup_temp = array_flip($GLOBALS['tmpl']->clearList_setup);
-               $pointer = count($GLOBALS['tmpl']->hierarchyInfo);
-               $hierarchyInfo = $GLOBALS['tmpl']->ext_process_hierarchyInfo(array(), $pointer);
+               $templateService = $this->getExtendedTemplateService();
+               $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(array(), $pointer);
                $head = '<thead><tr>';
-               $head .= '<th>' . $GLOBALS['LANG']->getLL('title', TRUE) . '</th>';
-               $head .= '<th>' . $GLOBALS['LANG']->getLL('rootlevel', TRUE) . '</th>';
-               $head .= '<th>' . $GLOBALS['LANG']->getLL('clearSetup', TRUE) . '</th>';
-               $head .= '<th>' . $GLOBALS['LANG']->getLL('clearConstants', TRUE) . '</th>';
-               $head .= '<th>' . $GLOBALS['LANG']->getLL('pid', TRUE) . '</th>';
-               $head .= '<th>' . $GLOBALS['LANG']->getLL('rootline', TRUE) . '</th>';
-               $head .= '<th>' . $GLOBALS['LANG']->getLL('nextLevel', TRUE) . '</th>';
+               $head .= '<th>' . $lang->getLL('title', TRUE) . '</th>';
+               $head .= '<th>' . $lang->getLL('rootlevel', TRUE) . '</th>';
+               $head .= '<th>' . $lang->getLL('clearSetup', TRUE) . '</th>';
+               $head .= '<th>' . $lang->getLL('clearConstants', TRUE) . '</th>';
+               $head .= '<th>' . $lang->getLL('pid', TRUE) . '</th>';
+               $head .= '<th>' . $lang->getLL('rootline', TRUE) . '</th>';
+               $head .= '<th>' . $lang->getLL('nextLevel', TRUE) . '</th>';
                $head .= '</tr></thead>';
-               $hierar = implode(array_reverse($GLOBALS['tmpl']->ext_getTemplateHierarchyArr($hierarchyInfo, '', array(), 1)), '');
+               $hierar = implode(array_reverse($templateService->ext_getTemplateHierarchyArr($hierarchyInfo, '', array(), 1)), '');
                $hierar = '<div class="table-fit"><table class="table table-striped table-hover" id="ts-analyzer">' . $head . $hierar . '</table></div>';
                $theOutput .= $this->pObj->doc->spacer(5);
-               $theOutput .= $this->pObj->doc->section($GLOBALS['LANG']->getLL('templateHierarchy', TRUE), $hierar, 0, 1);
+               $theOutput .= $this->pObj->doc->section($lang->getLL('templateHierarchy', TRUE), $hierar, 0, 1);
                $urlParameters = array(
                        'id' => $GLOBALS['SOBE']->id,
                        'template' => 'all'
                );
                $aHref = BackendUtility::getModuleUrl('web_ts', $urlParameters);
-               $completeLink = '<p><a href="' . htmlspecialchars($aHref) . '" class="btn btn-default">' . $GLOBALS['LANG']->getLL('viewCompleteTS', TRUE) . '</a></p>';
+
+               $completeLink = '<p><a href="' . htmlspecialchars($aHref) . '" class="btn btn-default">' . $lang->getLL('viewCompleteTS', TRUE) . '</a></p>';
                $theOutput .= $this->pObj->doc->spacer(5);
-               $theOutput .= $this->pObj->doc->section($GLOBALS['LANG']->getLL('completeTS', TRUE), $completeLink, 0, 1);
+               $theOutput .= $this->pObj->doc->section($lang->getLL('completeTS', TRUE), $completeLink, 0, 1);
                $theOutput .= $this->pObj->doc->spacer(15);
                // Output options
-               $theOutput .= $this->pObj->doc->section($GLOBALS['LANG']->getLL('displayOptions', TRUE), '', FALSE, TRUE);
+               $theOutput .= $this->pObj->doc->section($lang->getLL('displayOptions', TRUE), '', FALSE, TRUE);
 
-               $template = \TYPO3\CMS\Core\Utility\GeneralUtility::_GET('template');
+               $template = GeneralUtility::_GET('template');
                $addParams = $template ? '&template=' . $template : '';
                $theOutput .= '<div class="tst-analyzer-options">' .
                        '<div class="checkbox"><label for="checkTs_analyzer_checkLinenum">' .
                                BackendUtility::getFuncCheck($this->pObj->id, 'SET[ts_analyzer_checkLinenum]', $this->pObj->MOD_SETTINGS['ts_analyzer_checkLinenum'], '', $addParams, 'id="checkTs_analyzer_checkLinenum"') .
-                               $GLOBALS['LANG']->getLL('lineNumbers', TRUE) .
+                               $lang->getLL('lineNumbers', TRUE) .
                        '</label></div>' .
                        '<div class="checkbox"><label for="checkTs_analyzer_checkSyntax">' .
                                BackendUtility::getFuncCheck($this->pObj->id, 'SET[ts_analyzer_checkSyntax]', $this->pObj->MOD_SETTINGS['ts_analyzer_checkSyntax'], '', $addParams, 'id="checkTs_analyzer_checkSyntax"') .
-                               $GLOBALS['LANG']->getLL('syntaxHighlight', TRUE) . '</label> ' .
+                               $lang->getLL('syntaxHighlight', TRUE) . '</label> ' .
                        '</label></div>';
                if (!$this->pObj->MOD_SETTINGS['ts_analyzer_checkSyntax']) {
                        $theOutput .=
                                '<div class="checkbox"><label for="checkTs_analyzer_checkComments">' .
                                        BackendUtility::getFuncCheck($this->pObj->id, 'SET[ts_analyzer_checkComments]', $this->pObj->MOD_SETTINGS['ts_analyzer_checkComments'], '', $addParams, 'id="checkTs_analyzer_checkComments"') .
-                                       $GLOBALS['LANG']->getLL('comments', TRUE) .
+                                       $lang->getLL('comments', TRUE) .
                                '</label></div>' .
                                '<div class="checkbox"><label for="checkTs_analyzer_checkCrop">' .
                                        BackendUtility::getFuncCheck($this->pObj->id, 'SET[ts_analyzer_checkCrop]', $this->pObj->MOD_SETTINGS['ts_analyzer_checkCrop'], '', $addParams, 'id="checkTs_analyzer_checkCrop"') .
-                                       $GLOBALS['LANG']->getLL('cropLines', TRUE) .
+                                       $lang->getLL('cropLines', TRUE) .
                                '</label></div>';
                }
                $theOutput .=  '</div>';
@@ -163,50 +180,57 @@ class TemplateAnalyzerModuleFunctionController extends \TYPO3\CMS\Backend\Module
 
                if ($template) {
                        // Output Constants
-                       $theOutput .= $this->pObj->doc->section($GLOBALS['LANG']->getLL('constants', TRUE), '', 0, 1);
+                       $theOutput .= $this->pObj->doc->section($lang->getLL('constants', TRUE), '', 0, 1);
                        $theOutput .= $this->pObj->doc->sectionEnd();
 
-                       $GLOBALS['tmpl']->ext_lineNumberOffset = 0;
-                       $GLOBALS['tmpl']->ext_lineNumberOffset_mode = 'const';
-                       foreach ($GLOBALS['tmpl']->constants as $key => $val) {
-                               $currentTemplateId = $GLOBALS['tmpl']->hierarchyInfo[$key]['templateID'];
+                       $templateService->ext_lineNumberOffset = 0;
+                       $templateService->ext_lineNumberOffset_mode = 'const';
+                       foreach ($templateService->constants as $key => $val) {
+                               $currentTemplateId = $templateService->hierarchyInfo[$key]['templateID'];
                                if ($currentTemplateId == $template || $template === 'all') {
                                        $theOutput .= '
-                                               <h3>' . htmlspecialchars($GLOBALS['tmpl']->hierarchyInfo[$key]['title']) . '</h3>
+                                               <h3>' . htmlspecialchars($templateService->hierarchyInfo[$key]['title']) . '</h3>
                                                <div class="nowrap">' .
-                                                       $GLOBALS['tmpl']->ext_outputTS(array($val), $this->pObj->MOD_SETTINGS['ts_analyzer_checkLinenum'], $this->pObj->MOD_SETTINGS['ts_analyzer_checkComments'], $this->pObj->MOD_SETTINGS['ts_analyzer_checkCrop'], $this->pObj->MOD_SETTINGS['ts_analyzer_checkSyntax'], 0) .
+                                                       $templateService->ext_outputTS(array($val), $this->pObj->MOD_SETTINGS['ts_analyzer_checkLinenum'], $this->pObj->MOD_SETTINGS['ts_analyzer_checkComments'], $this->pObj->MOD_SETTINGS['ts_analyzer_checkCrop'], $this->pObj->MOD_SETTINGS['ts_analyzer_checkSyntax'], 0) .
                                                '</div>
                                        ';
                                        if ($template !== 'all') {
                                                break;
                                        }
                                }
-                               $GLOBALS['tmpl']->ext_lineNumberOffset += count(explode(LF, $val)) + 1;
+                               $templateService->ext_lineNumberOffset += count(explode(LF, $val)) + 1;
                        }
 
                        // Output Setup
                        $theOutput .= $this->pObj->doc->spacer(15);
-                       $theOutput .= $this->pObj->doc->section($GLOBALS['LANG']->getLL('setup', TRUE), '', 0, 1);
+                       $theOutput .= $this->pObj->doc->section($lang->getLL('setup', TRUE), '', 0, 1);
                        $theOutput .= $this->pObj->doc->sectionEnd();
-                       $GLOBALS['tmpl']->ext_lineNumberOffset = 0;
-                       $GLOBALS['tmpl']->ext_lineNumberOffset_mode = 'setup';
-                       foreach ($GLOBALS['tmpl']->config as $key => $val) {
-                               $currentTemplateId = $GLOBALS['tmpl']->hierarchyInfo[$key]['templateID'];
+                       $templateService->ext_lineNumberOffset = 0;
+                       $templateService->ext_lineNumberOffset_mode = 'setup';
+                       foreach ($templateService->config as $key => $val) {
+                               $currentTemplateId = $templateService->hierarchyInfo[$key]['templateID'];
                                if ($currentTemplateId == $template || $template == 'all') {
                                        $theOutput .= '
-                                               <h3>' . htmlspecialchars($GLOBALS['tmpl']->hierarchyInfo[$key]['title']) . '</h3>
+                                               <h3>' . htmlspecialchars($templateService->hierarchyInfo[$key]['title']) . '</h3>
                                                <div class="nowrap">' .
-                                                       $GLOBALS['tmpl']->ext_outputTS(array($val), $this->pObj->MOD_SETTINGS['ts_analyzer_checkLinenum'], $this->pObj->MOD_SETTINGS['ts_analyzer_checkComments'], $this->pObj->MOD_SETTINGS['ts_analyzer_checkCrop'], $this->pObj->MOD_SETTINGS['ts_analyzer_checkSyntax'], 0) .
+                                                       $templateService->ext_outputTS(array($val), $this->pObj->MOD_SETTINGS['ts_analyzer_checkLinenum'], $this->pObj->MOD_SETTINGS['ts_analyzer_checkComments'], $this->pObj->MOD_SETTINGS['ts_analyzer_checkCrop'], $this->pObj->MOD_SETTINGS['ts_analyzer_checkSyntax'], 0) .
                                                '</div>
                                        ';
                                        if ($template !== 'all') {
                                                break;
                                        }
                                }
-                               $GLOBALS['tmpl']->ext_lineNumberOffset += count(explode(LF, $val)) + 1;
+                               $templateService->ext_lineNumberOffset += count(explode(LF, $val)) + 1;
                        }
                }
                return $theOutput;
        }
 
+       /**
+        * @return ExtendedTemplateService
+        */
+       protected function getExtendedTemplateService() {
+               return $GLOBALS['tmpl'];
+       }
+
 }
index 20ac3b4..822c2b7 100644 (file)
@@ -14,52 +14,73 @@ namespace TYPO3\CMS\Tstemplate\Controller;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Backend\Module\AbstractFunctionModule;
+use TYPO3\CMS\Backend\Utility\BackendUtility;
+use TYPO3\CMS\Backend\Utility\IconUtility;
+use TYPO3\CMS\Core\DataHandling\DataHandler;
+use TYPO3\CMS\Core\TypoScript\ExtendedTemplateService;
+use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\Utility\MathUtility;
+use TYPO3\CMS\Frontend\Page\PageRepository;
+
 /**
  * TypoScript Constant editor
  *
  * Module Include-file
  *
- * localconf-variables:
- * $TYPO3_CONF_VARS['MODS']['web_ts']['onlineResourceDir'] = 'fileadmin/fonts/';               // This is the path (must be in "fileadmin/" !!) where the web_ts/constant-editor submodule fetches online resources. Put fonts (ttf) and standard images here!
+ * $GLOBALS['TYPO3_CONF_VARS']['MODS']['web_ts']['onlineResourceDir'] = 'fileadmin/fonts/';
+ * // This is the path (must be in "fileadmin/" !!) where the web_ts/constant-editor submodule fetches online resources.
+ * Put fonts (ttf) and standard images here!
  *
  * @author Kasper Skårhøj <kasperYYYY@typo3.com>
  */
-class TypoScriptTemplateConstantEditorModuleFunctionController extends \TYPO3\CMS\Backend\Module\AbstractFunctionModule {
+class TypoScriptTemplateConstantEditorModuleFunctionController extends AbstractFunctionModule {
+
+       /**
+        * @var TypoScriptTemplateModuleController
+        */
+       public $pObj;
 
        /**
         * Initialize editor
         *
+        * Initializes the module.
+        * Done in this function because we may need to re-initialize if data is submitted!
+        *
         * @param int $pageId
         * @param int $template_uid
-        * @return int
+        * @return bool
         */
        public function initialize_editor($pageId, $template_uid = 0) {
-               // Initializes the module. Done in this function because we may need to re-initialize if data is submitted!
-               global $tmpl, $tplRow, $theConstants;
-               $tmpl = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\TypoScript\ExtendedTemplateService::class);
-               // Defined global here!
-               $tmpl->tt_track = 0;
+               $templateService = GeneralUtility::makeInstance(ExtendedTemplateService::class);
+               $GLOBALS['tmpl'] = $templateService;
+
                // Do not log time-performance information
-               $tmpl->init();
-               $tmpl->ext_localGfxPrefix = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('tstemplate');
-               $tmpl->ext_localWebGfxPrefix = $GLOBALS['BACK_PATH'] . \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('tstemplate') . 'Resources/Public/';
+               $templateService->tt_track = FALSE;
+
+               $templateService->init();
+               $templateService->ext_localGfxPrefix = ExtensionManagementUtility::extPath('tstemplate');
+               $templateService->ext_localWebGfxPrefix = $GLOBALS['BACK_PATH'] . ExtensionManagementUtility::extRelPath('tstemplate') . 'Resources/Public/';
+
                // Get the row of the first VISIBLE template of the page. whereclause like the frontend.
-               $tplRow = $tmpl->ext_getFirstTemplate($pageId, $template_uid);
+               $GLOBALS['tplRow'] = $templateService->ext_getFirstTemplate($pageId, $template_uid);
                // IF there was a template...
-               if (is_array($tplRow)) {
+               if (is_array($GLOBALS['tplRow'])) {
                        // Gets the rootLine
-                       $sys_page = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Frontend\Page\PageRepository::class);
+                       $sys_page = GeneralUtility::makeInstance(PageRepository::class);
                        $rootLine = $sys_page->getRootLine($pageId);
                        // This generates the constants/config + hierarchy info for the template.
-                       $tmpl->runThroughTemplates($rootLine, $template_uid);
+                       $templateService->runThroughTemplates($rootLine, $template_uid);
                        // The editable constants are returned in an array.
-                       $theConstants = $tmpl->generateConfig_constants();
+                       $GLOBALS['theConstants'] = $templateService->generateConfig_constants();
                        // The returned constants are sorted in categories, that goes into the $tmpl->categories array
-                       $tmpl->ext_categorizeEditableConstants($theConstants);
-                       // This array will contain key=[expanded constantname], value=linenumber in template. (after edit_divider, if any)
-                       $tmpl->ext_regObjectPositions($tplRow['constants']);
-                       return 1;
+                       $templateService->ext_categorizeEditableConstants($GLOBALS['theConstants']);
+                       // This array will contain key=[expanded constant name], value=line number in template. (after edit_divider, if any)
+                       $templateService->ext_regObjectPositions($GLOBALS['tplRow']['constants']);
+                       return TRUE;
                }
+               return FALSE;
        }
 
        /**
@@ -69,10 +90,10 @@ class TypoScriptTemplateConstantEditorModuleFunctionController extends \TYPO3\CM
         * @return string
         */
        public function displayExample($theOutput) {
-               global $tmpl;
-               if ($tmpl->helpConfig['imagetag'] || $tmpl->helpConfig['description'] || $tmpl->helpConfig['header']) {
+               $templateService = $this->getExtendedTemplateService();
+               if ($templateService->helpConfig['imagetag'] || $templateService->helpConfig['description'] || $templateService->helpConfig['header']) {
                        $theOutput .= $this->pObj->doc->spacer(30);
-                       $theOutput .= $this->pObj->doc->section($tmpl->helpConfig['header'], '<div align="center">' . $tmpl->helpConfig['imagetag'] . '</div><BR>' . ($tmpl->helpConfig['description'] ? implode(explode('//', $tmpl->helpConfig['description']), '<BR>') . '<BR>' : '') . ($tmpl->helpConfig['bulletlist'] ? '<ul><li>' . implode(explode('//', $tmpl->helpConfig['bulletlist']), '<li>') . '</ul>' : '<BR>'));
+                       $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>'));
                }
                return $theOutput;
        }
@@ -83,8 +104,9 @@ class TypoScriptTemplateConstantEditorModuleFunctionController extends \TYPO3\CM
         * @return string
         */
        public function main() {
-               global $tmpl, $tplRow, $theConstants;
-               $GLOBALS['LANG']->includeLLFile('EXT:tstemplate/Resources/Private/Language/locallang_ceditor.xlf');
+               $lang = $this->getLanguageService();
+
+               $lang->includeLLFile('EXT:tstemplate/Resources/Private/Language/locallang_ceditor.xlf');
                $theOutput = '';
                // Create extension template
                $this->pObj->createTemplate($this->pObj->id);
@@ -94,23 +116,27 @@ class TypoScriptTemplateConstantEditorModuleFunctionController extends \TYPO3\CM
                if ($manyTemplatesMenu) {
                        $template_uid = $this->pObj->MOD_SETTINGS['templatesOnPage'];
                }
-               // BUGBUG: Should we check if the user may at all read and write template-records???
+
                // initialize
                $existTemplate = $this->initialize_editor($this->pObj->id, $template_uid);
                if ($existTemplate) {
+                       $templateService = $this->getExtendedTemplateService();
+                       $tplRow = $this->getTemplateRow();
+                       $theConstants = $this->getConstants();
+
                        $this->pObj->doc->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Tstemplate/ConstantEditor');
                        $saveId = $tplRow['_ORIG_uid'] ? $tplRow['_ORIG_uid'] : $tplRow['uid'];
                        // Update template ?
-                       if (\TYPO3\CMS\Core\Utility\GeneralUtility::_POST('submit') || \TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger(\TYPO3\CMS\Core\Utility\GeneralUtility::_POST('submit_x')) && \TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger(\TYPO3\CMS\Core\Utility\GeneralUtility::_POST('submit_y'))) {
-                               $tmpl->changed = 0;
-                               $tmpl->ext_procesInput(\TYPO3\CMS\Core\Utility\GeneralUtility::_POST(), array(), $theConstants, $tplRow);
-                               if ($tmpl->changed) {
+                       if (GeneralUtility::_POST('submit') || MathUtility::canBeInterpretedAsInteger(GeneralUtility::_POST('submit_x')) && MathUtility::canBeInterpretedAsInteger(GeneralUtility::_POST('submit_y'))) {
+                               $templateService->changed = 0;
+                               $templateService->ext_procesInput(GeneralUtility::_POST(), array(), $theConstants, $tplRow);
+                               if ($templateService->changed) {
                                        // Set the data to be saved
                                        $recData = array();
-                                       $recData['sys_template'][$saveId]['constants'] = implode($tmpl->raw, LF);
+                                       $recData['sys_template'][$saveId]['constants'] = implode($templateService->raw, LF);
                                        // Create new  tce-object
-                                       $tce = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\DataHandling\DataHandler::class);
-                                       $tce->stripslashes_values = 0;
+                                       $tce = GeneralUtility::makeInstance(DataHandler::class);
+                                       $tce->stripslashes_values = FALSE;
                                        $tce->start($recData, array());
                                        $tce->process_datamap();
                                        // Clear the cache (note: currently only admin-users can clear the cache in tce_main.php)
@@ -120,30 +146,31 @@ class TypoScriptTemplateConstantEditorModuleFunctionController extends \TYPO3\CM
                                }
                        }
                        // 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'] = $tmpl->ext_getCategoryLabelArray();
-                       $this->pObj->MOD_SETTINGS = \TYPO3\CMS\Backend\Utility\BackendUtility::getModuleData($this->pObj->MOD_MENU, \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('SET'), $this->pObj->MCONF['name']);
+                       $this->pObj->MOD_MENU['constant_editor_cat'] = $templateService->ext_getCategoryLabelArray();
+                       $this->pObj->MOD_SETTINGS = BackendUtility::getModuleData($this->pObj->MOD_MENU, GeneralUtility::_GP('SET'), $this->pObj->MCONF['name']);
                        // Resetting the menu (stop)
-                       $content = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForRecord('sys_template', $tplRow) . '<strong>' . $this->pObj->linkWrapTemplateTitle($tplRow['title'], 'constants') . '</strong>' . htmlspecialchars((trim($tplRow['sitetitle']) ? ' (' . $tplRow['sitetitle'] . ')' : ''));
-                       $theOutput .= $this->pObj->doc->section($GLOBALS['LANG']->getLL('editConstants', TRUE), $content, FALSE, TRUE);
+                       $content = IconUtility::getSpriteIconForRecord('sys_template', $tplRow) . '<strong>' . $this->pObj->linkWrapTemplateTitle($tplRow['title'], 'constants') . '</strong>' . htmlspecialchars((trim($tplRow['sitetitle']) ? ' (' . $tplRow['sitetitle'] . ')' : ''));
+                       $theOutput .= $this->pObj->doc->section($lang->getLL('editConstants', TRUE), $content, FALSE, TRUE);
                        if ($manyTemplatesMenu) {
                                $theOutput .= $this->pObj->doc->section('', $manyTemplatesMenu);
                        }
                        $theOutput .= $this->pObj->doc->spacer(10);
                        if (count($this->pObj->MOD_MENU['constant_editor_cat'])) {
-                               $menu = \TYPO3\CMS\Backend\Utility\BackendUtility::getFuncMenu($this->pObj->id, 'SET[constant_editor_cat]', $this->pObj->MOD_SETTINGS['constant_editor_cat'], $this->pObj->MOD_MENU['constant_editor_cat']);
-                               $theOutput .= $this->pObj->doc->section($GLOBALS['LANG']->getLL('category', TRUE), '<NOBR>' . $menu . '</NOBR>', FALSE);
+                               $menu = BackendUtility::getFuncMenu($this->pObj->id, 'SET[constant_editor_cat]', $this->pObj->MOD_SETTINGS['constant_editor_cat'], $this->pObj->MOD_MENU['constant_editor_cat']);
+                               $theOutput .= $this->pObj->doc->section($lang->getLL('category', TRUE), '<NOBR>' . $menu . '</NOBR>', FALSE);
                        } else {
-                               $theOutput .= $this->pObj->doc->section($GLOBALS['LANG']->getLL('noConstants', TRUE), $GLOBALS['LANG']->getLL('noConstantsDescription', TRUE), FALSE, FALSE, 1);
+                               $theOutput .= $this->pObj->doc->section($lang->getLL('noConstants', TRUE), $lang->getLL('noConstantsDescription', TRUE), FALSE, FALSE, 1);
                        }
                        $theOutput .= $this->pObj->doc->spacer(15);
                        // Category and constant editor config:
                        $category = $this->pObj->MOD_SETTINGS['constant_editor_cat'];
-                       $tmpl->ext_getTSCE_config($category);
+                       $templateService->ext_getTSCE_config($category);
 
-                       $printFields = trim($tmpl->ext_printFields($theConstants, $category));
+                       $printFields = trim($templateService->ext_printFields($theConstants, $category));
                        if ($printFields) {
                                $theOutput .= $this->pObj->doc->section('', $printFields);
                        }
+                       $BE_USER_modOptions = BackendUtility::getModTSconfig(0, 'mod.' . $this->pObj->MCONF['name']);
                        if ($BE_USER_modOptions['properties']['constantEditor.']['example'] != 'top') {
                                $theOutput = $this->displayExample($theOutput);
                        }
@@ -153,4 +180,25 @@ class TypoScriptTemplateConstantEditorModuleFunctionController extends \TYPO3\CM
                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 fea1560..99b1429 100644 (file)
@@ -14,6 +14,7 @@ namespace TYPO3\CMS\Tstemplate\Controller;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\DataHandling\DataHandler;
 use TYPO3\CMS\Core\TypoScript\ExtendedTemplateService;
 use TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
@@ -55,7 +56,6 @@ class TypoScriptTemplateInformationModuleFunctionController extends AbstractFunc
        public function tableRow($label, $data, $field, $id) {
                $lang = $this->getLanguageService();
                $ret = '<tr><td>';
-               $startAnchor = '';
                if ($field === 'config' || $field === 'constants') {
                        $urlParameters = array(
                                'id' => $this->pObj->id
@@ -81,17 +81,21 @@ class TypoScriptTemplateInformationModuleFunctionController extends AbstractFunc
         * $GLOBALS['tmpl'] 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!
+        *
         * @param int $pageId The uid of the current page
         * @param int $template_uid: The uid of the template record to be rendered (only if more than one template on the current page)
         * @return bool Returns TRUE if a template record was found, otherwise FALSE
         */
        public function initialize_editor($pageId, $template_uid = 0) {
-               // Initializes the module. Done in this function because we may need to re-initialize if data is submitted!
                /** @var ExtendedTemplateService $tmpl */
-               $GLOBALS['tmpl'] = $tmpl = GeneralUtility::makeInstance(\TYPO3\CMS\Core\TypoScript\ExtendedTemplateService::class);
+               $tmpl = GeneralUtility::makeInstance(ExtendedTemplateService::class);
+               $GLOBALS['tmpl'] = $tmpl;
+
                // Do not log time-performance information
-               $tmpl->tt_track = 0;
+               $tmpl->tt_track = FALSE;
                $tmpl->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'])) {
@@ -198,8 +202,8 @@ class TypoScriptTemplateInformationModuleFunctionController extends AbstractFunc
                                if (count($recData)) {
                                        $recData['sys_template'][$saveId] = $this->processTemplateRowBeforeSaving($recData['sys_template'][$saveId]);
                                        // Create new  tce-object
-                                       $tce = GeneralUtility::makeInstance(\TYPO3\CMS\Core\DataHandling\DataHandler::class);
-                                       $tce->stripslashes_values = 0;
+                                       $tce = GeneralUtility::makeInstance(DataHandler::class);
+                                       $tce->stripslashes_values = FALSE;
                                        $tce->alternativeFileName = $alternativeFileName;
                                        // Initialize
                                        $tce->start($recData, array());
index 75215c4..e0464b3 100644 (file)
@@ -14,9 +14,15 @@ namespace TYPO3\CMS\Tstemplate\Controller;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Backend\Module\BaseScriptClass;
+use TYPO3\CMS\Backend\Template\DocumentTemplate;
+use TYPO3\CMS\Core\DataHandling\DataHandler;
+use TYPO3\CMS\Core\Messaging\FlashMessage;
+use TYPO3\CMS\Core\TypoScript\ExtendedTemplateService;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Backend\Utility\BackendUtility;
 use TYPO3\CMS\Backend\Utility\IconUtility;
+use TYPO3\CMS\Core\Utility\MathUtility;
 
 /**
  * Module: TypoScript Tools
@@ -25,7 +31,7 @@ use TYPO3\CMS\Backend\Utility\IconUtility;
  *
  * @author Kasper Skårhøj <kasperYYYY@typo3.com>
  */
-class TypoScriptTemplateModuleController extends \TYPO3\CMS\Backend\Module\BaseScriptClass {
+class TypoScriptTemplateModuleController extends BaseScriptClass {
 
        /**
         * @var string
@@ -88,7 +94,7 @@ class TypoScriptTemplateModuleController extends \TYPO3\CMS\Backend\Module\BaseS
         * Constructor
         */
        public function __construct() {
-               $GLOBALS['LANG']->includeLLFile('EXT:tstemplate/ts/locallang.xlf');
+               $this->getLanguageService()->includeLLFile('EXT:tstemplate/ts/locallang.xlf');
 
                $this->MCONF = array(
                        'name' => $this->moduleName
@@ -106,7 +112,7 @@ class TypoScriptTemplateModuleController extends \TYPO3\CMS\Backend\Module\BaseS
                $this->e = GeneralUtility::_GP('e');
                $this->sObj = GeneralUtility::_GP('sObj');
                $this->edit = GeneralUtility::_GP('edit');
-               $this->perms_clause = $GLOBALS['BE_USER']->getPagePermsClause(1);
+               $this->perms_clause = $this->getBackendUser()->getPagePermsClause(1);
        }
 
        /**
@@ -116,9 +122,9 @@ class TypoScriptTemplateModuleController extends \TYPO3\CMS\Backend\Module\BaseS
         */
        public function clearCache() {
                if (GeneralUtility::_GP('clear_all_cache')) {
-                       $tce = GeneralUtility::makeInstance(\TYPO3\CMS\Core\DataHandling\DataHandler::class);
-                       /** @var $tce \TYPO3\CMS\Core\DataHandling\DataHandler */
-                       $tce->stripslashes_values = 0;
+                       /** @var DataHandler $tce */
+                       $tce = GeneralUtility::makeInstance(DataHandler::class);
+                       $tce->stripslashes_values = FALSE;
                        $tce->start(array(), array());
                        $tce->clear_cacheCmd('all');
                }
@@ -142,12 +148,14 @@ class TypoScriptTemplateModuleController extends \TYPO3\CMS\Backend\Module\BaseS
                $this->pageinfo = BackendUtility::readPageAccess($this->id, $this->perms_clause);
                $this->access = is_array($this->pageinfo);
 
-               /** @var \TYPO3\CMS\Backend\Template\DocumentTemplate doc */
-               $this->doc = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Template\DocumentTemplate::class);
+               /** @var DocumentTemplate doc */
+               $this->doc = GeneralUtility::makeInstance(DocumentTemplate::class);
                $this->doc->backPath = $GLOBALS['BACK_PATH'];
                $this->doc->setModuleTemplate('EXT:tstemplate/Resources/Private/Templates/tstemplate.html');
                $this->doc->addStyleSheet('module', 'sysext/tstemplate/Resources/Public/Styles/styles.css');
 
+               $lang = $this->getLanguageService();
+
                if ($this->id && $this->access) {
                        $urlParameters = array(
                                'id' => $this->id,
@@ -185,7 +193,7 @@ class TypoScriptTemplateModuleController extends \TYPO3\CMS\Backend\Module\BaseS
                        // Setting up the context sensitive menu:
                        $this->doc->getContextMenuCode();
                        // Build the modulle content
-                       $this->content = $this->doc->header($GLOBALS['LANG']->getLL('moduleTitle'));
+                       $this->content = $this->doc->header($lang->getLL('moduleTitle'));
                        $this->extObjContent();
                        // Setting up the buttons and markers for docheader
                        $docHeaderButtons = $this->getButtons();
@@ -193,28 +201,28 @@ class TypoScriptTemplateModuleController extends \TYPO3\CMS\Backend\Module\BaseS
                        $markers['CONTENT'] = $this->content;
                } else {
                        // Template pages:
-                       $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('pages.uid, count(*) AS count, max(sys_template.root) AS root_max_val, min(sys_template.root) AS root_min_val', 'pages,sys_template', 'pages.uid=sys_template.pid' . BackendUtility::deleteClause('pages') . BackendUtility::versioningPlaceholderClause('pages') . BackendUtility::deleteClause('sys_template') . BackendUtility::versioningPlaceholderClause('sys_template'), 'pages.uid');
-                       $templateArray = array();
+                       $db = $this->getDatabaseConnection();
+                       $res = $db->exec_SELECTquery('pages.uid, count(*) AS count, max(sys_template.root) AS root_max_val, min(sys_template.root) AS root_min_val', 'pages,sys_template', 'pages.uid=sys_template.pid' . BackendUtility::deleteClause('pages') . BackendUtility::versioningPlaceholderClause('pages') . BackendUtility::deleteClause('sys_template') . BackendUtility::versioningPlaceholderClause('sys_template'), 'pages.uid');
                        $pArray = array();
-                       while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
+                       while ($row = $db->sql_fetch_assoc($res)) {
                                $this->setInPageArray($pArray, BackendUtility::BEgetRootLine($row['uid'], 'AND 1=1'), $row);
                        }
-                       $GLOBALS['TYPO3_DB']->sql_free_result($res);
+                       $db->sql_free_result($res);
 
                        $table = '<div class="table-fit"><table class="table table-striped table-hover" id="ts-overview">' .
                                        '<thead>' .
                                        '<tr>' .
-                                       '<th>' . $GLOBALS['LANG']->getLL('pageName') . '</th>' .
-                                       '<th>' . $GLOBALS['LANG']->getLL('templates') . '</th>' .
-                                       '<th>' . $GLOBALS['LANG']->getLL('isRoot') . '</th>' .
-                                       '<th>' . $GLOBALS['LANG']->getLL('isExt') . '</th>' .
+                                       '<th>' . $lang->getLL('pageName') . '</th>' .
+                                       '<th>' . $lang->getLL('templates') . '</th>' .
+                                       '<th>' . $lang->getLL('isRoot') . '</th>' .
+                                       '<th>' . $lang->getLL('isExt') . '</th>' .
                                        '</tr>' .
                                        '</thead>' .
                                        '<tbody>' . implode('', $this->renderList($pArray)) . '</tbody>' .
                                        '</table></div>';
 
-                       $this->content = $this->doc->header($GLOBALS['LANG']->getLL('moduleTitle'));
-                       $this->content .= $this->doc->section('', '<p class="lead">' . $GLOBALS['LANG']->getLL('overview') . '</p>' . $table);
+                       $this->content = $this->doc->header($lang->getLL('moduleTitle'));
+                       $this->content .= $this->doc->section('', '<p class="lead">' . $lang->getLL('overview') . '</p>' . $table);
 
                        // RENDER LIST of pages with templates, END
                        // Setting up the buttons and markers for docheader
@@ -253,52 +261,54 @@ class TypoScriptTemplateModuleController extends \TYPO3\CMS\Backend\Module\BaseS
                        'shortcut' => ''
                );
 
+               $lang = $this->getLanguageService();
+
                if ($this->id && $this->access) {
                        // View page
-                       $buttons['view'] = '<a href="#" onclick="' . htmlspecialchars(BackendUtility::viewOnClick($this->pageinfo['uid'], $GLOBALS['BACK_PATH'], BackendUtility::BEgetRootLine($this->pageinfo['uid']))) . '" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.showPage', TRUE) . '">' . IconUtility::getSpriteIcon('actions-document-view') . '</a>';
-                       if ($this->extClassConf['name'] == \TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateInformationModuleFunctionController::class) {
+                       $buttons['view'] = '<a href="#" onclick="' . htmlspecialchars(BackendUtility::viewOnClick($this->pageinfo['uid'], $GLOBALS['BACK_PATH'], BackendUtility::BEgetRootLine($this->pageinfo['uid']))) . '" title="' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:labels.showPage', TRUE) . '">' . IconUtility::getSpriteIcon('actions-document-view') . '</a>';
+                       if ($this->extClassConf['name'] == TypoScriptTemplateInformationModuleFunctionController::class) {
                                // NEW button
                                $urlParameters = array(
                                        'id' => $this->id,
                                        'template' => 'all',
                                        'createExtension' => 'new'
                                );
-                               $buttons['new'] = '<a href="' . htmlspecialchars(BackendUtility::getModuleUrl('web_ts', $urlParameters)) . '" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:db_new.php.pagetitle', TRUE) . '">' . IconUtility::getSpriteIcon('actions-document-new') . '</a>';
+                               $buttons['new'] = '<a href="' . htmlspecialchars(BackendUtility::getModuleUrl('web_ts', $urlParameters)) . '" title="' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:db_new.php.pagetitle', TRUE) . '">' . IconUtility::getSpriteIcon('actions-document-new') . '</a>';
                                if (!empty($this->e) && !GeneralUtility::_POST('saveclose')) {
                                        // no NEW-button while edit
                                        $buttons['new'] = '';
                                        // SAVE button
                                        $buttons['save'] = IconUtility::getSpriteIcon('actions-document-save', array(
-                                               'html' => '<input type="image" class="c-inputButton" name="submit" src="clear.gif" ' . 'title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:rm.saveDoc', TRUE) . '" ' . 'value="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:rm.saveDoc', TRUE) . '" ' . '/>'
+                                               'html' => '<input type="image" class="c-inputButton" name="submit" src="clear.gif" ' . 'title="' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:rm.saveDoc', TRUE) . '" ' . 'value="' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:rm.saveDoc', TRUE) . '" ' . '/>'
                                        ));
                                        // SAVE AND CLOSE button
                                        $buttons['save_close'] = IconUtility::getSpriteIcon('actions-document-save-close', array(
-                                               'html' => '<input type="image" class="c-inputButton" name="saveclose" src="clear.gif" ' . 'title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:rm.saveCloseDoc', TRUE) . '" ' . 'value="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:rm.saveCloseDoc', TRUE) . '" ' . '/>'
+                                               'html' => '<input type="image" class="c-inputButton" name="saveclose" src="clear.gif" ' . 'title="' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:rm.saveCloseDoc', TRUE) . '" ' . 'value="' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:rm.saveCloseDoc', TRUE) . '" ' . '/>'
                                        ));
                                        // CLOSE button
                                        $url = BackendUtility::getModuleUrl('web_ts', array('id' => $this->id));
-                                       $buttons['close'] = '<a href="' . htmlspecialchars($url) . '" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:rm.closeDoc', TRUE) . '">' .  IconUtility::getSpriteIcon('actions-document-close') .'</a>';
+                                       $buttons['close'] = '<a href="' . htmlspecialchars($url) . '" title="' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:rm.closeDoc', TRUE) . '">' .  IconUtility::getSpriteIcon('actions-document-close') .'</a>';
                                }
-                       } elseif ($this->extClassConf['name'] === \TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateConstantEditorModuleFunctionController::class && count($this->MOD_MENU['constant_editor_cat'])) {
+                       } elseif ($this->extClassConf['name'] === TypoScriptTemplateConstantEditorModuleFunctionController::class && count($this->MOD_MENU['constant_editor_cat'])) {
                                // SAVE button
-                               $buttons['save'] = IconUtility::getSpriteIcon('actions-document-save', array('html' => '<input type="image" class="c-inputButton" name="submit" src="clear.gif" ' . 'title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:rm.saveDoc', TRUE) . '" ' . 'value="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:rm.saveDoc', TRUE) . '" ' . '/>'));
-                       } elseif ($this->extClassConf['name'] === \TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateObjectBrowserModuleFunctionController::class) {
+                               $buttons['save'] = IconUtility::getSpriteIcon('actions-document-save', array('html' => '<input type="image" class="c-inputButton" name="submit" src="clear.gif" ' . 'title="' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:rm.saveDoc', TRUE) . '" ' . 'value="' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:rm.saveDoc', TRUE) . '" ' . '/>'));
+                       } elseif ($this->extClassConf['name'] === TypoScriptTemplateObjectBrowserModuleFunctionController::class) {
                                if (!empty($this->sObj)) {
                                        // BACK
                                        $urlParameters = array(
                                                'id' => $this->id
                                        );
                                        $aHref = BackendUtility::getModuleUrl('web_ts', $urlParameters);
-                                       $buttons['back'] = '<a href="' . htmlspecialchars($aHref) . '" class="typo3-goBack" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.goBack', TRUE) . '">' . IconUtility::getSpriteIcon('actions-view-go-back') . '</a>';
+                                       $buttons['back'] = '<a href="' . htmlspecialchars($aHref) . '" class="typo3-goBack" title="' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:labels.goBack', TRUE) . '">' . IconUtility::getSpriteIcon('actions-view-go-back') . '</a>';
                                }
                        }
                        // Shortcut
-                       if ($GLOBALS['BE_USER']->mayMakeShortcut()) {
+                       if ($this->getBackendUser()->mayMakeShortcut()) {
                                $buttons['shortcut'] = $this->doc->makeShortcutIcon('id, edit_record, pointer, new_unique_uid, search_field, search_levels, showLimit', implode(',', array_keys($this->MOD_MENU)), $this->MCONF['name']);
                        }
                } else {
                        // Shortcut
-                       if ($GLOBALS['BE_USER']->mayMakeShortcut()) {
+                       if ($this->getBackendUser()->mayMakeShortcut()) {
                                $buttons['shortcut'] = $this->doc->makeShortcutIcon('id', '', $this->MCONF['name']);
                        }
                }
@@ -334,19 +344,24 @@ class TypoScriptTemplateModuleController extends \TYPO3\CMS\Backend\Module\BaseS
         */
        public function noTemplate($newStandardTemplate = 0) {
                // Defined global here!
-               $tmpl = GeneralUtility::makeInstance(\TYPO3\CMS\Core\TypoScript\ExtendedTemplateService::class);
-               /** @var $tmpl \TYPO3\CMS\Core\TypoScript\ExtendedTemplateService */
+               /** @var ExtendedTemplateService $tmpl */
+               $tmpl = GeneralUtility::makeInstance(ExtendedTemplateService::class);
+               $GLOBALS['tmpl'] = $tmpl;
+
                // Do not log time-performance information
                $tmpl->tt_track = FALSE;
                $tmpl->init();
-               $theOutput = '';
-               $flashMessage = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Messaging\FlashMessage::class, $GLOBALS['LANG']->getLL('noTemplateDescription') . '<br />' . $GLOBALS['LANG']->getLL('createTemplateToEditConfiguration'), $GLOBALS['LANG']->getLL('noTemplate'), \TYPO3\CMS\Core\Messaging\FlashMessage::INFO);
-               $theOutput .= $flashMessage->render();
+
+               $lang = $this->getLanguageService();
+
+               $flashMessage = GeneralUtility::makeInstance(FlashMessage::class, $lang->getLL('noTemplateDescription') . '<br />' . $lang->getLL('createTemplateToEditConfiguration'), $lang->getLL('noTemplate'), FlashMessage::INFO);
+               $theOutput = $flashMessage->render();
+
                // New standard?
                if ($newStandardTemplate) {
                        // Hook to change output, implemented for statictemplates
                        if (isset(
-                               $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][\TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateModuleController::class]['newStandardTemplateView']
+                               $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][TypoScriptTemplateModuleController::class]['newStandardTemplateView']
                        )) {
                                $selector = '';
                                $staticsText = '';
@@ -355,7 +370,7 @@ class TypoScriptTemplateModuleController extends \TYPO3\CMS\Backend\Module\BaseS
                                        'staticsText' => &$staticsText
                                );
                                GeneralUtility::callUserFunction(
-                                       $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][\TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateModuleController::class]['newStandardTemplateView'],
+                                       $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][TypoScriptTemplateModuleController::class]['newStandardTemplateView'],
                                        $reference,
                                        $this
                                );
@@ -367,14 +382,14 @@ class TypoScriptTemplateModuleController extends \TYPO3\CMS\Backend\Module\BaseS
                        }
                        // Extension?
                        $theOutput .= $this->doc->section(
-                               $GLOBALS['LANG']->getLL('newWebsite') . $staticsText,
-                               '<p>' . $GLOBALS['LANG']->getLL('newWebsiteDescription') . '</p>' . $selector . '<input class="btn btn-primary" type="submit" name="newWebsite" value="' . $GLOBALS['LANG']->getLL('newWebsiteAction') . '" />',
+                               $lang->getLL('newWebsite') . $staticsText,
+                               '<p>' . $lang->getLL('newWebsiteDescription') . '</p>' . $selector . '<input class="btn btn-primary" type="submit" name="newWebsite" value="' . $lang->getLL('newWebsiteAction') . '" />',
                                0, 1);
                }
                // Extension?
                $theOutput .= $this->doc->section(
-                       $GLOBALS['LANG']->getLL('extTemplate'),
-                       '<p>' . $GLOBALS['LANG']->getLL('extTemplateDescription') . '</p>' . '<input class="btn btn-default" type="submit" name="createExtension" value="' . $GLOBALS['LANG']->getLL('extTemplateAction') . '" />',
+                       $lang->getLL('extTemplate'),
+                       '<p>' . $lang->getLL('extTemplateDescription') . '</p>' . '<input class="btn btn-default" type="submit" name="createExtension" value="' . $lang->getLL('extTemplateAction') . '" />',
                        0, 1);
                // Go to first appearing...
                $first = $tmpl->ext_prevPageWithTemplate($this->id, $this->perms_clause);
@@ -384,22 +399,28 @@ class TypoScriptTemplateModuleController extends \TYPO3\CMS\Backend\Module\BaseS
                        );
                        $aHref = BackendUtility::getModuleUrl('web_ts', $urlParameters);
                        $theOutput .= $this->doc->section(
-                               $GLOBALS['LANG']->getLL('goToClosest'),
-                               sprintf('<p>' .$GLOBALS['LANG']->getLL('goToClosestDescription') . '</p>%s' . $GLOBALS['LANG']->getLL('goToClosestAction') . '%s', htmlspecialchars($first['title']), $first['uid'], '<a class="btn btn-default" href="' . htmlspecialchars($aHref) . '">', '</a>'),
+                               $lang->getLL('goToClosest'),
+                               sprintf('<p>' . $lang->getLL('goToClosestDescription') . '</p>%s' . $lang->getLL('goToClosestAction') . '%s', htmlspecialchars($first['title']), $first['uid'], '<a class="btn btn-default" href="' . htmlspecialchars($aHref) . '">', '</a>'),
                                0, 1);
                }
                return $theOutput;
        }
 
+       /**
+        * Render template menu
+        *
+        * @return string
+        */
        public function templateMenu() {
-               // Defined global here!
-               $tmpl = GeneralUtility::makeInstance(\TYPO3\CMS\Core\TypoScript\ExtendedTemplateService::class);
-               /** @var $tmpl \TYPO3\CMS\Core\TypoScript\ExtendedTemplateService */
+               /** @var ExtendedTemplateService $tmpl */
+               $tmpl = GeneralUtility::makeInstance(ExtendedTemplateService::class);
+               $GLOBALS['tmpl'] = $tmpl;
+
                // Do not log time-performance information
                $tmpl->tt_track = FALSE;
                $tmpl->init();
+
                $all = $tmpl->ext_getAllTemplates($this->id, $this->perms_clause);
-               $menu = '';
                if (count($all) > 1) {
                        $this->MOD_MENU['templatesOnPage'] = array();
                        foreach ($all as $d) {
@@ -407,8 +428,7 @@ class TypoScriptTemplateModuleController extends \TYPO3\CMS\Backend\Module\BaseS
                        }
                }
                $this->MOD_SETTINGS = BackendUtility::getModuleData($this->MOD_MENU, GeneralUtility::_GP('SET'), $this->MCONF['name'], $this->modMenu_type, $this->modMenu_dontValidateList, $this->modMenu_setDefaultList);
-               $menu = BackendUtility::getFuncMenu($this->id, 'SET[templatesOnPage]', $this->MOD_SETTINGS['templatesOnPage'], $this->MOD_MENU['templatesOnPage']);
-               return $menu;
+               return BackendUtility::getFuncMenu($this->id, 'SET[templatesOnPage]', $this->MOD_SETTINGS['templatesOnPage'], $this->MOD_MENU['templatesOnPage']);
        }
 
        /**
@@ -420,9 +440,9 @@ class TypoScriptTemplateModuleController extends \TYPO3\CMS\Backend\Module\BaseS
         */
        public function createTemplate($id, $actTemplateId = 0) {
                $recData = array();
-               /** @var $tce \TYPO3\CMS\Core\DataHandling\DataHandler */
-               $tce = GeneralUtility::makeInstance(\TYPO3\CMS\Core\DataHandling\DataHandler::class);
-               $tce->stripslashes_values = 0;
+               /** @var DataHandler $tce */
+               $tce = GeneralUtility::makeInstance(DataHandler::class);
+               $tce->stripslashes_values = FALSE;
 
                if (GeneralUtility::_GP('createExtension') || GeneralUtility::_GP('createExtension_x')) {
                        $recData['sys_template']['NEW'] = array(
@@ -434,14 +454,14 @@ class TypoScriptTemplateModuleController extends \TYPO3\CMS\Backend\Module\BaseS
                } elseif (GeneralUtility::_GP('newWebsite')) {
                        // Hook to handle row data, implemented for statictemplates
                        if (isset(
-                               $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][\TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateModuleController::class]['newStandardTemplateHandler']
+                               $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][TypoScriptTemplateModuleController::class]['newStandardTemplateHandler']
                        )) {
                                $reference = array(
                                        'recData' => &$recData,
                                        'id' => $id,
                                );
                                GeneralUtility::callUserFunction(
-                                       $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][\TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateModuleController::class]['newStandardTemplateHandler'],
+                                       $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][TypoScriptTemplateModuleController::class]['newStandardTemplateHandler'],
                                        $reference,
                                        $this
                                );
@@ -449,7 +469,7 @@ class TypoScriptTemplateModuleController extends \TYPO3\CMS\Backend\Module\BaseS
                        } else {
                                $recData['sys_template']['NEW'] = array(
                                        'pid' => $id,
-                                       'title' => $GLOBALS['LANG']->getLL('titleNewSite'),
+                                       'title' => $this->getLanguageService()->getLL('titleNewSite'),
                                        'sorting' => 0,
                                        'root' => 1,
                                        'clear' => 3,
@@ -505,28 +525,30 @@ page.10.value = HELLO WORLD!
         * @return array
         */
        public function renderList($pArray, $lines = array(), $c = 0) {
-               if (is_array($pArray)) {
-                       reset($pArray);
-                       static $i;
-                       foreach ($pArray as $k => $v) {
-                               if (\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($k)) {
-                                       if (isset($pArray[$k . '_'])) {
-                                               $lines[] = '<tr class="' . ($i++ % 2 == 0 ? 'bgColor4' : 'bgColor6') . '">
-                                                       <td nowrap><img src="clear.gif" width="1" height="1" hspace=' . $c * 10 . ' align="top">' . '<a href="' . htmlspecialchars(GeneralUtility::linkThisScript(array('id' => $k))) . '">' . IconUtility::getSpriteIconForRecord('pages', BackendUtility::getRecordWSOL('pages', $k), array('title' => ('ID: ' . $k))) . GeneralUtility::fixed_lgd_cs($pArray[$k], 30) . '</a></td>
-                                                       <td>' . $pArray[($k . '_')]['count'] . '</td>
-                                                       <td>' . ($pArray[$k . '_']['root_max_val'] > 0 ? IconUtility::getSpriteIcon('status-status-checked') : '&nbsp;') . '</td>
-                                                       <td>' . ($pArray[$k . '_']['root_min_val'] == 0 ? IconUtility::getSpriteIcon('status-status-checked') : '&nbsp;') . '</td>
-                                                       </tr>';
-                                       } else {
-                                               $lines[] = '<tr class="' . ($i++ % 2 == 0 ? 'bgColor4' : 'bgColor6') . '">
-                                                       <td nowrap ><img src="clear.gif" width="1" height="1" hspace=' . $c * 10 . ' align=top>' . IconUtility::getSpriteIconForRecord('pages', BackendUtility::getRecordWSOL('pages', $k)) . GeneralUtility::fixed_lgd_cs($pArray[$k], 30) . '</td>
-                                                       <td></td>
-                                                       <td></td>
-                                                       <td></td>
-                                                       </tr>';
-                                       }
-                                       $lines = $this->renderList($pArray[$k . '.'], $lines, $c + 1);
+               static $i;
+
+               if (!is_array($pArray)) {
+                       return $lines;
+               }
+
+               foreach ($pArray as $k => $v) {
+                       if (MathUtility::canBeInterpretedAsInteger($k)) {
+                               if (isset($pArray[$k . '_'])) {
+                                       $lines[] = '<tr class="' . ($i++ % 2 == 0 ? 'bgColor4' : 'bgColor6') . '">
+                                               <td nowrap><img src="clear.gif" width="1" height="1" hspace=' . $c * 10 . ' align="top">' . '<a href="' . htmlspecialchars(GeneralUtility::linkThisScript(array('id' => $k))) . '">' . IconUtility::getSpriteIconForRecord('pages', BackendUtility::getRecordWSOL('pages', $k), array('title' => ('ID: ' . $k))) . GeneralUtility::fixed_lgd_cs($pArray[$k], 30) . '</a></td>
+                                               <td>' . $pArray[($k . '_')]['count'] . '</td>
+                                               <td>' . ($pArray[$k . '_']['root_max_val'] > 0 ? IconUtility::getSpriteIcon('status-status-checked') : '&nbsp;') . '</td>
+                                               <td>' . ($pArray[$k . '_']['root_min_val'] == 0 ? IconUtility::getSpriteIcon('status-status-checked') : '&nbsp;') . '</td>
+                                               </tr>';
+                               } else {
+                                       $lines[] = '<tr class="' . ($i++ % 2 == 0 ? 'bgColor4' : 'bgColor6') . '">
+                                               <td nowrap ><img src="clear.gif" width="1" height="1" hspace=' . $c * 10 . ' align=top>' . IconUtility::getSpriteIconForRecord('pages', BackendUtility::getRecordWSOL('pages', $k)) . GeneralUtility::fixed_lgd_cs($pArray[$k], 30) . '</td>
+                                               <td></td>
+                                               <td></td>
+                                               <td></td>
+                                               </tr>';
                                }
+                               $lines = $this->renderList($pArray[$k . '.'], $lines, $c + 1);
                        }
                }
                return $lines;
index c818cae..13c2691 100644 (file)
@@ -14,20 +14,33 @@ namespace TYPO3\CMS\Tstemplate\Controller;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Backend\Module\AbstractFunctionModule;
 use TYPO3\CMS\Backend\Utility\BackendUtility;
+use TYPO3\CMS\Backend\Utility\IconUtility;
+use TYPO3\CMS\Core\DataHandling\DataHandler;
+use TYPO3\CMS\Core\Messaging\FlashMessage;
+use TYPO3\CMS\Core\Messaging\FlashMessageService;
+use TYPO3\CMS\Core\TypoScript\ExtendedTemplateService;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\Utility\MathUtility;
+use TYPO3\CMS\Frontend\Page\PageRepository;
 
 /**
  * This class displays the submodule "TypoScript Object Browser" inside the Web > Template module
  *
  * @author Kasper Skårhøj <kasperYYYY@typo3.com>
  */
-class TypoScriptTemplateObjectBrowserModuleFunctionController extends \TYPO3\CMS\Backend\Module\AbstractFunctionModule {
+class TypoScriptTemplateObjectBrowserModuleFunctionController extends AbstractFunctionModule {
+
+       /**
+        * @var TypoScriptTemplateModuleController
+        */
+       public $pObj;
 
        /**
         * Init
         *
-        * @param object $pObj
+        * @param TypoScriptTemplateModuleController $pObj
         * @param array $conf
         * @return void
         */
@@ -43,22 +56,23 @@ class TypoScriptTemplateObjectBrowserModuleFunctionController extends \TYPO3\CMS
         * @return array
         */
        public function modMenu() {
-               $GLOBALS['LANG']->includeLLFile('EXT:tstemplate/Resources/Private/Language/locallang_objbrowser.xlf');
+               $lang = $this->getLanguageService();
+               $lang->includeLLFile('EXT:tstemplate/Resources/Private/Language/locallang_objbrowser.xlf');
                $modMenu = array(
                        'ts_browser_type' => array(
-                               'const' => $GLOBALS['LANG']->getLL('constants'),
-                               'setup' => $GLOBALS['LANG']->getLL('setup')
+                               'const' => $lang->getLL('constants'),
+                               'setup' => $lang->getLL('setup')
                        ),
                        'ts_browser_toplevel_setup' => array(
-                               '0' => $GLOBALS['LANG']->csConvObj->conv_case($GLOBALS['LANG']->charSet, $GLOBALS['LANG']->getLL('all'), 'toUpper')
+                               '0' => $lang->csConvObj->conv_case($lang->charSet, $lang->getLL('all'), 'toUpper')
                        ),
                        'ts_browser_toplevel_const' => array(
-                               '0' => $GLOBALS['LANG']->csConvObj->conv_case($GLOBALS['LANG']->charSet, $GLOBALS['LANG']->getLL('all'), 'toUpper')
+                               '0' => $lang->csConvObj->conv_case($lang->charSet, $lang->getLL('all'), 'toUpper')
                        ),
                        'ts_browser_const' => array(
-                               '0' => $GLOBALS['LANG']->getLL('plainSubstitution'),
-                               'subst' => $GLOBALS['LANG']->getLL('substitutedGreen'),
-                               'const' => $GLOBALS['LANG']->getLL('unsubstitutedGreen')
+                               '0' => $lang->getLL('plainSubstitution'),
+                               'subst' => $lang->getLL('substitutedGreen'),
+                               'const' => $lang->getLL('unsubstitutedGreen')
                        ),
                        'ts_browser_regexsearch' => '1',
                        'ts_browser_fixedLgd' => '1',
@@ -67,7 +81,7 @@ class TypoScriptTemplateObjectBrowserModuleFunctionController extends \TYPO3\CMS
                );
                foreach (array('setup', 'const') as $bType) {
                        $addKey = GeneralUtility::_GET('addKey');
-                       // If any plus-signs were clicked, it's registred.
+                       // If any plus-signs were clicked, it's registered.
                        if (is_array($addKey)) {
                                reset($addKey);
                                if (current($addKey)) {
@@ -75,7 +89,7 @@ class TypoScriptTemplateObjectBrowserModuleFunctionController extends \TYPO3\CMS
                                } else {
                                        unset($this->pObj->MOD_SETTINGS['ts_browser_TLKeys_' . $bType][key($addKey)]);
                                }
-                               $GLOBALS['BE_USER']->pushModuleData($this->pObj->MCONF['name'], $this->pObj->MOD_SETTINGS);
+                               $this->getBackendUserAuthentication()->pushModuleData($this->pObj->MCONF['name'], $this->pObj->MOD_SETTINGS);
                        }
                        if (count($this->pObj->MOD_SETTINGS['ts_browser_TLKeys_' . $bType])) {
                                $modMenu['ts_browser_toplevel_' . $bType]['-'] = '---';
@@ -88,10 +102,12 @@ class TypoScriptTemplateObjectBrowserModuleFunctionController extends \TYPO3\CMS
        /**
         * Verify TS objects
         *
+        * @todo UNUSED in Core; deprecate it, https://forge.typo3.org/issues/64134
+        *
         * @param array $propertyArray
         * @param string $parentType
         * @param string $parentValue
-        * @return array
+        * @return array|NULL
         */
        public function verify_TSobjects($propertyArray, $parentType, $parentValue) {
                $TSobjTable = array(
@@ -139,7 +155,7 @@ class TypoScriptTemplateObjectBrowserModuleFunctionController extends \TYPO3\CMS
                        $result = array();
                        if (is_array($propertyArray)) {
                                foreach ($propertyArray as $key => $val) {
-                                       if (\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($key)) {
+                                       if (MathUtility::canBeInterpretedAsInteger($key)) {
                                                // If num-arrays
                                                $result[$key] = $TSobjTable[$ObjectKind]['prop']['1,2,3'];
                                        } else {
@@ -150,34 +166,36 @@ class TypoScriptTemplateObjectBrowserModuleFunctionController extends \TYPO3\CMS
                        }
                        return $result;
                }
+               return NULL;
        }
 
        /**
         * Initialize editor
         *
+        * Initializes the module. Done in this function because we may need to re-initialize if data is submitted!
+        *
         * @param int $pageId
         * @param int $template_uid
         * @return int
         */
        public function initialize_editor($pageId, $template_uid = 0) {
-               // Initializes the module. Done in this function because we may need to re-initialize if data is submitted!
-               global $tmpl, $tplRow, $theConstants;
                // Defined global here!
-               $tmpl = GeneralUtility::makeInstance(\TYPO3\CMS\Core\TypoScript\ExtendedTemplateService::class);
+               $templateService = GeneralUtility::makeInstance(ExtendedTemplateService::class);
+               $GLOBALS['tmpl'] = $templateService;
+
                // Do not log time-performance information
-               $tmpl->tt_track = 0;
-               $tmpl->init();
+               $templateService->tt_track = FALSE;
+               $templateService->init();
+
                // Gets the rootLine
-               $sys_page = GeneralUtility::makeInstance(\TYPO3\CMS\Frontend\Page\PageRepository::class);
+               $sys_page = GeneralUtility::makeInstance(PageRepository::class);
                $rootLine = $sys_page->getRootLine($pageId);
                // This generates the constants/config + hierarchy info for the template.
-               $tmpl->runThroughTemplates($rootLine, $template_uid);
+               $templateService->runThroughTemplates($rootLine, $template_uid);
+
                // Get the row of the first VISIBLE template of the page. whereclause like the frontend.
-               $tplRow = $tmpl->ext_getFirstTemplate($pageId, $template_uid);
-               // IF there was a template...
-               if (is_array($tplRow)) {
-                       return 1;
-               }
+               $GLOBALS['tplRow'] = $templateService->ext_getFirstTemplate($pageId, $template_uid);
+               return is_array($GLOBALS['tplRow']);
        }
 
        /**
@@ -186,20 +204,26 @@ class TypoScriptTemplateObjectBrowserModuleFunctionController extends \TYPO3\CMS
         * @return string
         */
        public function main() {
-               global $tmpl, $tplRow, $theConstants;
+               $lang = $this->getLanguageService();
                $POST = GeneralUtility::_POST();
+               $documentTemplate = $this->getDocumentTemplate();
+
                // Checking for more than one template an if, set a menu...
                $manyTemplatesMenu = $this->pObj->templateMenu();
                $template_uid = 0;
                if ($manyTemplatesMenu) {
                        $template_uid = $this->pObj->MOD_SETTINGS['templatesOnPage'];
                }
-               // BUGBUG: Should we check if the user may at all read and write template-records???
                $bType = $this->pObj->MOD_SETTINGS['ts_browser_type'];
                $existTemplate = $this->initialize_editor($this->pObj->id, $template_uid);
+               $tplRow = $this->getTemplateRow();
                // initialize
+               $theOutput = '';
                if ($existTemplate) {
-                       $theOutput .= $this->pObj->doc->section($GLOBALS['LANG']->getLL('currentTemplate'), ' <img ' . \TYPO3\CMS\Backend\Utility\IconUtility::skinImg($GLOBALS['BACK_PATH'], \TYPO3\CMS\Backend\Utility\IconUtility::getIcon('sys_template', $tplRow)) . ' align="top" /> <strong>' . $this->pObj->linkWrapTemplateTitle($tplRow['title'], ($bType == 'setup' ? 'config' : 'constants')) . '</strong>' . htmlspecialchars((trim($tplRow['sitetitle']) ? ' (' . $tplRow['sitetitle'] . ')' : '')));
+                       $content = ' <img ' . IconUtility::skinImg($this->getBackPath(), IconUtility::getIcon('sys_template', $tplRow)) . ' align="top" /> <strong>'
+                               . $this->pObj->linkWrapTemplateTitle($tplRow['title'], ($bType == 'setup' ? 'config' : 'constants')) . '</strong>'
+                               . htmlspecialchars(trim($tplRow['sitetitle']) ? ' (' . $tplRow['sitetitle'] . ')' : '');
+                       $theOutput .= $this->pObj->doc->section($lang->getLL('currentTemplate'), $content);
                        if ($manyTemplatesMenu) {
                                $theOutput .= $this->pObj->doc->section('', $manyTemplatesMenu);
                        }
@@ -217,23 +241,23 @@ class TypoScriptTemplateObjectBrowserModuleFunctionController extends \TYPO3\CMS
                                        if ($POST['add_property']) {
                                                $property = trim($POST['data'][$name]['name']);
                                                if (preg_replace('/[^a-zA-Z0-9_\\.]*/', '', $property) != $property) {
-                                                       $badPropertyMessage = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Messaging\FlashMessage::class, $GLOBALS['LANG']->getLL('noSpaces') . '<br />' . $GLOBALS['LANG']->getLL('nothingUpdated'), $GLOBALS['LANG']->getLL('badProperty'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
+                                                       $badPropertyMessage = GeneralUtility::makeInstance(FlashMessage::class, $lang->getLL('noSpaces') . '<br />' . $lang->getLL('nothingUpdated'), $lang->getLL('badProperty'), FlashMessage::ERROR);
                                                        $this->addFlashMessage($badPropertyMessage);
                                                } else {
                                                        $pline = $name . '.' . $property . ' = ' . trim($POST['data'][$name]['propertyValue']);
-                                                       $propertyAddedMessage = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Messaging\FlashMessage::class, htmlspecialchars($pline), $GLOBALS['LANG']->getLL('propertyAdded'));
+                                                       $propertyAddedMessage = GeneralUtility::makeInstance(FlashMessage::class, htmlspecialchars($pline), $lang->getLL('propertyAdded'));
                                                        $this->addFlashMessage($propertyAddedMessage);
                                                        $line .= LF . $pline;
                                                }
                                        } elseif ($POST['update_value']) {
                                                $pline = $name . ' = ' . trim($POST['data'][$name]['value']);
-                                               $updatedMessage = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Messaging\FlashMessage::class, htmlspecialchars($pline), $GLOBALS['LANG']->getLL('valueUpdated'));
+                                               $updatedMessage = GeneralUtility::makeInstance(FlashMessage::class, htmlspecialchars($pline), $lang->getLL('valueUpdated'));
                                                $this->addFlashMessage($updatedMessage);
                                                $line .= LF . $pline;
                                        } elseif ($POST['clear_object']) {
                                                if ($POST['data'][$name]['clearValue']) {
                                                        $pline = $name . ' >';
-                                                       $objectClearedMessage = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Messaging\FlashMessage::class, htmlspecialchars($pline), $GLOBALS['LANG']->getLL('objectCleared'));
+                                                       $objectClearedMessage = GeneralUtility::makeInstance(FlashMessage::class, htmlspecialchars($pline), $lang->getLL('objectCleared'));
                                                        $this->addFlashMessage($objectClearedMessage);
                                                        $line .= LF . $pline;
                                                }
@@ -246,8 +270,8 @@ class TypoScriptTemplateObjectBrowserModuleFunctionController extends \TYPO3\CMS
                                        $field = $bType == 'setup' ? 'config' : 'constants';
                                        $recData['sys_template'][$saveId][$field] = $tplRow[$field] . $line;
                                        // Create new  tce-object
-                                       $tce = GeneralUtility::makeInstance(\TYPO3\CMS\Core\DataHandling\DataHandler::class);
-                                       $tce->stripslashes_values = 0;
+                                       $tce = GeneralUtility::makeInstance(DataHandler::class);
+                                       $tce->stripslashes_values = FALSE;
                                        // Initialize
                                        $tce->start($recData, array());
                                        // Saved the stuff
@@ -260,10 +284,11 @@ class TypoScriptTemplateObjectBrowserModuleFunctionController extends \TYPO3\CMS
                        }
                }
                $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] = $tmpl->ext_depthKeys($tsbr, $this->pObj->MOD_SETTINGS['tsbrowser_depthKeys_' . $bType]);
+                       $this->pObj->MOD_SETTINGS['tsbrowser_depthKeys_' . $bType] = $templateService->ext_depthKeys($tsbr, $this->pObj->MOD_SETTINGS['tsbrowser_depthKeys_' . $bType]);
                        $update = 1;
                }
                if ($POST['Submit']) {
@@ -272,60 +297,58 @@ class TypoScriptTemplateObjectBrowserModuleFunctionController extends \TYPO3\CMS
                        $update = 1;
                }
                if ($update) {
-                       $GLOBALS['BE_USER']->pushModuleData($this->pObj->MCONF['name'], $this->pObj->MOD_SETTINGS);
+                       $this->getBackendUserAuthentication()->pushModuleData($this->pObj->MCONF['name'], $this->pObj->MOD_SETTINGS);
                }
-               $tmpl->matchAlternative = $this->pObj->MOD_SETTINGS['tsbrowser_conditions'];
-               $tmpl->matchAlternative[] = 'dummydummydummydummydummydummydummydummydummydummydummy';
+               $templateService->matchAlternative = $this->pObj->MOD_SETTINGS['tsbrowser_conditions'];
+               $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.
-               $tmpl->constantMode = $this->pObj->MOD_SETTINGS['ts_browser_const'];
-               if ($this->pObj->sObj && $tmpl->constantMode) {
-                       $tmpl->constantMode = 'untouched';
+               $templateService->constantMode = $this->pObj->MOD_SETTINGS['ts_browser_const'];
+               if ($this->pObj->sObj && $templateService->constantMode) {
+                       $templateService->constantMode = 'untouched';
                }
-               $tmpl->regexMode = $this->pObj->MOD_SETTINGS['ts_browser_regexsearch'];
-               $tmpl->fixedLgd = $this->pObj->MOD_SETTINGS['ts_browser_fixedLgd'];
-               $tmpl->linkObjects = TRUE;
-               $tmpl->ext_regLinenumbers = TRUE;
-               $tmpl->ext_regComments = $this->pObj->MOD_SETTINGS['ts_browser_showComments'];
-               $tmpl->bType = $bType;
+               $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;
                if ($this->pObj->MOD_SETTINGS['ts_browser_type'] == 'const') {
-                       $tmpl->ext_constants_BRP = (int)GeneralUtility::_GP('breakPointLN');
+                       $templateService->ext_constants_BRP = (int)GeneralUtility::_GP('breakPointLN');
                } else {
-                       $tmpl->ext_config_BRP = (int)GeneralUtility::_GP('breakPointLN');
+                       $templateService->ext_config_BRP = (int)GeneralUtility::_GP('breakPointLN');
                }
-               $tmpl->generateConfig();
+               $templateService->generateConfig();
                if ($bType == 'setup') {
-                       $theSetup = $tmpl->setup;
+                       $theSetup = $templateService->setup;
                } else {
-                       $theSetup = $tmpl->setup_constants;
+                       $theSetup = $templateService->setup_constants;
                }
                // EDIT A VALUE:
                if ($this->pObj->sObj) {
-                       list($theSetup, $theSetupValue) = $tmpl->ext_getSetup($theSetup, $this->pObj->sObj ? $this->pObj->sObj : '');
+                       list($theSetup, $theSetupValue) = $templateService->ext_getSetup($theSetup, $this->pObj->sObj ? $this->pObj->sObj : '');
                        if ($existTemplate) {
                                // Value
                                $out = '';
                                $out .= htmlspecialchars($this->pObj->sObj) . ' =<br />';
-                               $out .= '<input type="text" name="data[' . htmlspecialchars($this->pObj->sObj) . '][value]" value="' . htmlspecialchars($theSetupValue) . '"' . $GLOBALS['TBE_TEMPLATE']->formWidth(40) . ' />';
-                               $out .= '<input class="btn btn-default" type="submit" name="update_value" value="' . $GLOBALS['LANG']->getLL('updateButton') . '" />';
-                               $theOutput .= $this->pObj->doc->section($GLOBALS['LANG']->getLL('editProperty'), $out, 0, 0);
+                               $out .= '<input type="text" name="data[' . htmlspecialchars($this->pObj->sObj) . '][value]" value="' . htmlspecialchars($theSetupValue) . '"' . $documentTemplate->formWidth(40) . ' />';
+                               $out .= '<input class="btn btn-default" type="submit" name="update_value" value="' . $lang->getLL('updateButton') . '" />';
+                               $theOutput .= $this->pObj->doc->section($lang->getLL('editProperty'), $out, 0, 0);
                                // Property
-                               $out = '';
                                $out = '<nobr>' . htmlspecialchars($this->pObj->sObj) . '.';
-                               $out .= '<input type="text" name="data[' . htmlspecialchars($this->pObj->sObj) . '][name]"' . $GLOBALS['TBE_TEMPLATE']->formWidth(20) . ' /> = </nobr><br />';
-                               $out .= '<input type="text" name="data[' . htmlspecialchars($this->pObj->sObj) . '][propertyValue]"' . $GLOBALS['TBE_TEMPLATE']->formWidth(40) . ' />';
-                               $out .= '<input class="btn btn-default" type="submit" name="add_property" value="' . $GLOBALS['LANG']->getLL('addButton') . '" />';
+                               $out .= '<input type="text" name="data[' . htmlspecialchars($this->pObj->sObj) . '][name]"' . $documentTemplate->formWidth(20) . ' /> = </nobr><br />';
+                               $out .= '<input type="text" name="data[' . htmlspecialchars($this->pObj->sObj) . '][propertyValue]"' . $documentTemplate->formWidth(40) . ' />';
+                               $out .= '<input class="btn btn-default" type="submit" name="add_property" value="' . $lang->getLL('addButton') . '" />';
                                $theOutput .= $this->pObj->doc->spacer(20);
-                               $theOutput .= $this->pObj->doc->section($GLOBALS['LANG']->getLL('addProperty'), $out, 0, 0);
+                               $theOutput .= $this->pObj->doc->section($lang->getLL('addProperty'), $out, 0, 0);
                                // clear
-                               $out = '';
-                               $out = htmlspecialchars($this->pObj->sObj) . ' <strong>' . $GLOBALS['LANG']->csConvObj->conv_case($GLOBALS['LANG']->charSet, $GLOBALS['LANG']->getLL('clear'), 'toUpper') . '</strong> &nbsp;&nbsp;';
+                               $out = htmlspecialchars($this->pObj->sObj) . ' <strong>' . $lang->csConvObj->conv_case($lang->charSet, $lang->getLL('clear'), 'toUpper') . '</strong> &nbsp;&nbsp;';
                                $out .= '<input type="checkbox" name="data[' . htmlspecialchars($this->pObj->sObj) . '][clearValue]" value="1" />';
-                               $out .= '<input class="btn btn-default" type="submit" name="clear_object" value="' . $GLOBALS['LANG']->getLL('clearButton') . '" />';
+                               $out .= '<input class="btn btn-default" type="submit" name="clear_object" value="' . $lang->getLL('clearButton') . '" />';
                                $theOutput .= $this->pObj->doc->spacer(20);
-                               $theOutput .= $this->pObj->doc->section($GLOBALS['LANG']->getLL('clearObject'), $out, 0, 0);
+                               $theOutput .= $this->pObj->doc->section($lang->getLL('clearObject'), $out, 0, 0);
                                $theOutput .= $this->pObj->doc->spacer(10);
                        } else {
-                               $noTemplateMessage = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Messaging\FlashMessage::class, $GLOBALS['LANG']->getLL('noCurrentTemplate'), $GLOBALS['LANG']->getLL('edit'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
+                               $noTemplateMessage = GeneralUtility::makeInstance(FlashMessage::class, $lang->getLL('noCurrentTemplate'), $lang->getLL('edit'), FlashMessage::ERROR);
                                $this->addFlashMessage($noTemplateMessage);
                                $theOutput .= htmlspecialchars($this->pObj->sObj) . ' = <strong>' . htmlspecialchars($theSetupValue) . '</strong>';
                                $theOutput .= $this->pObj->doc->spacer(10);
@@ -339,26 +362,26 @@ class TypoScriptTemplateObjectBrowserModuleFunctionController extends \TYPO3\CMS
                        if (!$this->pObj->MOD_SETTINGS[('ts_browser_TLKeys_' . $bType)][$this->pObj->sObj]) {
                                if (count($theSetup)) {
                                        $out = '<a href="' . htmlspecialchars(($aHref . '&addKey[' . rawurlencode($this->pObj->sObj) . ']=1&SET[ts_browser_toplevel_' . $bType . ']=' . rawurlencode($this->pObj->sObj))) . '">';
-                                       $out .= sprintf($GLOBALS['LANG']->getLL('addKey'), htmlspecialchars($this->pObj->sObj));
+                                       $out .= sprintf($lang->getLL('addKey'), htmlspecialchars($this->pObj->sObj));
                                }
                        } else {
                                $out = '<a href="' . htmlspecialchars(($aHref . '&addKey[' . rawurlencode($this->pObj->sObj) . ']=0&SET[ts_browser_toplevel_' . $bType . ']=0')) . '">';
-                               $out .= sprintf($GLOBALS['LANG']->getLL('removeKey'), htmlspecialchars($this->pObj->sObj));
+                               $out .= sprintf($lang->getLL('removeKey'), htmlspecialchars($this->pObj->sObj));
                        }
                        if ($out) {
                                $theOutput .= $this->pObj->doc->divider(5);
                                $theOutput .= $this->pObj->doc->section('', $out);
                        }
                        // back
-                       $out = $GLOBALS['LANG']->getLL('back');
+                       $out = $lang->getLL('back');
                        $out = '<a href="' . htmlspecialchars($aHref) . '"><strong>' . $out . '</strong></a>';
                        $theOutput .= $this->pObj->doc->divider(5);
                        $theOutput .= $this->pObj->doc->section('', $out);
                } else {
-                       $tmpl->tsbrowser_depthKeys = $this->pObj->MOD_SETTINGS['tsbrowser_depthKeys_' . $bType];
+                       $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
-                               $tmpl->tsbrowser_depthKeys = $tmpl->ext_getSearchKeys($theSetup, '', GeneralUtility::_POST('search_field'), array());
+                               $templateService->tsbrowser_depthKeys = $templateService->ext_getSearchKeys($theSetup, '', GeneralUtility::_POST('search_field'), array());
                        }
                        $theOutput .= '
                                <div class="tsob-menu">
@@ -366,27 +389,27 @@ class TypoScriptTemplateObjectBrowserModuleFunctionController extends \TYPO3\CMS
                        if(is_array($this->pObj->MOD_MENU['ts_browser_type']) && count($this->pObj->MOD_MENU['ts_browser_type']) > 1){
                                $theOutput .= '
                                                <div class="form-group">
-                                                       <label class="control-label">' . $GLOBALS['LANG']->getLL('browse') . '</label>'
+                                                       <label class="control-label">' . $lang->getLL('browse') . '</label>'
                                                        . BackendUtility::getFuncMenu($this->pObj->id, 'SET[ts_browser_type]', $bType, $this->pObj->MOD_MENU['ts_browser_type']). '
                                                </div>';
                        }
                        if(is_array($this->pObj->MOD_MENU['ts_browser_toplevel_' . $bType]) && count($this->pObj->MOD_MENU['ts_browser_toplevel_' . $bType]) > 1){
                                $theOutput .= '
                                                <div class="form-group">
-                                                       <label class="control-label" for="ts_browser_toplevel_' . $bType . '">' . $GLOBALS['LANG']->getLL('objectList') . '</label> '
+                                                       <label class="control-label" for="ts_browser_toplevel_' . $bType . '">' . $lang->getLL('objectList') . '</label> '
                                                        . BackendUtility::getFuncMenu($this->pObj->id, 'SET[ts_browser_toplevel_' . $bType . ']', $this->pObj->MOD_SETTINGS['ts_browser_toplevel_' . $bType], $this->pObj->MOD_MENU['ts_browser_toplevel_' . $bType]) . '
                                                </div>';
                        }
                        $theOutput .= '
                                                <div class="form-group">
-                                                       <label class="control-label" for="search_field">' . $GLOBALS['LANG']->getLL('search') . '</label>
-                                                       <input class="form-control" type="search" name="search_field" id="search_field" value="' . htmlspecialchars($POST['search_field']) . '"' . $GLOBALS['TBE_TEMPLATE']->formWidth(20) . '/>
+                                                       <label class="control-label" for="search_field">' . $lang->getLL('search') . '</label>
+                                                       <input class="form-control" type="search" name="search_field" id="search_field" value="' . htmlspecialchars($POST['search_field']) . '"' . $documentTemplate->formWidth(20) . '/>
                                                </div>
-                                               <input class="btn btn-default tsob-search-submit" type="submit" name="search" value="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xlf:search') . '" />
+                                               <input class="btn btn-default tsob-search-submit" type="submit" name="search" value="' . $lang->sL('LLL:EXT:lang/locallang_common.xlf:search') . '" />
                                        </div>
                                        <div class="checkbox">
                                                <label for="checkTs_browser_regexsearch">
-                                                       ' . BackendUtility::getFuncCheck($this->pObj->id, 'SET[ts_browser_regexsearch]', $this->pObj->MOD_SETTINGS['ts_browser_regexsearch'], '', '', 'id="checkTs_browser_regexsearch"') . $GLOBALS['LANG']->getLL('regExp') . '
+                                                       ' . BackendUtility::getFuncCheck($this->pObj->id, 'SET[ts_browser_regexsearch]', $this->pObj->MOD_SETTINGS['ts_browser_regexsearch'], '', '', 'id="checkTs_browser_regexsearch"') . $lang->getLL('regExp') . '
                                                </label>
                                        </div>
                                </div>';
@@ -394,37 +417,33 @@ class TypoScriptTemplateObjectBrowserModuleFunctionController extends \TYPO3\CMS
                        if (!$theKey || !str_replace('-', '', $theKey)) {
                                $theKey = '';
                        }
-                       list($theSetup, $theSetupValue) = $tmpl->ext_getSetup($theSetup, $this->pObj->MOD_SETTINGS['ts_browser_toplevel_' . $bType] ? $this->pObj->MOD_SETTINGS['ts_browser_toplevel_' . $bType] : '');
-                       $tree = $tmpl->ext_getObjTree($theSetup, $theKey, '', '', $theSetupValue, $this->pObj->MOD_SETTINGS['ts_browser_alphaSort']);
-                       $tree = $tmpl->substituteCMarkers($tree);
+                       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);
                        $urlParameters = array(
                                'id' => $this->pObj->id
                        );
                        $aHref = BackendUtility::getModuleUrl('web_ts', $urlParameters);
                        // Parser Errors:
                        $pEkey = $bType == 'setup' ? 'config' : 'constants';
-                       if (count($tmpl->parserErrors[$pEkey])) {
+                       if (count($templateService->parserErrors[$pEkey])) {
                                $errMsg = array();
-                               $templateAnalyzerInstalled = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('tstemplate');
-                               foreach ($tmpl->parserErrors[$pEkey] as $inf) {
-                                       $errorLink = '';
-                                       if ($templateAnalyzerInstalled) {
-                                               $errorLink = ' <a href="' . htmlspecialchars(($aHref . '&SET[function]=TYPO3\\CMS\\Tstemplate\\Controller\\TemplateAnalyzerModuleFunctionController&template=all&SET[ts_analyzer_checkLinenum]=1#line-' . $inf[2])) . '">' . $GLOBALS['LANG']->getLL('errorShowDetails') . '</a>';
-                                       }
+                               foreach ($templateService->parserErrors[$pEkey] as $inf) {
+                                       $errorLink = ' <a href="' . htmlspecialchars(($aHref . '&SET[function]=TYPO3\\CMS\\Tstemplate\\Controller\\TemplateAnalyzerModuleFunctionController&template=all&SET[ts_analyzer_checkLinenum]=1#line-' . $inf[2])) . '">' . $lang->getLL('errorShowDetails') . '</a>';
                                        $errMsg[] = $inf[1] . ': &nbsp; &nbsp;' . $inf[0] . $errorLink;
                                }
                                $theOutput .= $this->pObj->doc->spacer(10);
-                               $flashMessage = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Messaging\FlashMessage::class, implode($errMsg, '<br />'), $GLOBALS['LANG']->getLL('errorsWarnings'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
+                               $flashMessage = GeneralUtility::makeInstance(FlashMessage::class, implode($errMsg, '<br />'), $lang->getLL('errorsWarnings'), FlashMessage::ERROR);
                                $theOutput .= $flashMessage->render();
                        }
 
                        if (isset($this->pObj->MOD_SETTINGS['ts_browser_TLKeys_' . $bType][$theKey])) {
-                               $remove = '<a href="' . htmlspecialchars(($aHref . '&addKey[' . $theKey . ']=0&SET[ts_browser_toplevel_' . $bType . ']=0')) . '">' . $GLOBALS['LANG']->getLL('removeKey') . '</a>';
+                               $remove = '<a href="' . htmlspecialchars(($aHref . '&addKey[' . $theKey . ']=0&SET[ts_browser_toplevel_' . $bType . ']=0')) . '">' . $lang->getLL('removeKey') . '</a>';
                        } else {
                                $remove = '';
                        }
 
-                       $label = $theKey ? $theKey : ($bType == 'setup' ? $GLOBALS['LANG']->csConvObj->conv_case($GLOBALS['LANG']->charSet, $GLOBALS['LANG']->getLL('setupRoot'), 'toUpper') : $GLOBALS['LANG']->csConvObj->conv_case($GLOBALS['LANG']->charSet, $GLOBALS['LANG']->getLL('constantRoot'), 'toUpper'));
+                       $label = $theKey ? $theKey : ($bType == 'setup' ? $lang->csConvObj->conv_case($lang->charSet, $lang->getLL('setupRoot'), 'toUpper') : $lang->csConvObj->conv_case($lang->charSet, $lang->getLL('constantRoot'), 'toUpper'));
                        $theOutput .= $this->pObj->doc->sectionEnd();
 
                        $theOutput .= '<div class="panel panel-default">';
@@ -437,27 +456,27 @@ class TypoScriptTemplateObjectBrowserModuleFunctionController extends \TYPO3\CMS
                        // second row options
                        $menu = '<div class="tsob-menu-row2">';
                        $menu .= '<div class="checkbox"><label for="checkTs_browser_showComments">' . BackendUtility::getFuncCheck($this->pObj->id, 'SET[ts_browser_showComments]', $this->pObj->MOD_SETTINGS['ts_browser_showComments'], '', '', 'id="checkTs_browser_showComments"');
-                       $menu .= $GLOBALS['LANG']->getLL('displayComments') . '</label></div>';
+                       $menu .= $lang->getLL('displayComments') . '</label></div>';
                        $menu .= '<div class="checkbox"><label for="checkTs_browser_alphaSort">' . BackendUtility::getFuncCheck($this->pObj->id, 'SET[ts_browser_alphaSort]', $this->pObj->MOD_SETTINGS['ts_browser_alphaSort'], '', '', 'id="checkTs_browser_alphaSort"');
-                       $menu .= $GLOBALS['LANG']->getLL('sortAlphabetically') . '</label></div>';
+                       $menu .= $lang->getLL('sortAlphabetically') . '</label></div>';
                        $menu .= '<div class="checkbox"><label for="checkTs_browser_fixedLgd">' . BackendUtility::getFuncCheck($this->pObj->id, 'SET[ts_browser_fixedLgd]', $this->pObj->MOD_SETTINGS['ts_browser_fixedLgd'], '', '', 'id="checkTs_browser_fixedLgd"');
-                       $menu .= $GLOBALS['LANG']->getLL('cropLines') . '</label></div>';
+                       $menu .= $lang->getLL('cropLines') . '</label></div>';
                        if ($bType == 'setup' && !$this->pObj->MOD_SETTINGS['ts_browser_fixedLgd']) {
-                               $menu .= '<br /><br /><label>' . $GLOBALS['LANG']->getLL('displayConstants') . '</label>';
+                               $menu .= '<br /><br /><label>' . $lang->getLL('displayConstants') . '</label>';
                                $menu .= BackendUtility::getFuncMenu($this->pObj->id, 'SET[ts_browser_const]', $this->pObj->MOD_SETTINGS['ts_browser_const'], $this->pObj->MOD_MENU['ts_browser_const']);
                        }
                        $menu .= '</div>';
-                       $theOutput .= $this->pObj->doc->section($GLOBALS['LANG']->getLL('displayOptions'), '<nobr>' . $menu . '</nobr>', 0, 1);
+                       $theOutput .= $this->pObj->doc->section($lang->getLL('displayOptions'), '<nobr>' . $menu . '</nobr>', 0, 1);
                        // Conditions:
-                       if (is_array($tmpl->sections) && !empty($tmpl->sections)) {
-                               $theOutput .= $this->pObj->doc->section($GLOBALS['LANG']->getLL('conditions'), '', 0, 1);
+                       if (is_array($templateService->sections) && !empty($templateService->sections)) {
+                               $theOutput .= $this->pObj->doc->section($lang->getLL('conditions'), '', 0, 1);
                                $out = '';
-                               foreach ($tmpl->sections as $key => $val) {
+                               foreach ($templateService->sections as $key => $val) {
                                        $out .= '<div class="checkbox"><label for="check' . $key . '">';
-                                       $out .= '<input class="checkbox" type="checkbox" name="conditions[' . $key . ']" id="check' . $key . '" value="' . htmlspecialchars($val) . '"' . ($this->pObj->MOD_SETTINGS['tsbrowser_conditions'][$key] ? ' checked' : '') . ' />' . $tmpl->substituteCMarkers(htmlspecialchars($val));
+                                       $out .= '<input class="checkbox" type="checkbox" name="conditions[' . $key . ']" id="check' . $key . '" value="' . htmlspecialchars($val) . '"' . ($this->pObj->MOD_SETTINGS['tsbrowser_conditions'][$key] ? ' checked' : '') . ' />' . $templateService->substituteCMarkers(htmlspecialchars($val));
                                        $out .= '</label></div>';
                                }
-                               $theOutput .=  '<div class="tsob-menu-row2">' . $out . '</div><input class="btn btn-default" type="submit" name="Submit" value="' . $GLOBALS['LANG']->getLL('setConditions') . '" />';
+                               $theOutput .=  '<div class="tsob-menu-row2">' . $out . '</div><input class="btn btn-default" type="submit" name="Submit" value="' . $lang->getLL('setConditions') . '" />';
                        }
                        // Ending section:
                        $theOutput .= $this->pObj->doc->sectionEnd();
@@ -468,15 +487,29 @@ class TypoScriptTemplateObjectBrowserModuleFunctionController extends \TYPO3\CMS
        /**
         * Add flash message to queue
         *
-        * @param \TYPO3\CMS\Core\Messaging\FlashMessage $flasgMessage
+        * @param FlashMessage $flashMessage
         * @return void
         */
-       protected function addFlashMessage(\TYPO3\CMS\Core\Messaging\FlashMessage $flashMessage) {
-               /** @var $flashMessageService \TYPO3\CMS\Core\Messaging\FlashMessageService */
-               $flashMessageService = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Messaging\FlashMessageService::class);
+       protected function addFlashMessage(FlashMessage $flashMessage) {
+               /** @var $flashMessageService FlashMessageService */
+               $flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class);
                /** @var $defaultFlashMessageQueue \TYPO3\CMS\Core\Messaging\FlashMessageQueue */
                $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
                $defaultFlashMessageQueue->enqueue($flashMessage);
        }
 
+       /**
+        * @return ExtendedTemplateService
+        */
+       protected function getExtendedTemplateService() {
+               return $GLOBALS['tmpl'];
+       }
+
+       /**
+        * @return array
+        */
+       protected function getTemplateRow() {
+               return $GLOBALS['tplRow'];
+       }
+
 }