[FOLLOWUP][TASK] Streamline usage of PageRenderer 39/41239/5
authorWouter Wolters <typo3@wouterwolters.nl>
Tue, 14 Jul 2015 20:20:22 +0000 (22:20 +0200)
committerGeorg Ringer <georg.ringer@gmail.com>
Tue, 14 Jul 2015 21:33:02 +0000 (23:33 +0200)
Use local variable in FormEngine for PageRenderer,
remove redeclared function in TriggerViewHelper and
solve problem with public getPageRenderer() deprecation.

Releases: master
Resolves: #68074
Change-Id: Ifc7325055189df6c1ff93c308bd8911262d7fe67
Reviewed-on: http://review.typo3.org/41239
Reviewed-by: Nicole Cordes <typo3@cordes.co>
Tested-by: Nicole Cordes <typo3@cordes.co>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
typo3/sysext/backend/Classes/Form/FormEngine.php
typo3/sysext/backend/Classes/Template/DocumentTemplate.php
typo3/sysext/core/Documentation/Changelog/master/Deprecation-68074-DeprecateGetPageRenderer.rst
typo3/sysext/extensionmanager/Classes/ViewHelpers/Be/TriggerViewHelper.php
typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php

index 7fc64f0..b8ac143 100644 (file)
@@ -1231,31 +1231,32 @@ class FormEngine {
                                FormEngineValidation.registerReady();
                        }';
 
+                       $pageRenderer = $this->getPageRenderer();
                        foreach ($this->requireJsModules as $moduleName => $callbacks) {
                                if (!is_array($callbacks)) {
                                        $callbacks = array($callbacks);
                                }
                                foreach ($callbacks as $callback) {
-                                       $this->getPageRenderer()->loadRequireJsModule($moduleName, $callback);
+                                       $pageRenderer->loadRequireJsModule($moduleName, $callback);
                                }
                        }
-                       $this->getPageRenderer()->loadPrototype();
-                       $this->getPageRenderer()->loadJquery();
-                       $this->getPageRenderer()->loadExtJS();
+                       $pageRenderer->loadPrototype();
+                       $pageRenderer->loadJquery();
+                       $pageRenderer->loadExtJS();
                        // rtehtmlarea needs extjs quick tips (?)
-                       $this->getPageRenderer()->enableExtJSQuickTips();
+                       $pageRenderer->enableExtJSQuickTips();
                        $beUserAuth = $this->getBackendUserAuthentication();
                        // Make textareas resizable and flexible ("autogrow" in height)
                        $textareaSettings = array(
                                'autosize'  => (bool)$beUserAuth->uc['resizeTextareas_Flexible']
                        );
-                       $this->getPageRenderer()->addInlineSettingArray('Textarea', $textareaSettings);
+                       $pageRenderer->addInlineSettingArray('Textarea', $textareaSettings);
 
                        $this->loadJavascriptLib('sysext/backend/Resources/Public/JavaScript/jsfunc.tbe_editor.js');
-                       $this->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/ValueSlider');
+                       $pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/ValueSlider');
                        // Needed for FormEngine manipulation (date picker)
                        $dateFormat = ($GLOBALS['TYPO3_CONF_VARS']['SYS']['USdateFormat'] ? array('MM-DD-YYYY', 'HH:mm MM-DD-YYYY') : array('DD-MM-YYYY', 'HH:mm DD-MM-YYYY'));
-                       $this->getPageRenderer()->addInlineSetting('DateTimePicker', 'DateFormat', $dateFormat);
+                       $pageRenderer->addInlineSetting('DateTimePicker', 'DateFormat', $dateFormat);
 
                        // support placeholders for IE9 and lower
                        $clientInfo = GeneralUtility::clientInfo();
@@ -1264,13 +1265,13 @@ class FormEngine {
                        }
 
                        // @todo: remove scriptaclous once suggest & flex form foo is moved to RequireJS, see #55575
-                       $this->getPageRenderer()->loadScriptaculous();
+                       $pageRenderer->loadScriptaculous();
                        $this->loadJavascriptLib('sysext/backend/Resources/Public/JavaScript/jsfunc.tceforms_suggest.js');
 
-                       $this->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Filelist/FileListLocalisation');
-                       $this->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/DragUploader');
+                       $pageRenderer->loadRequireJsModule('TYPO3/CMS/Filelist/FileListLocalisation');
+                       $pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/DragUploader');
 
-                       $this->getPageRenderer()->addInlineLanguagelabelFile(
+                       $pageRenderer->addInlineLanguagelabelFile(
                                \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('lang') . 'locallang_core.xlf',
                                'file_upload'
                        );
@@ -1329,11 +1330,12 @@ class FormEngine {
         */
        public function printNeededJSFunctions() {
                // set variables to be accessible for JS
-               $this->getPageRenderer()->addInlineSetting('FormEngine', 'formName', 'editform');
-               $this->getPageRenderer()->addInlineSetting('FormEngine', 'backPath', '');
+               $pageRenderer = $this->getPageRenderer();
+               $pageRenderer->addInlineSetting('FormEngine', 'formName', 'editform');
+               $pageRenderer->addInlineSetting('FormEngine', 'backPath', '');
 
                // Integrate JS functions for the element browser if such fields or IRRE fields were processed
-               $this->getPageRenderer()->addInlineSetting('FormEngine', 'legacyFieldChangedCb', 'function() { ' . $this->TBE_EDITOR_fieldChanged_func . ' };');
+               $pageRenderer->addInlineSetting('FormEngine', 'legacyFieldChangedCb', 'function() { ' . $this->TBE_EDITOR_fieldChanged_func . ' };');
 
                return $this->JSbottom('editform');
        }
index 1858b96..2ec11b0 100644 (file)
@@ -354,7 +354,7 @@ function jumpToUrl(URL) {
        /**
         * @var PageRenderer
         */
-       protected $pageRenderer;
+       protected $pageRenderer = NULL;
 
        /**
         * Alternative template file
@@ -385,7 +385,7 @@ function jumpToUrl(URL) {
         */
        public function __construct() {
                // Initializes the page rendering object:
-               $this->getPageRenderer();
+               $this->initPageRenderer();
 
                // load Legacy CSS Support
                $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/LegacyCssClasses');
@@ -434,37 +434,47 @@ function jumpToUrl(URL) {
        }
 
        /**
+        * Initializes the page renderer object
+        */
+       protected function initPageRenderer() {
+               if ($this->pageRenderer !== NULL) {
+                       return;
+               }
+               $this->pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
+               $this->pageRenderer->setLanguage($GLOBALS['LANG']->lang);
+               $this->pageRenderer->enableConcatenateFiles();
+               $this->pageRenderer->enableCompressCss();
+               $this->pageRenderer->enableCompressJavascript();
+               // Add all JavaScript files defined in $this->jsFiles to the PageRenderer
+               foreach ($this->jsFilesNoConcatenation as $file) {
+                       $this->pageRenderer->addJsFile(
+                               $GLOBALS['BACK_PATH'] . $file,
+                               'text/javascript',
+                               TRUE,
+                               FALSE,
+                               '',
+                               TRUE
+                       );
+               }
+               // Add all JavaScript files defined in $this->jsFiles to the PageRenderer
+               foreach ($this->jsFiles as $file) {
+                       $this->pageRenderer->addJsFile($GLOBALS['BACK_PATH'] . $file);
+               }
+               if ((int)$GLOBALS['TYPO3_CONF_VARS']['BE']['debug'] === 1) {
+                       $this->pageRenderer->enableDebugMode();
+               }
+       }
+
+       /**
         * Gets instance of PageRenderer configured with the current language, file references and debug settings
         *
         * @return PageRenderer
-        * @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8. This method will become protected then.
+        * @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8.
         */
        public function getPageRenderer() {
-               if (!isset($this->pageRenderer)) {
-                       $this->pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
-                       $this->pageRenderer->setLanguage($GLOBALS['LANG']->lang);
-                       $this->pageRenderer->enableConcatenateFiles();
-                       $this->pageRenderer->enableCompressCss();
-                       $this->pageRenderer->enableCompressJavascript();
-                       // Add all JavaScript files defined in $this->jsFiles to the PageRenderer
-                       foreach ($this->jsFilesNoConcatenation as $file) {
-                               $this->pageRenderer->addJsFile(
-                                       $GLOBALS['BACK_PATH'] . $file,
-                                       'text/javascript',
-                                       TRUE,
-                                       FALSE,
-                                       '',
-                                       TRUE
-                               );
-                       }
-                       // Add all JavaScript files defined in $this->jsFiles to the PageRenderer
-                       foreach ($this->jsFiles as $file) {
-                               $this->pageRenderer->addJsFile($GLOBALS['BACK_PATH'] . $file);
-                       }
-               }
-               if ((int)$GLOBALS['TYPO3_CONF_VARS']['BE']['debug'] === 1) {
-                       $this->pageRenderer->enableDebugMode();
-               }
+               GeneralUtility::logDeprecatedFunction();
+               $this->initPageRenderer();
+
                return $this->pageRenderer;
        }
 
index b215cd3..ba3bfbf 100644 (file)
@@ -16,9 +16,7 @@ The following public functions have been marked for deprecation as the instance
 Impact
 ======
 
-Using ``BackendController::getPageRenderer`` or ``FrontendDocumentTemplate::getPageRenderer`` will throw a deprecation message.
-The public functions ``DocumentTemplate::getPageRenderer`` and ``TypoScriptFrontendController::getPageRenderer`` will become
-protected methods with TYPO3 CMS 8. As those functions have to be used within the classes themselves no deprecation message can be thrown.
+Using one of these functions will throw a deprecation message.
 
 
 Migration
index ec06c9d..803810c 100644 (file)
@@ -55,11 +55,4 @@ class TriggerViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\Be\AbstractBackendV
                return '';
        }
 
-       /**
-        * @return PageRenderer
-        */
-       protected function getPageRenderer() {
-               return $this->objectManager->get(PageRenderer::class);
-       }
-
 }
index dfbca23..0c1f3ab 100644 (file)
@@ -798,7 +798,7 @@ class TypoScriptFrontendController {
        /**
         * @var PageRenderer
         */
-       protected $pageRenderer;
+       protected $pageRenderer = NULL;
 
        /**
         * The page cache object, use this to save pages to the cache and to
@@ -890,6 +890,7 @@ class TypoScriptFrontendController {
                $this->clientInfo = GeneralUtility::clientInfo();
                $this->uniqueString = md5(microtime());
                $this->csConvObj = GeneralUtility::makeInstance(CharsetConverter::class);
+               $this->initPageRenderer();
                // Call post processing function for constructor:
                if (is_array($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['tslib_fe-PostProc'])) {
                        $_params = array('pObj' => &$this);
@@ -902,6 +903,18 @@ class TypoScriptFrontendController {
        }
 
        /**
+        * Initializes the page renderer object
+        */
+       protected function initPageRenderer() {
+               if ($this->pageRenderer !== NULL) {
+                       return;
+               }
+               $this->pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
+               $this->pageRenderer->setTemplateFile('EXT:frontend/Resources/Private/Templates/MainPage.html');
+               $this->pageRenderer->setBackPath(TYPO3_mainDir);
+       }
+
+       /**
         * @param string $contentType
         * @internal Should only be used by TYPO3 core for now
         */
@@ -978,14 +991,12 @@ class TypoScriptFrontendController {
         * Gets instance of PageRenderer
         *
         * @return PageRenderer
-        * @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8. This method will become protected then.
+        * @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8.
         */
        public function getPageRenderer() {
-               if (!isset($this->pageRenderer)) {
-                       $this->pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
-                       $this->pageRenderer->setTemplateFile('EXT:frontend/Resources/Private/Templates/MainPage.html');
-                       $this->pageRenderer->setBackPath(TYPO3_mainDir);
-               }
+               GeneralUtility::logDeprecatedFunction();
+               $this->initPageRenderer();
+
                return $this->pageRenderer;
        }
 
@@ -2529,7 +2540,7 @@ class TypoScriptFrontendController {
                                        if ($this->pSetup['pageHeaderFooterTemplateFile']) {
                                                $file = $this->tmpl->getFileName($this->pSetup['pageHeaderFooterTemplateFile']);
                                                if ($file) {
-                                                       $this->getPageRenderer()->setTemplateFile($file);
+                                                       $this->pageRenderer->setTemplateFile($file);
                                                }
                                        }
                                }
@@ -3387,7 +3398,9 @@ class TypoScriptFrontendController {
                $this->additionalJavaScript = $this->config['INTincScript_ext']['additionalJavaScript'];
                $this->additionalCSS = $this->config['INTincScript_ext']['additionalCSS'];
                $this->divSection = '';
-               if (!empty($this->config['INTincScript_ext']['pageRenderer'])) {
+               if (empty($this->config['INTincScript_ext']['pageRenderer'])) {
+                       $this->initPageRenderer();
+               } else {
                        /** @var PageRenderer $pageRenderer */
                        $pageRenderer = unserialize($this->config['INTincScript_ext']['pageRenderer']);
                        $this->pageRenderer = $pageRenderer;
@@ -3410,7 +3423,7 @@ class TypoScriptFrontendController {
                                $this->convOutputCharset(implode(LF, $this->additionalFooterData), 'FD'),
                                $this->convOutputCharset($this->divSection, 'TDS'),
                        ),
-                       $this->getPageRenderer()->renderJavaScriptAndCssForProcessingOfUncachedContentObjects($this->content, $this->config['INTincScript_ext']['divKey'])
+                       $this->pageRenderer->renderJavaScriptAndCssForProcessingOfUncachedContentObjects($this->content, $this->config['INTincScript_ext']['divKey'])
                );
                // Replace again, because header and footer data and page renderer replacements may introduce additional placeholders (see #44825)
                $this->recursivelyReplaceIntPlaceholdersInContent();
@@ -4464,7 +4477,7 @@ class TypoScriptFrontendController {
                $this->languageDependencies = array();
                // Setting language key and split index:
                $this->lang = $this->config['config']['language'] ?: 'default';
-               $this->getPageRenderer()->setLanguage($this->lang);
+               $this->pageRenderer->setLanguage($this->lang);
 
                // Finding the requested language in this list based
                // on the $lang key being inputted to this function.