Currently route subscribers have only access to the collection holding dynamically-defined routes. This is not a big problem since in hook_menu() we used to have no item available, but when altering routes we need all the defined routes not only the dynamic ones, otherwise we will have a regression as soon as we get rid of hook_menu()/hook_menu_alter().

Additionally since we allow route subscribers to know about already defined routes, it would be handy to have access also to statically-defined routes, which would allow for instance to provide copies of them on different paths. An example of this use case is #1810394: Site configuration with domain based language negotiation results in redirecting authenticated users to a different domain when accessing a content entity route for translation language different from the interface language, where we are currently exploring the idea of providing language-specific entity forms on different routes than the original ones:

node/{node}/edit (entity form in the current language)
node/{node}/edit/{language} (entity form in the specified language)

To do this in a generic way we need to copy the routes provided by every entity-defining module.

Comments

dawehner’s picture

If you look at the current Router Builder it is designed in a way that you never have all the routes in the memory.
So by default it first builds the static routes per module and then allow you to provide dynamic ones.

Based upon that I would guess that using the alter event is the recommended way to move forward.

plach’s picture

Status: Active » Closed (works as designed)

Based upon that I would guess that using the alter event is the recommended way to move forward.

If I understand correctly the alter event is called for each module providing static route definitions and once for all dynamic ones. So we never get a unique call with all the available routes but we can still alter any defined route, correct?

If so it seems we have no regression here, sorry for the noise.

dawehner’s picture

If I understand correctly the alter event is called for each module providing static route definitions and once for all dynamic ones. So we never get a unique call with all the available routes but we can still alter any defined route, correct?

Exactly, you would just have to figure out whether your wanted changed route exists in the current altered route collection.

dawehner’s picture

Issue summary: View changes

Updated issue summary.