Bug #91671
closedMissing documentation?: forward to controller action of another extension
0%
Description
It's maybe not really a bug, but I had a hard time to figure this out:
In an extbase-controller I forward to a controller-action of another extension. This may be not very common, but anyway.
In TYPO3 9 this worked without any problems, but not in TYPO3 10. It refused to resolve the class name of the controller to forward to.
I spent hours to understand how the dispatch-thing works, and how and when the classname of the controller is determined.
This is different in TYPO3 9, there it determines the classname by combining parts of the request (vendor, extensionname, controller, action) directly in the Request-Object's getControllerObjectName().
TYPO3 10 loads a configuration with the configuration-manager in \TYPO3\CMS\Extbase\Mvc\Web\RequestBuilder, and passes an alias-classname-map to the request object (setControllerAliasToClassNameMapping), but this map only contains the controller classes configured in the plugin setup.
Fortunately, the setControllerAliasToClassNameMapping is public, so it's possible to override the classname-map and forward to a foreign controller:
$this->request->setControllerAliasToClassNameMapping (
['Cloud' => 'SGPA\Sgpaclouds\Controller\CloudController']
);
$this->forward( 'navigation', 'Cloud', 'Sgpaclouds',
array(
'navItems' => $navItems,'rawPrependHTML' => $this->view->render()
)
);
The magic happens then in $request->setControllerName( ... ), where the class name is fetched from the map. controller->forward( ) calls $this->request->setControllerName( ... ), so the overridden map will apply there.
Maybe someone else would be glad to find this hint in the documentation.
Updated by Cyril Janody over 4 years ago
Hi,
I confirm, this should be documented...
In my case the controller is in the same extension.
Your solution works great and saved me a lot of debugging time!
Makes my day! ;)
Regards
Updated by Henrik Elsner over 3 years ago
- TYPO3 Version changed from 8 to 10
You saved my day.
$controllerObjectName is empty even with proper usage of setters for ExtensionName or even by using setControllerObjectName()
This means all of the info is set properly except of the $controllerObjectName that is needed within the dispatcher.
I allow myself to adapt the TYPO3 version to v10 as it worked (also in my case) for v9, but does not anymore in v10
Updated by Henrik Elsner over 3 years ago
I added an issue in the docs repo so we can provide the docs if necessary.
https://github.com/TYPO3-Documentation/TYPO3CMS-Book-ExtbaseFluid/issues/464
Updated by Kevin von Spiczak over 2 years ago
I can confirm this issue on v10.
I noticed some forward statements in a controller where not working anymore, after upgrading vom 9 to 10.
These calls were forwarding to controller actions of another Plugin, but within the same extension.
The workaround did the trick, thank you very much!
Updated by Lina Wolf over 2 years ago
Situation for TYPO3 v11 and 12 will be documented here:
https://github.com/TYPO3-Documentation/TYPO3CMS-Reference-CoreApi/pull/2075
Updated by Lina Wolf over 2 years ago
And the situation of the situation in TYPO3 10 here:
https://github.com/TYPO3-Documentation/TYPO3CMS-Book-ExtbaseFluid/pull/569
Updated by Garvin Hicking about 1 year ago
- Related to Bug #101824: RedirectReponse to another Controller missing controllerObjectName added
Updated by Garvin Hicking about 1 year ago
Addendum: Documentation was missing an important information that target actions need to be explicitly registered so that they can be resolved.
Calling `setControllerAliasToClassNameMapping` was actually a workaround to make the target action known to Extbase, where in fact it should be resolved automatically, if all information was provided.
The documentation will be updated via https://github.com/TYPO3-Documentation/TYPO3CMS-Reference-CoreApi/pull/3400