diff --git a/typo3/sysext/extbase/Classes/Service/ExtensionService.php b/typo3/sysext/extbase/Classes/Service/ExtensionService.php index a14769166cd4ee5fa59e4b530b840eab10018d1a..2f332816c87d5495b4ccce2d3b9515eef91d24f6 100644 --- a/typo3/sysext/extbase/Classes/Service/ExtensionService.php +++ b/typo3/sysext/extbase/Classes/Service/ExtensionService.php @@ -123,11 +123,14 @@ class ExtensionService implements \TYPO3\CMS\Core\SingletonInterface } $pluginNames = []; foreach ($plugins as $pluginName => $pluginConfiguration) { - foreach ($pluginConfiguration['controllers'] ?? [] as $pluginControllerName => $pluginControllerActions) { + $controllers = $pluginConfiguration['controllers'] ?? []; + $controllerAliases = array_column($controllers, 'actions', 'alias'); + + foreach ($controllerAliases as $pluginControllerName => $pluginControllerActions) { if (strtolower($pluginControllerName) !== strtolower($controllerName)) { continue; } - if (in_array($actionName, $pluginControllerActions['actions'], true)) { + if (in_array($actionName, $pluginControllerActions, true)) { $pluginNames[] = $pluginName; } } @@ -230,10 +233,10 @@ class ExtensionService implements \TYPO3\CMS\Core\SingletonInterface */ public function getDefaultControllerNameByPlugin(string $extensionName, string $pluginName): ?string { - // todo: using false as a default is fishy. - // todo: rather make sure that $controllers is an array and then return the (string) key or null - $controllers = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions'][$extensionName]['plugins'][$pluginName]['controllers'] ?? false; - return $controllers ? key($controllers) : null; + $controllers = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions'][$extensionName]['plugins'][$pluginName]['controllers'] ?? []; + $controllerAliases = array_column($controllers, 'alias'); + $defaultControllerName = (string)($controllerAliases[0] ?? ''); + return $defaultControllerName !== '' ? $defaultControllerName : null; } /** @@ -246,11 +249,11 @@ class ExtensionService implements \TYPO3\CMS\Core\SingletonInterface */ public function getDefaultActionNameByPluginAndController(string $extensionName, string $pluginName, string $controllerName): ?string { - // todo: using false as a default is fishy. - // todo: rather make sure that $actions is an array and then return the (string) key or null - // todo: also use reset(), rather than current, as array pointer might have been moved. - $actions = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions'][$extensionName]['plugins'][$pluginName]['controllers'][$controllerName]['actions'] ?? false; - return $actions ? current($actions) : null; + $controllers = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions'][$extensionName]['plugins'][$pluginName]['controllers'] ?? []; + $controllerActionsByAlias = array_column($controllers, 'actions', 'alias'); + $actions = $controllerActionsByAlias[$controllerName] ?? []; + $defaultActionName = (string)($actions[0] ?? ''); + return $defaultActionName !== '' ? $defaultActionName : null; } /** diff --git a/typo3/sysext/extbase/Tests/Functional/Service/ExtensionServiceTest.php b/typo3/sysext/extbase/Tests/Functional/Service/ExtensionServiceTest.php new file mode 100644 index 0000000000000000000000000000000000000000..c5f65f6c84a6e17979d909f6f68e619e5ce66d69 --- /dev/null +++ b/typo3/sysext/extbase/Tests/Functional/Service/ExtensionServiceTest.php @@ -0,0 +1,66 @@ +<?php +declare(strict_types = 1); +namespace TYPO3\CMS\Extbase\Tests\Functional\Service; + +/* + * 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 Prophecy\Argument; +use TYPO3\CMS\Extbase\Configuration\ConfigurationManager; +use TYPO3\CMS\Extbase\Configuration\FrontendConfigurationManager; +use TYPO3\CMS\Extbase\Object\ObjectManagerInterface; +use TYPO3\CMS\Extbase\Service\EnvironmentService; +use TYPO3\CMS\Extbase\Service\ExtensionService; +use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase; + +class ExtensionServiceTest extends FunctionalTestCase +{ + /** + * @var array + */ + protected $testExtensionsToLoad = ['typo3/sysext/extbase/Tests/Functional/Fixtures/Extensions/blog_example']; + + /** + * @var array + */ + protected $coreExtensionsToLoad = ['extbase', 'fluid']; + + /** + * @test + */ + public function getPluginNameByActionDetectsPluginNameFromGlobalExtensionConfigurationArray() + { + $environmentService = $this->prophesize(EnvironmentService::class); + $environmentService->isEnvironmentInFrontendMode()->willReturn(true); + $environmentService->isEnvironmentInBackendMode()->willReturn(false); + $environmentService = $environmentService->reveal(); + + $frontendConfigurationManager = $this->prophesize(FrontendConfigurationManager::class); + $frontendConfigurationManager->getConfiguration(Argument::cetera())->willReturn([]); + + $objectManager = $this->prophesize(ObjectManagerInterface::class); + $objectManager->get(Argument::exact(FrontendConfigurationManager::class))->willReturn($frontendConfigurationManager->reveal()); + + $configurationManager = new ConfigurationManager( + $objectManager->reveal(), + $environmentService + ); + + $extensionService = new ExtensionService(); + $extensionService->injectConfigurationManager($configurationManager); + + $pluginName = $extensionService->getPluginNameByAction('BlogExample', 'Blog', 'testForm'); + + self::assertSame('Blogs', $pluginName); + } +} diff --git a/typo3/sysext/extbase/Tests/Unit/Service/ExtensionServiceTest.php b/typo3/sysext/extbase/Tests/Unit/Service/ExtensionServiceTest.php index ea054535f17fd8d4c3e83b63dc45214dbc71067c..c508a0f509dd5783e6b301302e22e95a3e8a70ce 100644 --- a/typo3/sysext/extbase/Tests/Unit/Service/ExtensionServiceTest.php +++ b/typo3/sysext/extbase/Tests/Unit/Service/ExtensionServiceTest.php @@ -61,14 +61,16 @@ class ExtensionServiceTest extends UnitTestCase 'plugins' => [ 'SomePlugin' => [ 'controllers' => [ - 'ControllerName' => [ + 'Fully\\Qualified\\ControllerName' => [ + 'alias' => 'ControllerName', 'actions' => ['index', 'otherAction'] ] ] ], 'ThirdPlugin' => [ 'controllers' => [ - 'ControllerName' => [ + 'Fully\\Qualified\\ControllerName' => [ + 'alias' => 'ControllerName', 'actions' => ['otherAction', 'thirdAction'] ] ] @@ -79,11 +81,13 @@ class ExtensionServiceTest extends UnitTestCase 'plugins' => [ 'SecondPlugin' => [ 'controllers' => [ - 'ControllerName' => [ + 'Fully\\Qualified\\ControllerName' => [ + 'alias' => 'ControllerName', 'actions' => ['index', 'otherAction'] ], - 'SecondControllerName' => [ + 'Fully\\Qualified\\SecondControllerName' => [ 'actions' => ['someAction', 'someOtherAction'], + 'alias' => 'SecondControllerName', 'nonCacheableActions' => ['someOtherAction'] ] ]