diff --git a/typo3/sysext/extbase/Classes/Utility/ExtensionUtility.php b/typo3/sysext/extbase/Classes/Utility/ExtensionUtility.php index ec6ebe9f38e527ccfd2facde9c6dde7ec1c3ec22..189767c79cf26b6182ee03173eb736924135823d 100644 --- a/typo3/sysext/extbase/Classes/Utility/ExtensionUtility.php +++ b/typo3/sysext/extbase/Classes/Utility/ExtensionUtility.php @@ -14,6 +14,8 @@ namespace TYPO3\CMS\Extbase\Utility; * The TYPO3 project - inspiring people to share! */ +use TYPO3\CMS\Core\Utility\StringUtility; + /** * Utilities to manage plugins and modules of an extension. Also useful to auto-generate the autoloader registry * file ext_autoload.php. @@ -310,15 +312,43 @@ tt_content.' . $pluginSignature . ' { */ public static function resolveControllerAliasFromControllerClassName(string $controllerClassName): string { - if (strrpos($controllerClassName, 'Controller') === false) { + // This method has been adjusted for TYPO3 10.3 to mitigate the issue that controller aliases + // could not longer be calculated from controller classes when calling + // \TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin(). + // + // The idea for version 11 is to let the user choose a controller alias and to check for its + // uniqueness per plugin. That way, the core does no longer rely on the namespace of + // controller classes to be in a specific format. + // + // todo: Change the way plugins are registered and enforce a controller alias to be set by + // the user to also free the core from guessing a simple alias by looking at the + // class name. This makes it possible to choose controller class names without a + // controller suffix. + + $strLen = strlen('Controller'); + + if (!StringUtility::endsWith($controllerClassName, 'Controller')) { return ''; } - return trim(substr( - $controllerClassName, - (int)strrpos($controllerClassName, '\\'), - -strlen('Controller') - ), '\\'); + $controllerClassNameWithoutControllerSuffix = substr($controllerClassName, 0, -$strLen); + + if (strrpos($controllerClassNameWithoutControllerSuffix, 'Controller\\') === false) { + $positionOfLastSlash = (int)strrpos($controllerClassNameWithoutControllerSuffix, '\\'); + $positionOfLastSlash += $positionOfLastSlash === 0 ? 0 : 1; + + return substr($controllerClassNameWithoutControllerSuffix, $positionOfLastSlash); + } + + $positionOfControllerNamespacePart = (int)strrpos( + $controllerClassNameWithoutControllerSuffix, + 'Controller\\' + ); + + return substr( + $controllerClassNameWithoutControllerSuffix, + $positionOfControllerNamespacePart + $strLen + 1 + ); } /** diff --git a/typo3/sysext/extbase/Tests/Unit/Utility/ExtensionUtilityTest.php b/typo3/sysext/extbase/Tests/Unit/Utility/ExtensionUtilityTest.php index 9cd4b5a8b7994342c6c9876f22dc337597c7b9a5..a3685ae529b3ad9efef169ec39b4ae96f03d8ddb 100644 --- a/typo3/sysext/extbase/Tests/Unit/Utility/ExtensionUtilityTest.php +++ b/typo3/sysext/extbase/Tests/Unit/Utility/ExtensionUtilityTest.php @@ -480,6 +480,10 @@ class ExtensionUtilityTest extends UnitTestCase '', 'Foo\\Bar\\baz\\qUx\\Foocontroller', ], + 'Controller in arbitrary namespace with subfolder in Controller namespace' => [ + 'Baz\\Foo', + 'Foo\\Bar\\Controller\\Baz\\FooController', + ], ]; }