Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
In case there's a Context OG Action 'Set Group Context', og_theme_custom_theme is invoked before it (returning empty og_context()), thus the context has not been applied yet. How can I enforce the theme to be set after all the contexts have been triggered?
Comment | File | Size | Author |
---|---|---|---|
#7 | og_theme-interaction-og-context-2147409-7.patch | 1.47 KB | justanothermark |
#1 | 2147409-og-theme-cache.patch | 717 bytes | agentrickard |
Comments
Comment #1
agentrickardAs far as I can tell, there is a very nasty cache bug in og_context() that sometimes causes the page to be cached with the wrong theme.
This admittedly ugly patch works around the problem by invalidating the page cache until og_context() sends a proper value.
Comment #2
agentrickardComment #3
agentrickardIn my case, I've tracked this down to a problem in entity_cache. If the parent group node is not in {cache_entity_node}, the lookup sometimes fails.
I wonder if this is a problem with entity_metadata_wrapper().
Comment #4
agentrickardThat's not it. But on cache clear, menu_get_custom_theme() is returning NULL.
Comment #5
agentrickardAfter thorough research, I don't think this is a context issue. It looks like a race condition in core.
See #943616: hook_custom_theme() does not work as expected and #1120188: Default Theme intermittently replaces Sub Theme for information about the reasons.
I ended up writing a custom hook_init() to force the theme to reset. I don't think that approach is appropriate for a patch to OG Theme. Though it could be moved to og_theme_init().
Comment #6
agentrickardThat approach has issues with subthemes and admin pages, so I wrote a more robust version.
Comment #7
justanothermark CreditAttribution: justanothermark at CTI Digital commentedAlthough this issue is closed, we had the same problem with a different workaround that I thought was worth sharing for anyone that finds the issue in the future.
Our approach was to avoid using og_context if it was possible to find the group type and ID from arg(). This only works for groups that are nodes but I'm sure it could be easily modified for other entities if required. It falls back to og_context if the shortcut doesn't work but
Again, as agentrickard has said, this is very much a workaround and I wouldn't expect it to be committed to the module unless a generic version could be made.