... or: "Move drupal_theme_initialize() out of bootstrap, into menu_execute_active_handler()".
Imo it would make sense to give modules like sections a chance to negotiate which theme to use, before we spend valuable time initializing the default theme. For this negotiation it would be useful to have information about the avtive router item and menu callback already available. The best time would be inside menu_execute_active_handler(), after menu_get_item(), but before calling the page callback.
Why?
- Give contrib modules a chance to negotiate which theme to use, with the data from menu_get_item() already available, so that we don't do theme initialization twice.
- Give contrib modules a chance to redirect to a different path, with the data from menu_get_item() already available, but without wasting time on theme initialization.
- Don't tempt contrib modules to call menu_get_item() from hook_init(), so we get a more predictable flow.
This also means that we need to add one or additional hooks between menu_get_item() and menu callback execution:
- A hook before theme negotiation, that would be a good place for redirection modules.
- A hook for theme negotiation, where each interested module can have a say.
- A hook after theme negotiation, for whatever purpose. We could even let the theme itself implement that hook, or give it a chance to do something.
The hooks can take the $router_item as an argument, and the last one could take a $theme object as an additional argument.
See also #852562: Call a hook from menu_execute_active_handler, after the router item is found.
----
An alternative would be a lazy theme initialization on the first call to theme(). However, this would be less predictable than the above, because we can never be sure at what time the global state from theme initialization is set or not.
Comments
Comment #1
donquixote commentedmore complete title.
Comment #2
donquixote commentedWas a bad idea to change the title.
Or otherwise, what's the difference to #852562: Call a hook from menu_execute_active_handler, after the router item is found. ?
Comment #3
Crell commentedmenu_execute_active_handler() no longer exists, so this isn't really relevant anymore.