Issue Bug Closed

#90822Parameter $controllerName in method uriFor of UriBuilder cannot be passed in a correct format

Tobias Schmidt 03/24/20, 14:49 updated 04/21/20, 12:16

Description

Until TYPO3 9 the method uriFor required the parameter $controllerName to be passed in the format of the controller alias. That is the controller class name without the namespace and the Controller suffix. With change Deprecation: #87550 – Use controller classes when registering plugins/modules this does not work anymore because method \TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin no longer accepts the class alias as array keys for parameters $controllerActions and $nonCacheableControllerActions. Instead it is neccessary to use the fully qualified controller class names.

This change leads to the following structure in $GLOBALS['TYPO3_CONF_VARS']:
_EXTCONF -> extbase -> extensions ->MyExtension -> plugins -> MyPlugin -> controllers -> *Vendor\MyExtension\Controller\MyWhateverController*_

If you call method uriFor of the UriBuilder with parameter $controllerName it passes the parameter to getPluginNameByAction of ExtensionService:

if ($pluginName === null && $this->environmentService->isEnvironmentInFrontendMode()) {
    $pluginName = $this->extensionService->getPluginNameByAction($extensionName, $controllerArguments['controller'], $controllerArguments['action']);
}

In method getPluginNameByAction in ExtensionService there is a comparison between the passed parameter $controllerName and the controller name from $GLOBALS['TYPO3_CONF_VARS']:

foreach ($plugins as $pluginName => $pluginConfiguration) {
    foreach ($pluginConfiguration['controllers'] ?? [] as $pluginControllerName => $pluginControllerActions) {
        if (strtolower($pluginControllerName) !== strtolower($controllerName)) {
            continue;
        }
        if (in_array($actionName, $pluginControllerActions['actions'], true)) {
            $pluginNames[] = $pluginName;
        }
    }
}

If you pass the class alias as parameter $controllerName in method uriFor the plugin name can never be set because the comparison always fails. If you pass the parameter $controllerName as fully qualified controller class name the comparison matches but the controller argument in the resulting link is wrong:
_tx_myextension_pi1[controller]=Vendor\MyExtension\Controller\MyWhateverController_

There is a mixup or inconsistency of using class alias and fully qualified class names that breaks the usage of parameter $controllerName in method uriFor of UriBuilder.

Reviews 1