Feature #104393
closedAdd new Extbase event AfterControllerActionResolvedEvent near AfterRequestDispatchedEvent
0%
Description
The `AfterRequestDispatchedEvent` is triggered after the content is completely rendered, even including the view.
If an action of another controller shall be rendered this adds up to the needed time and performance.
Therefore I propose another event, after the controller is resolved:
$controller = $this->resolveController($request); $this->eventDispatcher->dispatch(new AfterControllerResolvedEvent($controller, $request)); $response = $controller->processRequest($request);
As the code `$controller->processRequest($request)` triggers determination of the action too, the new Event wouldn't cover cases where just another action of the same controller should be dispatched individually, though.
To achieve this the code inside `ActionController::processRequest` had to be changed, so that determining the action would be separated from processing. This would be a deeper change though, but probably better and more reasonable than the proposed event.
When these two steps are separated it would be possible to include an event where controller and action are known already. Just forwarding wouldn't be included as that's done from inside the actions.
$controller = $this->resolveController($request); $action = $this->resolveControllerAction($request); $this->eventDispatcher->dispatch(new AfterControllerActionResolvedEvent($controller, $action, $request)); $response = $controller->processRequest($request);
Target of new Event is having the option to alter the dispatcher result, specifically to change Controller and/or Action, even if my code example wouldn't provide this feature.
In the frontend as well on many levels for developers this would be a hidden feature and hard to discover without knowledge about it's existence, similar to AOP where this problem exists too.
Examples:
- An extension provides wiki-pages for kids and adults, the level is different and could be switched based on the usergroup, without having to adjust this in the controller. Instead for each usergroup an own controller and view could be realized without much efforts.
- Shops / Banks / Assurances could provide different pages base on location or target group.
Updated by Garvin Hicking 3 months ago
Could you maybe describe a use case for this, so the need for it could be better understood? Do you try to listen on specific actions being executed that are not under your control?
Updated by David Bruchmann 3 months ago
Garvin, I thought about using it but am not sure if that's the best solution for my case.
It's about introducing another aspect, that is not available by headers or URL, to decide about the controller. That could be a setting in the extension settings which are stored in config/system/settings.php as example.
In my use-case I tend to decide against it, as it's not flexible but rather a one-time decision the user has to do -- this might be acceptable in different use-cases though.
Updated by Garvin Hicking 3 months ago
- Subject changed from Bad performance ot AfterRequestDispatchedEvent to Add new Extbase event AfterControllerActionResolvedEvent near AfterRequestDispatchedEvent
Updated by David Bruchmann 3 months ago
- Description updated (diff)
- Target version deleted (
13 LTS)
Updated by Torben Hansen 3 months ago
Although this might be a feature to easily solve the described use cases, it is not a good idea to change the action (or even the controller) on/before request processing. We already had switchableControllerActions, where there code-wise was no single source of truth for the provided action for a plugin and which therefore also has been removed from Extbase. Changing action (or controller) at runtime is against the MVC design principles and can lead to unexpected behaviors (e.g. routing, caching), debugging and maintenance challenges, or even introduce security issues when implemented wrong (e.g. extension developer decides to use unsigned GET parameter to change the action/controller). So I strongly against implementing the suggested event.
I suggest to use an uncached action to determine the conditions/data for frontend output and Fluid views with conditions to show individual content to different user/target groups.
Updated by David Bruchmann 3 months ago ยท Edited
Torben I agree, at least with cache this solution wouldn't work at all.
Introduction would be quite easy, but fixing all the follow-up issues you mentioned probably a pain.
So please feel free to close the issue.
Updated by Garvin Hicking 3 months ago
- Status changed from New to Closed
Thanks for diving into this. I agree that the "single source of truth" for this, preventing events to take over actions is a good reason. Closing this for now then!