[TASK] Remove dependency to TSFE from AdminPanel initialisation 23/61323/8
authorSusanne Moog <susanne.moog@typo3.com>
Fri, 19 Jul 2019 10:14:22 +0000 (12:14 +0200)
committerBenjamin Franzke <bfr@qbus.de>
Mon, 22 Jul 2019 07:01:50 +0000 (09:01 +0200)
The dependency of AdminPanel initialisation and TSFE has been dissolved.
Furthermore, the AdminPanel initialisation has been better integrated
into the PSR-15 middleware process by providing modules with an option
to manipulate the request object during initialisation.

Resolves: #88807
Releases: master
Change-Id: I9db2d3056d8216e15ff3303a7667ff7a4d8016e3
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/61323
Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Benjamin Franzke <bfr@qbus.de>
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Reviewed-by: Benjamin Franzke <bfr@qbus.de>
14 files changed:
typo3/sysext/adminpanel/Classes/Controller/MainController.php
typo3/sysext/adminpanel/Classes/Middleware/AdminPanelInitiator.php
typo3/sysext/adminpanel/Classes/ModuleApi/InitializableInterface.php
typo3/sysext/adminpanel/Classes/ModuleApi/RequestEnricherInterface.php [new file with mode: 0644]
typo3/sysext/adminpanel/Classes/Modules/CacheModule.php
typo3/sysext/adminpanel/Classes/Modules/Debug/Log.php
typo3/sysext/adminpanel/Classes/Modules/PreviewModule.php
typo3/sysext/adminpanel/Classes/Modules/TsDebug/TypoScriptWaterfall.php
typo3/sysext/adminpanel/Tests/Unit/Fixtures/MainModuleFixture.php
typo3/sysext/adminpanel/Tests/Unit/Middleware/AdminPanelInitiatorTest.php
typo3/sysext/adminpanel/Tests/Unit/Modules/PreviewModuleTest.php
typo3/sysext/core/Documentation/Changelog/master/Deprecation-88807-AdminPanelInitializableInterfaceHasBeenDeprecated.rst [new file with mode: 0644]
typo3/sysext/core/Documentation/Changelog/master/Feature-88807-AdminPanelRequestEnricherInterfaceHasBeenIntroduced.rst [new file with mode: 0644]
typo3/sysext/install/Configuration/ExtensionScanner/Php/ClassNameMatcher.php

index 6b543b3..e7e2c40 100644 (file)
@@ -23,6 +23,7 @@ use TYPO3\CMS\Adminpanel\ModuleApi\InitializableInterface;
 use TYPO3\CMS\Adminpanel\ModuleApi\ModuleDataStorageCollection;
 use TYPO3\CMS\Adminpanel\ModuleApi\ModuleInterface;
 use TYPO3\CMS\Adminpanel\ModuleApi\PageSettingsProviderInterface;
+use TYPO3\CMS\Adminpanel\ModuleApi\RequestEnricherInterface;
 use TYPO3\CMS\Adminpanel\ModuleApi\ShortInfoProviderInterface;
 use TYPO3\CMS\Adminpanel\ModuleApi\SubmoduleProviderInterface;
 use TYPO3\CMS\Adminpanel\Service\ConfigurationService;
@@ -89,16 +90,18 @@ class MainController implements SingletonInterface
      * Initializes settings for the admin panel.
      *
      * @param ServerRequestInterface $request
+     * @return ServerRequestInterface
      */
-    public function initialize(ServerRequestInterface $request): void
+    public function initialize(ServerRequestInterface $request): ServerRequestInterface
     {
         $this->modules = $this->moduleLoader->validateSortAndInitializeModules(
             $this->adminPanelModuleConfiguration
         );
 
         if (StateUtility::isActivatedForUser()) {
-            $this->initializeModules($request, $this->modules);
+            $request = $this->initializeModules($request, $this->modules);
         }
+        return $request;
     }
 
     /**
@@ -189,23 +192,30 @@ class MainController implements SingletonInterface
     /**
      * @param \Psr\Http\Message\ServerRequestInterface $request
      * @param \TYPO3\CMS\Adminpanel\ModuleApi\ModuleInterface[] $modules
+     * @return \Psr\Http\Message\ServerRequestInterface
      */
-    protected function initializeModules(ServerRequestInterface $request, array $modules): void
+    protected function initializeModules(ServerRequestInterface $request, array $modules): ServerRequestInterface
     {
         foreach ($modules as $module) {
             if (
-                ($module instanceof InitializableInterface)
+                ($module instanceof InitializableInterface || $module instanceof RequestEnricherInterface)
                 && (
                     (($module instanceof ConfigurableInterface) && $module->isEnabled())
                     || (!($module instanceof ConfigurableInterface))
                 )
             ) {
-                $module->initializeModule($request);
+                if ($module instanceof RequestEnricherInterface) {
+                    $request = $module->enrich($request);
+                } elseif ($module instanceof InitializableInterface) {
+                    $module->initializeModule($request);
+                    trigger_error('Method initializeModule is deprecated use RequestEnricherInterface::enrich instead.', E_USER_DEPRECATED);
+                }
             }
             if ($module instanceof SubmoduleProviderInterface) {
-                $this->initializeModules($request, $module->getSubModules());
+                $request = $this->initializeModules($request, $module->getSubModules());
             }
         }
+        return $request;
     }
 
     /**
index 91c178e..51ee5bb 100644 (file)
@@ -48,7 +48,7 @@ class AdminPanelInitiator implements MiddlewareInterface
             $adminPanelController = GeneralUtility::makeInstance(
                 MainController::class
             );
-            $adminPanelController->initialize($request);
+            $request = $adminPanelController->initialize($request);
         }
         return $handler->handle($request);
     }
index 9377e1a..95212eb 100644 (file)
@@ -29,6 +29,7 @@ use Psr\Http\Message\ServerRequestInterface;
  *
  * @see \TYPO3\CMS\Adminpanel\Middleware\AdminPanelInitiator::process()
  * @see \TYPO3\CMS\Adminpanel\Controller\MainController::initialize()
+ * @deprecated Use RequestEnricherInterface instead
  */
 interface InitializableInterface
 {
@@ -36,6 +37,7 @@ interface InitializableInterface
      * Initialize the module - runs early in a TYPO3 request
      *
      * @param ServerRequestInterface $request
+     * @deprecated
      */
     public function initializeModule(ServerRequestInterface $request): void;
 }
diff --git a/typo3/sysext/adminpanel/Classes/ModuleApi/RequestEnricherInterface.php b/typo3/sysext/adminpanel/Classes/ModuleApi/RequestEnricherInterface.php
new file mode 100644 (file)
index 0000000..32d3dbb
--- /dev/null
@@ -0,0 +1,45 @@
+<?php
+declare(strict_types = 1);
+
+namespace TYPO3\CMS\Adminpanel\ModuleApi;
+
+/*
+ * 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\ServerRequestInterface;
+
+/**
+ * Adminpanel interface to denote that a module has tasks to perform on initialization of the request and may enrich said request
+ *
+ * Modules that need to set data / options early in the rendering process to be able to collect data, should implement
+ * this interface - for example the log module uses the initialization to register the admin panel log collection early
+ * in the rendering process.
+ *
+ * Modules that manipulate the request based on their configuration should also implement this interface.
+ *
+ * Initialize is called in the PSR-15 middleware stack through admin panel initialisation via the AdminPanel MainController.
+ *
+ * @see \TYPO3\CMS\Adminpanel\Middleware\AdminPanelInitiator::process()
+ * @see \TYPO3\CMS\Adminpanel\Controller\MainController::initialize()
+ */
+interface RequestEnricherInterface
+{
+    /**
+     * Initialize the module - runs in the TYPO3 middleware stack at an early point
+     * may manipulate the current request
+     *
+     * @param ServerRequestInterface $request
+     * @return \Psr\Http\Message\ServerRequestInterface
+     */
+    public function enrich(ServerRequestInterface $request): ServerRequestInterface;
+}
index 281fc78..805e15e 100644 (file)
@@ -18,15 +18,15 @@ namespace TYPO3\CMS\Adminpanel\Modules;
 
 use Psr\Http\Message\ServerRequestInterface;
 use TYPO3\CMS\Adminpanel\ModuleApi\AbstractModule;
-use TYPO3\CMS\Adminpanel\ModuleApi\InitializableInterface;
 use TYPO3\CMS\Adminpanel\ModuleApi\PageSettingsProviderInterface;
+use TYPO3\CMS\Adminpanel\ModuleApi\RequestEnricherInterface;
 use TYPO3\CMS\Adminpanel\ModuleApi\ResourceProviderInterface;
 use TYPO3\CMS\Backend\Routing\UriBuilder;
+use TYPO3\CMS\Core\Routing\PageArguments;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Fluid\View\StandaloneView;
-use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
 
-class CacheModule extends AbstractModule implements PageSettingsProviderInterface, InitializableInterface, ResourceProviderInterface
+class CacheModule extends AbstractModule implements PageSettingsProviderInterface, RequestEnricherInterface, ResourceProviderInterface
 {
     /**
      * @return string
@@ -49,16 +49,22 @@ class CacheModule extends AbstractModule implements PageSettingsProviderInterfac
         $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
         $feCacheClear = $this->getBackendUser()->isAdmin() || $this->getBackendUser()->getTSConfig()['options.']['clearCache.']['pages'];
 
+        $pageId = 0;
+        $pageArguments = $GLOBALS['TYPO3_REQUEST']->getAttribute('routing');
+        if ($pageArguments instanceof PageArguments) {
+            $pageId = $pageArguments->getPageId();
+        }
+
         $view->assignMultiple(
             [
                 'isEnabled' => $this->getBackendUser()->uc['AdminPanel']['display_cache'],
                 'noCache' => $this->getBackendUser()->uc['AdminPanel']['cache_noCache'],
-                'currentId' => $this->getTypoScriptFrontendController()->id,
+                'currentId' => $pageId,
                 'clearPageCacheUrl' => $feCacheClear ? (string)$uriBuilder->buildUriFromRoute('tce_db', ['cacheCmd' => 'pages']) : '',
                 'clearCurrentPageCacheUrl' => (string)$uriBuilder->buildUriFromRoute(
                     'tce_db',
                     [
-                        'cacheCmd' => $this->getTypoScriptFrontendController()->id,
+                        'cacheCmd' => $pageId,
                     ]
                 ),
             ]
@@ -87,19 +93,12 @@ class CacheModule extends AbstractModule implements PageSettingsProviderInterfac
     /**
      * @inheritdoc
      */
-    public function initializeModule(ServerRequestInterface $request): void
+    public function enrich(ServerRequestInterface $request): ServerRequestInterface
     {
         if ($this->configurationService->getConfigurationOption('cache', 'noCache')) {
-            $this->getTypoScriptFrontendController()->set_no_cache('Admin Panel: No Caching', true);
+            $request = $request->withAttribute('noCache', true);
         }
-    }
-
-    /**
-     * @return TypoScriptFrontendController
-     */
-    protected function getTypoScriptFrontendController(): TypoScriptFrontendController
-    {
-        return $GLOBALS['TSFE'];
+        return $request;
     }
 
     /**
index b60a922..679b49b 100644 (file)
@@ -21,9 +21,9 @@ use TYPO3\CMS\Adminpanel\Log\InMemoryLogWriter;
 use TYPO3\CMS\Adminpanel\ModuleApi\AbstractSubModule;
 use TYPO3\CMS\Adminpanel\ModuleApi\ContentProviderInterface;
 use TYPO3\CMS\Adminpanel\ModuleApi\DataProviderInterface;
-use TYPO3\CMS\Adminpanel\ModuleApi\InitializableInterface;
 use TYPO3\CMS\Adminpanel\ModuleApi\ModuleData;
 use TYPO3\CMS\Adminpanel\ModuleApi\ModuleSettingsProviderInterface;
+use TYPO3\CMS\Adminpanel\ModuleApi\RequestEnricherInterface;
 use TYPO3\CMS\Adminpanel\Service\ConfigurationService;
 use TYPO3\CMS\Core\Log\LogLevel;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
@@ -34,7 +34,7 @@ use TYPO3\CMS\Fluid\View\StandaloneView;
  *
  * @internal
  */
-class Log extends AbstractSubModule implements DataProviderInterface, ContentProviderInterface, ModuleSettingsProviderInterface, InitializableInterface
+class Log extends AbstractSubModule implements DataProviderInterface, ContentProviderInterface, ModuleSettingsProviderInterface, RequestEnricherInterface
 {
     /**
      * @var int
@@ -178,7 +178,7 @@ class Log extends AbstractSubModule implements DataProviderInterface, ContentPro
     /**
      * @inheritdoc
      */
-    public function initializeModule(ServerRequestInterface $request): void
+    public function enrich(ServerRequestInterface $request): ServerRequestInterface
     {
         $this->logLevel = $this->getConfigOption('startLevel');
 
@@ -189,6 +189,7 @@ class Log extends AbstractSubModule implements DataProviderInterface, ContentPro
         $GLOBALS['TYPO3_CONF_VARS']['LOG'] = array_filter(
             $configWithInMemoryWriter
         );
+        return $request;
     }
 
     protected function setLoggingConfigRecursive(array $logConfig): array
index 32ba16b..2b78bfd 100644 (file)
@@ -18,24 +18,23 @@ namespace TYPO3\CMS\Adminpanel\Modules;
 
 use Psr\Http\Message\ServerRequestInterface;
 use TYPO3\CMS\Adminpanel\ModuleApi\AbstractModule;
-use TYPO3\CMS\Adminpanel\ModuleApi\InitializableInterface;
 use TYPO3\CMS\Adminpanel\ModuleApi\PageSettingsProviderInterface;
+use TYPO3\CMS\Adminpanel\ModuleApi\RequestEnricherInterface;
 use TYPO3\CMS\Adminpanel\ModuleApi\ResourceProviderInterface;
 use TYPO3\CMS\Adminpanel\Repositories\FrontendGroupsRepository;
 use TYPO3\CMS\Core\Context\Context;
 use TYPO3\CMS\Core\Context\DateTimeAspect;
 use TYPO3\CMS\Core\Context\UserAspect;
 use TYPO3\CMS\Core\Context\VisibilityAspect;
+use TYPO3\CMS\Core\Routing\PageArguments;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Fluid\View\StandaloneView;
 use TYPO3\CMS\Frontend\Aspect\PreviewAspect;
-use TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication;
-use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
 
 /**
  * Admin Panel Preview Module
  */
-class PreviewModule extends AbstractModule implements InitializableInterface, PageSettingsProviderInterface, ResourceProviderInterface
+class PreviewModule extends AbstractModule implements RequestEnricherInterface, PageSettingsProviderInterface, ResourceProviderInterface
 {
     /**
      * module configuration, set on initialize
@@ -73,7 +72,7 @@ class PreviewModule extends AbstractModule implements InitializableInterface, Pa
     /**
      * @inheritdoc
      */
-    public function initializeModule(ServerRequestInterface $request): void
+    public function enrich(ServerRequestInterface $request): ServerRequestInterface
     {
         $this->config = [
             'showHiddenPages' => (bool)$this->getConfigOptionForModule('showHiddenPages'),
@@ -85,7 +84,7 @@ class PreviewModule extends AbstractModule implements InitializableInterface, Pa
         if ($this->config['showFluidDebug']) {
             // forcibly unset fluid caching as it does not care about the tsfe based caching settings
             unset($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['fluid_template']['frontend']);
-            $GLOBALS['TSFE']->set_no_cache('Cache is disabled if fluid debugging is enabled', true);
+            $request = $request->withAttribute('noCache', true);
         }
         $this->initializeFrontendPreview(
             $this->config['showHiddenPages'],
@@ -93,6 +92,8 @@ class PreviewModule extends AbstractModule implements InitializableInterface, Pa
             $this->config['simulateDate'],
             $this->config['simulateUserGroup']
         );
+
+        return $request;
     }
 
     /**
@@ -107,10 +108,16 @@ class PreviewModule extends AbstractModule implements InitializableInterface, Pa
 
         $frontendGroupsRepository = GeneralUtility::makeInstance(FrontendGroupsRepository::class);
 
+        $pageId = 0;
+        $pageArguments = $GLOBALS['TYPO3_REQUEST']->getAttribute('routing');
+        if ($pageArguments instanceof PageArguments) {
+            $pageId = $pageArguments->getPageId();
+        }
+
         $view->assignMultiple(
             [
                 'show' => [
-                    'pageId' => (int)$this->getTypoScriptFrontendController()->id,
+                    'pageId' => $pageId,
                     'hiddenPages' => $this->config['showHiddenPages'],
                     'hiddenRecords' => $this->config['showHiddenRecords'],
                     'fluidDebug' => $this->config['showFluidDebug'],
@@ -138,14 +145,6 @@ class PreviewModule extends AbstractModule implements InitializableInterface, Pa
     }
 
     /**
-     * @return TypoScriptFrontendController
-     */
-    protected function getTypoScriptFrontendController(): TypoScriptFrontendController
-    {
-        return $GLOBALS['TSFE'];
-    }
-
-    /**
      * Initialize frontend preview functionality incl.
      * simulation of users or time
      *
@@ -161,7 +160,6 @@ class PreviewModule extends AbstractModule implements InitializableInterface, Pa
         int $simulateUserGroup
     ): void {
         $context = GeneralUtility::makeInstance(Context::class);
-        $typoScriptFrontendController = $this->getTypoScriptFrontendController();
         $this->clearPreviewSettings($context);
 
         // Set preview flag
@@ -191,21 +189,11 @@ class PreviewModule extends AbstractModule implements InitializableInterface, Pa
         }
         // simulate usergroup
         if ($simulateUserGroup) {
-            $typoScriptFrontendController->simUserGroup = $simulateUserGroup;
-            if (!$typoScriptFrontendController->fe_user instanceof FrontendUserAuthentication) {
-                $typoScriptFrontendController->fe_user = GeneralUtility::makeInstance(
-                    FrontendUserAuthentication::class
-                );
-            }
-            if (!is_array($typoScriptFrontendController->fe_user->user)) {
-                $typoScriptFrontendController->fe_user->user = [];
-            }
-            $typoScriptFrontendController->fe_user->user[$typoScriptFrontendController->fe_user->usergroup_column] = $simulateUserGroup;
             $context->setAspect(
                 'frontend.user',
                 GeneralUtility::makeInstance(
                     UserAspect::class,
-                    $typoScriptFrontendController->fe_user ?: null,
+                    null,
                     [$simulateUserGroup]
                 )
             );
index 737c814..eb99b31 100644 (file)
@@ -19,9 +19,9 @@ namespace TYPO3\CMS\Adminpanel\Modules\TsDebug;
 use Psr\Http\Message\ServerRequestInterface;
 use TYPO3\CMS\Adminpanel\ModuleApi\AbstractSubModule;
 use TYPO3\CMS\Adminpanel\ModuleApi\ContentProviderInterface;
-use TYPO3\CMS\Adminpanel\ModuleApi\InitializableInterface;
 use TYPO3\CMS\Adminpanel\ModuleApi\ModuleData;
 use TYPO3\CMS\Adminpanel\ModuleApi\ModuleSettingsProviderInterface;
+use TYPO3\CMS\Adminpanel\ModuleApi\RequestEnricherInterface;
 use TYPO3\CMS\Adminpanel\Service\ConfigurationService;
 use TYPO3\CMS\Backend\FrontendBackendUserAuthentication;
 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
@@ -30,14 +30,13 @@ use TYPO3\CMS\Core\Context\TypoScriptAspect;
 use TYPO3\CMS\Core\TimeTracker\TimeTracker;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Fluid\View\StandaloneView;
-use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
 
 /**
  * Class TypoScriptWaterfall
  *
  * @internal
  */
-class TypoScriptWaterfall extends AbstractSubModule implements InitializableInterface, ContentProviderInterface, ModuleSettingsProviderInterface
+class TypoScriptWaterfall extends AbstractSubModule implements RequestEnricherInterface, ContentProviderInterface, ModuleSettingsProviderInterface
 {
     /**
      * @var ConfigurationService
@@ -70,17 +69,14 @@ class TypoScriptWaterfall extends AbstractSubModule implements InitializableInte
     /**
      * @inheritdoc
      */
-    public function initializeModule(ServerRequestInterface $request): void
+    public function enrich(ServerRequestInterface $request): ServerRequestInterface
     {
-        $typoScriptFrontend = $this->getTypoScriptFrontendController();
-        $forceTemplateParsing = $this->getConfigurationOption(
-            'forceTemplateParsing'
-        );
-        if ($forceTemplateParsing) {
+        if ($this->getConfigurationOption('forceTemplateParsing')) {
             GeneralUtility::makeInstance(Context::class)->setAspect('typoscript', GeneralUtility::makeInstance(TypoScriptAspect::class, true));
-            $typoScriptFrontend->set_no_cache('Admin Panel: Force template parsing', true);
+            $request = $request->withAttribute('noCache', true);
         }
         $this->getTimeTracker()->LR = (bool)$this->getConfigurationOption('LR');
+        return $request;
     }
 
     /**
@@ -186,12 +182,4 @@ class TypoScriptWaterfall extends AbstractSubModule implements InitializableInte
     {
         return GeneralUtility::makeInstance(TimeTracker::class);
     }
-
-    /**
-     * @return TypoScriptFrontendController
-     */
-    protected function getTypoScriptFrontendController(): TypoScriptFrontendController
-    {
-        return $GLOBALS['TSFE'];
-    }
 }
index ebcd4c1..d44c1e7 100644 (file)
@@ -16,12 +16,12 @@ namespace TYPO3\CMS\Adminpanel\Tests\Unit\Fixtures;
  * The TYPO3 project - inspiring people to share!
  */
 
-use     Psr\Http\Message\ServerRequestInterface;
+use Psr\Http\Message\ServerRequestInterface;
 use TYPO3\CMS\Adminpanel\ModuleApi\ConfigurableInterface;
-use TYPO3\CMS\Adminpanel\ModuleApi\InitializableInterface;
 use TYPO3\CMS\Adminpanel\ModuleApi\ModuleInterface;
 use TYPO3\CMS\Adminpanel\ModuleApi\OnSubmitActorInterface;
 use TYPO3\CMS\Adminpanel\ModuleApi\PageSettingsProviderInterface;
+use TYPO3\CMS\Adminpanel\ModuleApi\RequestEnricherInterface;
 use TYPO3\CMS\Adminpanel\ModuleApi\ResourceProviderInterface;
 use TYPO3\CMS\Adminpanel\ModuleApi\ShortInfoProviderInterface;
 use TYPO3\CMS\Adminpanel\ModuleApi\SubmoduleProviderInterface;
@@ -30,7 +30,7 @@ class MainModuleFixture implements
     ModuleInterface,
     ShortInfoProviderInterface,
     SubmoduleProviderInterface,
-    InitializableInterface,
+    RequestEnricherInterface,
                ResourceProviderInterface,
     PageSettingsProviderInterface,
     OnSubmitActorInterface,
@@ -87,15 +87,6 @@ class MainModuleFixture implements
     }
 
     /**
-     * Initialize the module - runs early in a TYPO3 request
-     *
-     * @param ServerRequestInterface $request
-     */
-    public function initializeModule(ServerRequestInterface $request): void
-    {
-    }
-
-    /**
      * Module is enabled
      * -> should be initialized
      * A module may be enabled but not shown
@@ -167,4 +158,16 @@ class MainModuleFixture implements
     {
         return false;
     }
+
+    /**
+     * Initialize the module - runs in the TYPO3 middleware stack at an early point
+     * may manipulate the current request
+     *
+     * @param ServerRequestInterface $request
+     * @return ServerRequestInterface
+     */
+    public function enrich(ServerRequestInterface $request): ServerRequestInterface
+    {
+        return $request;
+    }
 }
index 2b1f1dd..ccce862 100644 (file)
@@ -24,7 +24,6 @@ use TYPO3\CMS\Adminpanel\Controller\MainController;
 use TYPO3\CMS\Adminpanel\Middleware\AdminPanelInitiator;
 use TYPO3\CMS\Backend\FrontendBackendUserAuthentication;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
-use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
 
 /**
@@ -59,14 +58,13 @@ class AdminPanelInitiatorTest extends UnitTestCase
         $userAuthentication->uc = $uc;
         $GLOBALS['BE_USER'] = $userAuthentication->reveal();
 
-        $tsfe = $this->prophesize(TypoScriptFrontendController::class);
-        $GLOBALS['TSFE'] = $tsfe;
-
         $controller = $this->prophesize(MainController::class);
         GeneralUtility::setSingletonInstance(MainController::class, $controller->reveal());
         $handler = $this->prophesizeHandler();
         $request = $this->prophesize(ServerRequestInterface::class);
         $request->withAttribute(Argument::cetera())->willReturn($request);
+        $controller->initialize($request->reveal())->willReturn($request);
+
         // Act
         $adminPanelInitiator = new AdminPanelInitiator();
         $adminPanelInitiator->process(
@@ -125,9 +123,6 @@ class AdminPanelInitiatorTest extends UnitTestCase
         $userAuthentication->uc = $uc;
         $GLOBALS['BE_USER'] = $userAuthentication->reveal();
 
-        $tsfe = $this->prophesize(TypoScriptFrontendController::class);
-        $GLOBALS['TSFE'] = $tsfe;
-
         $controller = $this->prophesize(MainController::class);
         GeneralUtility::setSingletonInstance(MainController::class, $controller->reveal());
         $handler = $this->prophesizeHandler();
index 09a22ce..67db7af 100644 (file)
@@ -9,8 +9,6 @@ use TYPO3\CMS\Adminpanel\Modules\PreviewModule;
 use TYPO3\CMS\Adminpanel\Service\ConfigurationService;
 use TYPO3\CMS\Core\Context\Context;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
-use TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication;
-use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
 
 class PreviewModuleTest extends UnitTestCase
@@ -47,8 +45,6 @@ class PreviewModuleTest extends UnitTestCase
     {
         $this->resetSingletonInstances = true;
         $request = $this->prophesize(ServerRequestInterface::class);
-        $tsfe = $this->prophesize(TypoScriptFrontendController::class);
-        $GLOBALS['TSFE'] = $tsfe->reveal();
         $configurationService = $this->prophesize(ConfigurationService::class);
         $configurationService->getMainConfiguration()->willReturn([]);
         $configurationService->getConfigurationOption('preview', 'simulateDate')->willReturn($dateToSimulate);
@@ -57,7 +53,7 @@ class PreviewModuleTest extends UnitTestCase
         GeneralUtility::setSingletonInstance(ConfigurationService::class, $configurationService->reveal());
 
         $previewModule = new PreviewModule();
-        $previewModule->initializeModule($request->reveal());
+        $previewModule->enrich($request->reveal());
 
         self::assertSame($GLOBALS['SIM_EXEC_TIME'], $expectedExecTime, 'EXEC_TIME');
         self::assertSame($GLOBALS['SIM_ACCESS_TIME'], $expectedAccessTime, 'ACCESS_TIME');
@@ -70,10 +66,6 @@ class PreviewModuleTest extends UnitTestCase
     {
         $this->resetSingletonInstances = true;
         $request = $this->prophesize(ServerRequestInterface::class);
-        $tsfe = $this->prophesize(TypoScriptFrontendController::class);
-        $feUser = $this->prophesize(FrontendUserAuthentication::class);
-        $tsfe->fe_user = $feUser->reveal();
-        $GLOBALS['TSFE'] = $tsfe->reveal();
         $configurationService = $this->prophesize(ConfigurationService::class);
         $configurationService->getMainConfiguration()->willReturn([]);
         $configurationService->getConfigurationOption('preview', 'showHiddenPages')->willReturn('0');
@@ -87,7 +79,7 @@ class PreviewModuleTest extends UnitTestCase
         GeneralUtility::setSingletonInstance(ConfigurationService::class, $configurationService->reveal());
 
         $previewModule = new PreviewModule();
-        $previewModule->initializeModule($request->reveal());
+        $previewModule->enrich($request->reveal());
 
         $context->setAspect('frontend.user', Argument::any())->shouldHaveBeenCalled();
     }
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Deprecation-88807-AdminPanelInitializableInterfaceHasBeenDeprecated.rst b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-88807-AdminPanelInitializableInterfaceHasBeenDeprecated.rst
new file mode 100644 (file)
index 0000000..fa8a912
--- /dev/null
@@ -0,0 +1,37 @@
+.. include:: ../../Includes.txt
+
+===========================================================================
+Deprecation: #88807 - AdminPanel InitializableInterface has been deprecated
+===========================================================================
+
+See :issue:`88807`
+
+Description
+===========
+
+`\TYPO3\CMS\Adminpanel\ModuleApi\InitializableInterface` has been deprecated in favor of the newly
+introduced `\TYPO3\CMS\Adminpanel\ModuleApi\RequestEnricherInterface`.
+
+
+Impact
+======
+
+Using `\TYPO3\CMS\Adminpanel\ModuleApi\InitializableInterface` will trigger a deprecation message.
+
+
+Affected Installations
+======================
+
+All instances that use `\TYPO3\CMS\Adminpanel\ModuleApi\InitializableInterface` are affected.
+
+
+Migration
+=========
+
+Switch to `\TYPO3\CMS\Adminpanel\ModuleApi\RequestEnricherInterface` instead:
+
+- change method name `initializeModule` to `enrich`
+- change return value to return an instance of
+  :php:`\Psr\Http\Message\ServerRequestInterface`
+
+.. index:: Frontend, PHP-API, PartiallyScanned, ext:adminpanel
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Feature-88807-AdminPanelRequestEnricherInterfaceHasBeenIntroduced.rst b/typo3/sysext/core/Documentation/Changelog/master/Feature-88807-AdminPanelRequestEnricherInterfaceHasBeenIntroduced.rst
new file mode 100644 (file)
index 0000000..ea96670
--- /dev/null
@@ -0,0 +1,25 @@
+.. include:: ../../Includes.txt
+
+=========================================================================
+Feature: #88807 - AdminPanel RequestEnricherInterface has been introduced
+=========================================================================
+
+See :issue:`88807`
+
+Description
+===========
+
+The AdminPanel initialisation process has been refactored and an interface called
+:php:`\TYPO3\CMS\Adminpanel\ModuleApi\RequestEnricherInterface` has been introduced.
+
+
+Impact
+======
+
+With the :php:`\TYPO3\CMS\Adminpanel\ModuleApi\RequestEnricherInterface`, adminpanel modules gain the
+ability to manipulate the request object during TYPO3's processing of the PSR-15 middlewares.
+All modules implementing the interface need a method :php:`enrich($request)` and may return an altered
+:php:`$request` in their processing. At the end of the processing, the `$request` has to be returned
+and will in turn be used in further PSR-15 middleware stack processing.
+
+.. index:: Frontend, PHP-API, ext:adminpanel
index a2474e3..cd32a73 100644 (file)
@@ -1311,4 +1311,10 @@ return [
             'Breaking-88496-MethodGetSwitchableControllerActionsHasBeenRemoved.rst'
         ],
     ],
+    'TYPO3\CMS\Adminpanel\ModuleApi\InitializableInterface' => [
+        'restFiles' => [
+            'Deprecation-88807-AdminPanelInitializableInterfaceHasBeenDeprecated.rst',
+            'Feature-88807-AdminPanelRequestEnricherInterfaceHasBeenIntroduced.rst',
+        ],
+    ],
 ];