event_nodeapi on load calls init_theme()
| Project: | Event |
| Version: | 5.x-2.x-dev |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
Jump to:
I'm not sure if this is a bug, or by design. I'll try to explain as clearly as possible although unfortunately I don't have a solution.
If I understand correctly, modules may use hook_init to define global variables before much of the page processing is done. In particular, it allows moduels like Organic Groups to define $custom_theme based on a node's group. To do this, OG performs the following actions:
1) Node_load on whatever node is currently being viewed
2) Gets it group
3) Loads the group node
4) Gets the custom theme from the group node
5) Sets global $custom_theme to that custom theme
All of this is done from hook_init.
If this node is an event:
1) node_load fires event_nodeapi's load case
2) This calls event_include_files()
3) event_include_files calls path_to_theme()
4) path_to_theme calls init_theme (because it was called from hook_init, init_theme hasn't been called yet and global $path_to_theme is still null)
As a result of this, event type nodes are unable to be properly loaded in any hook_init as they cause the theme to start up before hook_init would like it to, effectively interrupting hook_init.
It makes more sense to file this here than OG to me, however is this is incorrect I'd be happy to move it elsewhere. For a short term solution, as none of my themes implemented event.css I just remove the 'if' check, and always include the default css. This isn't an optimal solution I know, but It Works For Me. I hope the stack trace isn't too detailed, wanted to explain the exact situation that caused me issues.
Thanks,
jrp

#1
Yeah, the situation with event_include_files is far from ideal, but so is OG's way to determine what to do...
I introduced the path_to_theme thing to allow easier customization for event themers. I've no way to know if it is actually used and thus I cannot simly drop it...
#2
After some more poking around and talking to Killes, it looks like OG 6 (both 1.x and 2.x) help avoid this problem by doing group lookups by using menu_get_object instead of node_load. This doesn't necessarily solve the issue outright, but at least this instance of it the issue is taken care of by upgrading to D6. Here is a patch which is very, very tentative which might solve this problem.
Index: event.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/event/event.module,v
retrieving revision 1.348.2.19
diff -u -b -r1.348.2.19 event.module
--- event.module 15 Mar 2009 18:13:08 -0000 1.348.2.19
+++ event.module 28 May 2009 06:08:20 -0000
@@ -12,7 +12,9 @@
include_once(EVENT_PATH .'/event.theme');
global $db_type;
include_once(EVENT_PATH ."/event_database.$db_type.inc");
+}
+function event_include_theme_files() {
if (file_exists($file = path_to_theme() .'/event.css')) {
drupal_add_css($file);
}
@@ -2203,6 +2205,7 @@
case 'view':
if (isset($node->in_preview) && $node->in_preview) {
global $user;
+ event_include_theme_files();
event_nodeapi($node, 'submit');
$node->event['start'] = $node->event_start;
$node->event['end'] = $node->event_end;
#3
Jrp,
Thanks for the patch! It set me on the right way and now (at least) the event node pages are themed.
Will poke around too to see if I can do the same with the day, week, month and list ones.
Ricardo