Problem/Motivation
Steps to reproduce
Proposed resolution
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
Problem/Motivation
There are a number of issues where we want one module to be able to add to the output of another:
- #3221351: 3rd-party should be able to alter the EntityListBuilder rows
- #2612222: Provide a better way to alter entity revision overview
- #3227102: Content Translation Overview Controller - make overview table easier to extend
Various solutions are being suggested on those issues:
- alter hooks for the render array, invoked in the controller
- an event that is fired by the controller
Both of these solutions have a problem that they do not scale to all the other places where alteration of a controller's output is needed. We'd need to add more and more alter hooks or BuildEvents. Or add a Single All-Encompassing one of those, which would be a new version of D7's hook_page_alter() (urgh), or an event version of the same.
Steps to reproduce
Proposed resolution
What if we added a way for router controllers to be decorated?
We'd have something like this in routing.yml:
original.route.decorator:
decorates: original.route
defaults:
_decorator: '\Drupal\mymodule\Controller\MyRouteDecorator'
MyRouteDecorator then becomes the class called for the route's output. It receives the render array from the decorated route's controller.
If multiple decorators are declared, they can use a weight property to set their order.
This would be an extension to Symfony's routing system, but I don't see this being adopted upstream, because Symfony doesn't have module-based architecture where we need one part of the system to be able to alter things made by another part.