[!!!][TASK] Drop TBE_TEMPLATE variable 92/59492/6
authorBenni Mack <benni@typo3.org>
Fri, 18 Jan 2019 20:52:19 +0000 (21:52 +0100)
committerBenni Mack <benni@typo3.org>
Tue, 29 Jan 2019 07:19:29 +0000 (08:19 +0100)
The global variable TBE_TEMPLATE is not
necessary anymore, and is not available anymore.

The change is still ugly, as TBE_TEMPLATE
initializes the PageRenderer object
with necessary information, which should
become built inside PageRenderer for BE. This has been
moved to Backend's RequestHandler where this can be
abstracted further at a later point.

Resolves: #87567
Releases: master
Change-Id: If1cb184740f1e99c0aeca5ae19c85899d56f3f9a
Reviewed-on: https://review.typo3.org/59492
Tested-by: TYPO3com <noreply@typo3.com>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
Reviewed-by: Daniel Gorges <daniel.gorges@b13.de>
Tested-by: Daniel Gorges <daniel.gorges@b13.de>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
14 files changed:
typo3/sysext/backend/Classes/Controller/BackendController.php
typo3/sysext/backend/Classes/Controller/DummyController.php
typo3/sysext/backend/Classes/Controller/LoginController.php
typo3/sysext/backend/Classes/Controller/Wizard/AbstractWizardController.php
typo3/sysext/backend/Classes/Http/RequestHandler.php
typo3/sysext/backend/Classes/Middleware/LegacyBackendTemplateInitialization.php [deleted file]
typo3/sysext/backend/Classes/Template/DocumentTemplate.php
typo3/sysext/backend/Configuration/RequestMiddlewares.php
typo3/sysext/backend/Tests/Unit/Controller/LoginControllerTest.php
typo3/sysext/core/Classes/Page/PageRenderer.php
typo3/sysext/core/Classes/TypoScript/ExtendedTemplateService.php
typo3/sysext/core/Documentation/Changelog/master/Breaking-87567-GlobalVariableTBE_TEMPLATERemoved.rst [new file with mode: 0644]
typo3/sysext/install/Configuration/ExtensionScanner/Php/ArrayGlobalMatcher.php
typo3/sysext/recordlist/Classes/RecordList/DatabaseRecordList.php

index 131cfa2..8f4ce4f 100644 (file)
@@ -18,6 +18,7 @@ use Psr\Http\Message\ResponseInterface;
 use TYPO3\CMS\Backend\Domain\Repository\Module\BackendModuleRepository;
 use TYPO3\CMS\Backend\Module\ModuleLoader;
 use TYPO3\CMS\Backend\Routing\UriBuilder;
+use TYPO3\CMS\Backend\Template\DocumentTemplate;
 use TYPO3\CMS\Backend\Toolbar\ToolbarItemInterface;
 use TYPO3\CMS\Backend\Utility\BackendUtility;
 use TYPO3\CMS\Core\Configuration\ExtensionConfiguration;
@@ -259,7 +260,7 @@ class BackendController
         // Set document title:
         $title = $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'] ? $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'] . ' [TYPO3 CMS ' . TYPO3_version . ']' : 'TYPO3 CMS ' . TYPO3_version;
         // Renders the module page
-        $this->content = $this->getDocumentTemplate()->render($title, $view->render());
+        $this->content = GeneralUtility::makeInstance(DocumentTemplate::class)->render($title, $view->render());
         $hookConfiguration = ['content' => &$this->content];
         $this->executeHook('renderPostProcess', $hookConfiguration);
     }
@@ -611,14 +612,4 @@ class BackendController
     {
         return $GLOBALS['BE_USER'];
     }
-
-    /**
-     * Returns an instance of DocumentTemplate
-     *
-     * @return \TYPO3\CMS\Backend\Template\DocumentTemplate
-     */
-    protected function getDocumentTemplate()
-    {
-        return $GLOBALS['TBE_TEMPLATE'];
-    }
 }
index 8f5f27e..62b27a2 100644 (file)
@@ -17,6 +17,7 @@ namespace TYPO3\CMS\Backend\Controller;
 use Psr\Http\Message\ResponseInterface;
 use TYPO3\CMS\Backend\Template\DocumentTemplate;
 use TYPO3\CMS\Core\Http\HtmlResponse;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
 
 /**
  * '/empty' routing target returns dummy content.
@@ -31,18 +32,8 @@ class DummyController
      */
     public function mainAction(): ResponseInterface
     {
-        $documentTemplate = $this->getDocumentTemplate();
+        $documentTemplate = GeneralUtility::makeInstance(DocumentTemplate::class);
         $content = $documentTemplate->startPage('Dummy document') . $documentTemplate->endPage();
         return new HtmlResponse($content);
     }
-
-    /**
-     * Returns an instance of DocumentTemplate
-     *
-     * @return DocumentTemplate
-     */
-    protected function getDocumentTemplate()
-    {
-        return $GLOBALS['TBE_TEMPLATE'];
-    }
 }
index e4674bd..6a96d61 100644 (file)
@@ -96,6 +96,11 @@ class LoginController implements LoggerAwareInterface
     protected $view;
 
     /**
+     * @var DocumentTemplate
+     */
+    protected $documentTemplate;
+
+    /**
      * Injects the request and response objects for the current request or subrequest
      * As this controller goes only through the main() method, it is rather simple for now
      *
@@ -138,6 +143,7 @@ class LoginController implements LoggerAwareInterface
      */
     protected function init(ServerRequestInterface $request): void
     {
+        $this->documentTemplate = GeneralUtility::makeInstance(DocumentTemplate::class);
         $parsedBody = $request->getParsedBody();
         $queryParams = $request->getQueryParams();
         $this->validateAndSortLoginProviders();
@@ -211,7 +217,7 @@ class LoginController implements LoggerAwareInterface
                     '" can\'t be resolved. Please check if the file exists and the extension is activated.'
                 );
             }
-            $this->getDocumentTemplate()->inDocStylesArray[] = '
+            $this->documentTemplate->inDocStylesArray[] = '
                                .typo3-login-carousel-control.right,
                                .typo3-login-carousel-control.left,
                                .panel-login { border: 0; }
@@ -227,7 +233,7 @@ class LoginController implements LoggerAwareInterface
 
         // Add additional css to use the highlight color in the login screen
         if (!empty($extConf['loginHighlightColor'])) {
-            $this->getDocumentTemplate()->inDocStylesArray[] = '
+            $this->documentTemplate->inDocStylesArray[] = '
                                .btn-login.disabled, .btn-login[disabled], fieldset[disabled] .btn-login,
                                .btn-login.disabled:hover, .btn-login[disabled]:hover, fieldset[disabled] .btn-login:hover,
                                .btn-login.disabled:focus, .btn-login[disabled]:focus, fieldset[disabled] .btn-login:focus,
@@ -257,7 +263,7 @@ class LoginController implements LoggerAwareInterface
             } else {
                 $logo = 'EXT:backend/Resources/Public/Images/typo3_orange.svg';
             }
-            $this->getDocumentTemplate()->inDocStylesArray[] = '
+            $this->documentTemplate->inDocStylesArray[] = '
                                .typo3-login-logo .typo3-login-image { max-width: 150px; height:100%;}
                        ';
         }
@@ -289,9 +295,9 @@ class LoginController implements LoggerAwareInterface
         $loginProvider = GeneralUtility::makeInstance($this->loginProviders[$this->loginProviderIdentifier]['provider']);
         $loginProvider->render($this->view, $pageRenderer, $this);
 
-        $content = $this->getDocumentTemplate()->startPage('TYPO3 CMS Login: ' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']);
+        $content = $this->documentTemplate->startPage('TYPO3 CMS Login: ' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']);
         $content .= $this->view->render();
-        $content .= $this->getDocumentTemplate()->endPage();
+        $content .= $this->documentTemplate->endPage();
 
         return $content;
     }
@@ -361,7 +367,7 @@ class LoginController implements LoggerAwareInterface
         if ($this->loginRefresh) {
             $formProtection->setSessionTokenFromRegistry();
             $formProtection->persistSessionToken();
-            $this->getDocumentTemplate()->JScode .= GeneralUtility::wrapJS('
+            $this->documentTemplate->JScode .= GeneralUtility::wrapJS('
                                if (window.opener && window.opener.TYPO3 && window.opener.TYPO3.LoginRefresh) {
                                        window.opener.TYPO3.LoginRefresh.startTask();
                                        window.close();
@@ -577,14 +583,4 @@ class LoginController implements LoggerAwareInterface
     {
         return $GLOBALS['BE_USER'];
     }
-
-    /**
-     * Returns an instance of DocumentTemplate
-     *
-     * @return DocumentTemplate
-     */
-    protected function getDocumentTemplate(): DocumentTemplate
-    {
-        return $GLOBALS['TBE_TEMPLATE'];
-    }
 }
index 4a2255a..c458b55 100644 (file)
@@ -14,7 +14,6 @@ namespace TYPO3\CMS\Backend\Controller\Wizard;
  * 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\Localization\LanguageService;
@@ -78,14 +77,4 @@ class AbstractWizardController
     {
         return $GLOBALS['LANG'];
     }
-
-    /**
-     * Returns an instance of DocumentTemplate
-     *
-     * @return DocumentTemplate
-     */
-    protected function getDocumentTemplate()
-    {
-        return $GLOBALS['TBE_TEMPLATE'];
-    }
 }
index eecfe51..d117e39 100644 (file)
@@ -19,8 +19,8 @@ use Psr\Http\Message\ResponseInterface;
 use Psr\Http\Message\ServerRequestInterface;
 use Psr\Http\Server\RequestHandlerInterface;
 use TYPO3\CMS\Backend\Routing\Exception\InvalidRequestTokenException;
+use TYPO3\CMS\Backend\Template\DocumentTemplate;
 use TYPO3\CMS\Core\Http\RedirectResponse;
-use TYPO3\CMS\Core\Http\Response;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 
 /**
@@ -45,6 +45,10 @@ class RequestHandler implements RequestHandlerInterface
      */
     public function handle(ServerRequestInterface $request): ResponseInterface
     {
+        // This is currently placed here, as DocumentTemplate does some magic with
+        // PageRenderer (= which is a singleton) to populate Backend Styles from TBE_STYLES
+        // which should be built only if necessary, but currently done all over the place.
+        GeneralUtility::makeInstance(DocumentTemplate::class);
         try {
             // Check if the router has the available route and dispatch.
             $dispatcher = GeneralUtility::makeInstance(RouteDispatcher::class);
diff --git a/typo3/sysext/backend/Classes/Middleware/LegacyBackendTemplateInitialization.php b/typo3/sysext/backend/Classes/Middleware/LegacyBackendTemplateInitialization.php
deleted file mode 100644 (file)
index 1d483ec..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-<?php
-declare(strict_types = 1);
-namespace TYPO3\CMS\Backend\Middleware;
-
-/*
- * This file is part of the TYPO3 CMS project.
- *
- * It is free software; you can redistribute it and/or modify it under
- * the terms of the GNU General Public License, either version 2
- * of the License, or any later version.
- *
- * For the full copyright and license information, please read the
- * LICENSE.txt file that was distributed with this source code.
- *
- * The TYPO3 project - inspiring people to share!
- */
-
-use Psr\Http\Message\ResponseInterface;
-use Psr\Http\Message\ServerRequestInterface;
-use Psr\Http\Server\MiddlewareInterface;
-use Psr\Http\Server\RequestHandlerInterface;
-use TYPO3\CMS\Backend\Template\DocumentTemplate;
-use TYPO3\CMS\Core\Utility\GeneralUtility;
-
-/**
- * Initializes the global object $GLOBALS['TBE_TEMPLATE'] for legacy reasons
- *
- * @internal
- */
-class LegacyBackendTemplateInitialization implements MiddlewareInterface
-{
-    /**
-     * $GLOBALS['TBE_TEMPLATE'] is available then
-     *
-     * @param ServerRequestInterface $request
-     * @param RequestHandlerInterface $handler
-     * @return ResponseInterface
-     */
-    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
-    {
-        $GLOBALS['TBE_TEMPLATE'] = GeneralUtility::makeInstance(DocumentTemplate::class);
-        return $handler->handle($request);
-    }
-}
index 8558ddd..93aec4f 100644 (file)
@@ -172,28 +172,6 @@ function jumpToUrl(URL) {
     ];
 
     /**
-     * JavaScript files loaded for every page in the Backend
-     *
-     * @var array
-     */
-    protected $jsFiles = [];
-
-    /**
-     * JavaScript files loaded for every page in the Backend, but explicitly excluded from concatenation (useful for libraries etc.)
-     *
-     * @var array
-     */
-    protected $jsFilesNoConcatenation = [];
-
-    /**
-     * Indicates if a <div>-output section is open
-     *
-     * @var int
-     * @internal will be removed in TYPO3 v9
-     */
-    public $sectionFlag = 0;
-
-    /**
      * (Default) Class for wrapping <DIV>-tag of page. Is set in class extensions.
      *
      * @var string
@@ -244,7 +222,6 @@ function jumpToUrl(URL) {
      */
     public function __construct()
     {
-        // Initializes the page rendering object:
         $this->initPageRenderer();
 
         $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
@@ -288,31 +265,13 @@ function jumpToUrl(URL) {
      */
     protected function initPageRenderer()
     {
-        if ($this->pageRenderer !== null) {
-            return;
-        }
         $this->pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
         $this->pageRenderer->setLanguage($GLOBALS['LANG']->lang);
         $this->pageRenderer->enableConcatenateCss();
         $this->pageRenderer->enableConcatenateJavascript();
         $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(
-                $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($file);
-        }
-        if ((int)$GLOBALS['TYPO3_CONF_VARS']['BE']['debug'] === 1) {
+        if ($GLOBALS['TYPO3_CONF_VARS']['BE']['debug']) {
             $this->pageRenderer->enableDebugMode();
         }
     }
@@ -457,7 +416,6 @@ function jumpToUrl(URL) {
 
         $headerStart = '<!DOCTYPE html>';
         $this->pageRenderer->setXmlPrologAndDocType($headerStart);
-        $this->pageRenderer->setHeadTag('<head>' . LF . '<!-- TYPO3 Script ID: ' . htmlspecialchars($this->scriptID) . ' -->');
         header('Content-Type:text/html;charset=utf-8');
         $this->pageRenderer->setCharSet('utf-8');
         $this->pageRenderer->setMetaTag('name', 'generator', $this->generator());
index bc7fbc3..c5b2336 100644 (file)
@@ -47,13 +47,6 @@ return [
             ]
         ],
         /** internal: do not use or reference this middleware in your own code */
-        'typo3/cms-backend/legacy-document-template' => [
-            'target' => \TYPO3\CMS\Backend\Middleware\LegacyBackendTemplateInitialization::class,
-            'after' => [
-                'typo3/cms-backend/authentication'
-            ]
-        ],
-        /** internal: do not use or reference this middleware in your own code */
         'typo3/cms-backend/output-compression' => [
             'target' => \TYPO3\CMS\Backend\Middleware\OutputCompression::class,
             'after' => [
index b5b8c73..21222e2 100644 (file)
@@ -218,8 +218,6 @@ class LoginControllerTest extends UnitTestCase
         $authenticationProphecy->writeUC()->willReturn();
         $this->prophesizeFormProtection();
         $GLOBALS['BE_USER'] = $authenticationProphecy->reveal();
-        $documentTemplateProphecy = $this->prophesize(DocumentTemplate::class);
-        $GLOBALS['TBE_TEMPLATE'] = $documentTemplateProphecy->reveal();
 
         $this->loginControllerMock = $this->getAccessibleMock(
             LoginController::class,
@@ -232,10 +230,11 @@ class LoginControllerTest extends UnitTestCase
         $GLOBALS['BE_USER']->user['uid'] = 1;
         $this->loginControllerMock->method('isLoginInProgress')->willReturn(false);
         $this->loginControllerMock->_set('loginRefresh', true);
+        $this->loginControllerMock->_set('documentTemplate', $this->prophesize(DocumentTemplate::class)->reveal());
 
         $this->loginControllerMock->_call('checkRedirect', $this->prophesize(ServerRequest::class)->reveal());
 
-        self::assertContains('window.opener.TYPO3.LoginRefresh.startTask();', $documentTemplateProphecy->JScode);
+        self::assertContains('window.opener.TYPO3.LoginRefresh.startTask();', $this->loginControllerMock->_get('documentTemplate')->JScode);
     }
 
     /**
@@ -255,8 +254,6 @@ class LoginControllerTest extends UnitTestCase
         $authenticationProphecy->writeUC()->willReturn();
         $GLOBALS['BE_USER'] = $authenticationProphecy->reveal();
         $this->prophesizeFormProtection();
-        $documentTemplateProphecy = $this->prophesize(DocumentTemplate::class);
-        $GLOBALS['TBE_TEMPLATE'] = $documentTemplateProphecy->reveal();
 
         $this->loginControllerMock = $this->getAccessibleMock(
             LoginController::class,
@@ -269,10 +266,11 @@ class LoginControllerTest extends UnitTestCase
         $GLOBALS['BE_USER']->user['uid'] = 1;
         $this->loginControllerMock->method('isLoginInProgress')->willReturn(true);
         $this->loginControllerMock->_set('loginRefresh', true);
+        $this->loginControllerMock->_set('documentTemplate', $this->prophesize(DocumentTemplate::class)->reveal());
 
         $this->loginControllerMock->_call('checkRedirect', $this->prophesize(ServerRequest::class)->reveal());
 
-        self::assertContains('window.opener.TYPO3.LoginRefresh.startTask();', $documentTemplateProphecy->JScode);
+        self::assertContains('window.opener.TYPO3.LoginRefresh.startTask();', $this->loginControllerMock->_get('documentTemplate')->JScode);
     }
 
     /**
index 1fbd107..97e2ef4 100644 (file)
@@ -16,6 +16,7 @@ namespace TYPO3\CMS\Core\Page;
 
 use TYPO3\CMS\Backend\Routing\Router;
 use TYPO3\CMS\Backend\Routing\UriBuilder;
+use TYPO3\CMS\Backend\Template\DocumentTemplate;
 use TYPO3\CMS\Core\Cache\CacheManager;
 use TYPO3\CMS\Core\Cache\Exception\NoSuchCacheException;
 use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface;
@@ -2395,7 +2396,7 @@ class PageRenderer implements \TYPO3\CMS\Core\SingletonInterface
             } else {
                 $cssOptions = [];
                 if (TYPO3_MODE === 'BE') {
-                    $cssOptions = ['baseDirectories' => $GLOBALS['TBE_TEMPLATE']->getSkinStylesheetDirectories()];
+                    $cssOptions = ['baseDirectories' => GeneralUtility::makeInstance(DocumentTemplate::class)->getSkinStylesheetDirectories()];
                 }
                 $this->cssLibs = $this->getCompressor()->concatenateCssFiles($this->cssLibs, $cssOptions);
                 $this->cssFiles = $this->getCompressor()->concatenateCssFiles($this->cssFiles, $cssOptions);
index 1b1a910..dd5ff85 100644 (file)
@@ -14,7 +14,6 @@ namespace TYPO3\CMS\Core\TypoScript;
  * The TYPO3 project - inspiring people to share!
  */
 
-use TYPO3\CMS\Backend\Template\DocumentTemplate;
 use TYPO3\CMS\Backend\Utility\BackendUtility;
 use TYPO3\CMS\Core\Context\Context;
 use TYPO3\CMS\Core\Database\ConnectionPool;
@@ -1587,12 +1586,4 @@ class ExtendedTemplateService extends TemplateService
     {
         return $GLOBALS['LANG'];
     }
-
-    /**
-     * @return DocumentTemplate
-     */
-    protected function getDocumentTemplate()
-    {
-        return $GLOBALS['TBE_TEMPLATE'];
-    }
 }
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Breaking-87567-GlobalVariableTBE_TEMPLATERemoved.rst b/typo3/sysext/core/Documentation/Changelog/master/Breaking-87567-GlobalVariableTBE_TEMPLATERemoved.rst
new file mode 100644 (file)
index 0000000..b4907e9
--- /dev/null
@@ -0,0 +1,37 @@
+.. include:: ../../Includes.txt
+
+========================================================
+Breaking: #87567 - Global variable $TBE_TEMPLATE removed
+========================================================
+
+See :issue:`87567`
+
+Description
+===========
+
+The global variable used in TYPO3 Backend :php:`$GLOBALS[TBE_TEMPLATE]` which was available
+for legacy reasons for old backend modules as an instance of :php:`DocumentTemplate` a.k.a. `alt_doc`
+has been removed.
+
+The according PSR-15 middleware, which was marked as internal, is also removed.
+
+
+Impact
+======
+
+Calling any method or property on :php:`$GLOBALS[TBE_TEMPLATE]` will result in a fatal error.
+
+
+Affected Installations
+======================
+
+TYPO3 installations with older extensions using the global variable.
+
+
+Migration
+=========
+
+Instantiate the :php:`DocumentTemplate` class directly in the controller of the module, or migrate
+to :php:`ModuleTemplate` which is available since TYPO3 v7.
+
+.. index:: PHP-API, FullyScanned, ext:backend
\ No newline at end of file
index 8062110..7e27dd8 100644 (file)
@@ -26,4 +26,9 @@ return [
             'Breaking-87193-DeprecatedFunctionalityRemoved.rst',
         ],
     ],
+    '$GLOBALS[\'TBE_TEMPLATE\']' => [
+        'restFiles' => [
+            'Breaking-87567-GlobalVariableTBE_TEMPLATERemoved.rst',
+        ],
+    ],
 ];
index 6526458..26026a8 100644 (file)
@@ -730,7 +730,7 @@ class DatabaseRecordList
                 . $this->iconFactory->getIcon('actions-refresh', Icon::SIZE_SMALL)->render() . '</a>';
             // Shortcut
             if ($backendUser->mayMakeShortcut()) {
-                $buttons['shortcut'] = $this->getDocumentTemplate()->makeShortcutIcon(
+                $buttons['shortcut'] = GeneralUtility::makeInstance(DocumentTemplate::class)->makeShortcutIcon(
                     'id, M, imagemode, pointer, table, search_field, search_levels, showLimit, sortField, sortRev',
                     implode(',', array_keys($this->MOD_MENU)),
                     'web_list'
@@ -2875,14 +2875,6 @@ class DatabaseRecordList
     }
 
     /**
-     * @return DocumentTemplate
-     */
-    protected function getDocumentTemplate()
-    {
-        return $GLOBALS['TBE_TEMPLATE'];
-    }
-
-    /**
      * Initializes the list generation
      *
      * @param int $id Page id for which the list is rendered. Must be >= 0