Rules hook_init() causes theme system to initialize too early
benthroop - March 6, 2009 - 21:59
| Project: | Rules |
| Version: | 6.x-1.0 |
| Component: | Rules Engine |
| Category: | bug report |
| Priority: | critical |
| Assigned: | Unassigned |
| Status: | closed |
| Issue tags: | maintenance mode, theme |
Jump to:
Description
It is possible that using a rule with "User is going to view a page" as the event cause Maintenance Mode to show up with no theme, no css.
A theory is that Rules is initializing theme during bootstrap.
See this thread: http://drupal.org/node/374645#comment-1306636
Someone else should test this before it's marked as active...

#1
Does it so, independent from what action/condition you configure? Could you try an empty rule?
#2
Confirmed on Drupal 6.10 with Beta 5 of Rules. A completely empty rule that is merely triggered each time a user views a page kills all styling on the maintenance page.
It also screws up the blocks page. If you're using an administration theme it prevents any other theme from loading on the blocks page.
#3
Hi,
I can confirm its screwing up the block admin page on Drupal 6.12 running Rules 6.x-1.0.
How can I assist in fixing this behaviour? Which info do you need?
Regards,
Jutta
#4
Nothing, I think the problem is that a call to t() - probably done by the logging system - initializes the theme system to early. I need to have a look at that.
#5
You are right, Rules module calls t() in hook_init, which calls theme('placeholder') , which invokes init_theme() too early.
I believe this is critical since it breaks site administration. When you can't configure your blocks it is confusing as hell.
This also probably means that "User is going to view a page" event should not have "show message" action, cause it uses t() too. Probably, any output in this event should be forbidden, cause in Drupal all output should go through theme layer.
Even more, most actions use t() anyway so we should either make workaround for this, or disable most actions for this event, leaving only custom php action. And if someone is confident enough to use custom php action, atleast he will do it conciously and it will be his responsibility to deal with consequences of such action.
Would be nice to put big, bold warning at that event, like "Note, that this event is invoked in hook_init() and you shouldn't use any Drupal functions that would cause unexpected theme system init."
#6
subscribing.
#7
I just fixed that. Now the theme system is only initialized if an action does so or the rules debug evaluation is shown. I've done so by avoid '%' replacements in t(), which initialize the theme. I've also added a help text to the rules "A user is going to view a page" action.
#8
just to confirm the bug and that the fix works. Thanks
#9
Automatically closed -- issue fixed for 2 weeks with no activity.