I'm working on sections-5.x module, what set's a $custom_theme in hook_menu() and i found a problem only exists with normal caching mode active. i cannot simply find what's wrong, but it looks like Drupal ignores $custom_theme variable if cache mode is active. This problem only comes up if i'm an anonymous user. I don't know how to trace down this problem!?

Someone able to give me a hint how to find the source of this problem or have a look to core code and gets an idea?

The "trace" module patch for 5.x is buggy and do not work with anonymous users... i'm a little bit lost!?

Comments

chx’s picture

Status: Active » Closed (works as designed)

if cache is on then the page is served from the... surprise! cache. theme system does not fire.

hass’s picture

Status: Closed (works as designed) » Active

Well, that's expected behavior and this is what makes me wonder. The frontpage is normally (without cache) displayed with 3 columns theme and after caching is enabled the page is displayed the 2 column standard layout :-(((. Both themes are active...

Any idea what *could* be wrong?

johnalbin’s picture

Priority: Critical » Normal

It sounds like the cache was created before the sections were set up.

Try:

  1. clearing the cache (the devel module is useful for this
  2. turning the cache off
  3. setting up sections and making sure it works for anonymous users
  4. turning the cache on

The cache should then be created with the sections module’s modifications.

hass’s picture

Title: normal cache ON: $custom_theme var ignored » modules $custom_theme var ignored if theme_placeholder used in hook_menu
Priority: Normal » Critical

Ok, it took me MUCH and a HARD time to figure out what's broken here, but i found what happen. While this is a general problem i'd like to ask you what we can do to prevent this problem in general. I mark this critical, while it breaks the theme system.

Howto repro:
1. Create a menu item that have a theme placeholder like 'title' => t('Delete %name', array('%name' => $name))
2. Add

function sections_menu($may_cache) {

  if ($may_cache) { 
    $name = 'my_subtheme'
    // code that runs only once
    global $custom_theme;
    $custom_theme = $name;
  }

}

3. Now a menu item containing the t() function calls function t()
4. t() see the %name and calls theme('placeholder', $value)
5. theme_get_function() does a init_theme() and now all goes wrong...
6. and prevent theme switching by modules, while $custom_theme cannot overwrite a previously set theme. The overwrite is prevented by if (isset($theme)) { return; } in init_theme().

So i can only say today: Never ever should *any* module use t() with %name in hook_menu OR init_theme() get's fired for theme_placeholder by theme_get_function function and theme switch will fail for anonymous users in cached mode with subthemes!

hass’s picture

sorry, above code should be if (!$may_cache) {

drumm’s picture

Status: Active » Closed (works as designed)

Don't use hook_menu() for setting $custom_theme. Use hook_init().