Bug #91671

Missing documentation?: forward to controller action of another extension

Added by This M├Ąchler 27 days ago.

Status:
New
Priority:
Should have
Assignee:
-
Category:
Documentation
Target version:
-
Start date:
2020-06-18
Due date:
% Done:

0%

TYPO3 Version:
8
PHP Version:
7.2
Tags:
extbase controller forward class map alias
Complexity:
Is Regression:
Sprint Focus:

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.

Also available in: Atom PDF