Project

General

Profile

Actions

Bug #91671

closed

Missing documentation?: forward to controller action of another extension

Added by This Mächler almost 4 years ago. Updated 8 months ago.

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

0%

Estimated time:
TYPO3 Version:
10
PHP Version:
7.2
Tags:
extbase controller forward class map alias
Complexity:
Is Regression:
Yes
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.


Related issues 1 (0 open1 closed)

Related to TYPO3 Core - Bug #101824: RedirectReponse to another Controller missing controllerObjectNameClosed2023-09-01

Actions
Actions #1

Updated by Cyril Janody over 3 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

Actions #2

Updated by Henrik Elsner almost 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

Actions #3

Updated by Henrik Elsner almost 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

Actions #4

Updated by Mathias Brodala almost 3 years ago

  • Is Regression set to Yes
Actions #5

Updated by Kevin von Spiczak about 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!

Actions #6

Updated by Lina Wolf over 1 year ago

Situation for TYPO3 v11 and 12 will be documented here:

https://github.com/TYPO3-Documentation/TYPO3CMS-Reference-CoreApi/pull/2075

Actions #7

Updated by Lina Wolf over 1 year ago

And the situation of the situation in TYPO3 10 here:
https://github.com/TYPO3-Documentation/TYPO3CMS-Book-ExtbaseFluid/pull/569

Actions #8

Updated by Lina Wolf over 1 year ago

  • Status changed from New to Resolved
Actions #9

Updated by Benni Mack over 1 year ago

  • Status changed from Resolved to Closed
Actions #10

Updated by Garvin Hicking 8 months ago

  • Related to Bug #101824: RedirectReponse to another Controller missing controllerObjectName added
Actions #11

Updated by Garvin Hicking 8 months 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

Actions

Also available in: Atom PDF