Commit 6db9a9dc authored by Daniel Gohlke's avatar Daniel Gohlke Committed by Alexander Schnitzler
Browse files

[BUGFIX] Return class alias respecting namespace

The resolveControllerAliasFromControllerClassName returns an alias
respecting subfolders in controller namespace to avoid same aliases
for different controllers and to load the templates from
corresponding directories.

Resolves: #90480
Releases: master
Change-Id: I3ed691e126579a4cfcc35f9589beb017b06a2f82
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/63361


Tested-by: default avatarTYPO3com <noreply@typo3.com>
Tested-by: Susanne Moog's avatarSusanne Moog <look@susi.dev>
Tested-by: default avatarAlexander Schnitzler <git@alexanderschnitzler.de>
Reviewed-by: Susanne Moog's avatarSusanne Moog <look@susi.dev>
Reviewed-by: default avatarAlexander Schnitzler <git@alexanderschnitzler.de>
parent ac747e1a
......@@ -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
);
}
/**
......
......@@ -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',
],
];
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment