system_token_info() has a call to l() in its date custom format definition. With the following modules enabled, this causes issues with theme initialisation:

This is because the following happens on the first load after cache clear:

  1. The theme is initialised, and hook_custom_theme() invoked.
  2. og_custom_theme() calls og_context(), which loads various entities, including a file
  3. file_entity_file_load() then replaces tokens in image alt/title text using token_replace().
  4. This invokes token_replace() which in turn invokes all implementations of hook_tokens().
  5. addressfield_tokens_tokens() is called, which calls token_info(), which calls system_token_info() which calls l()
  6. l() initialises the theme but we still haven't finished initialising the theme the first time around

This causes the custom theme to not be set correctly, until the second load of the page after cache clear.

The fault could lie be anywhere in the above call stack and to determine that, I guess we have to answer if it is reasonable for a hook_custom_theme() implementation to load entities (probably), if it is reasonable for a hook_tokens() implementation to call token_info() (maybe not) and if it is reasonable for a hook_token_info() implementation to call l() (probably).

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

msmithcti’s picture

Status: Active » Needs review
FileSize
766 bytes

This patch is the simplest solution, but probably not the actual eventual fix needed here.

Status: Needs review » Needs work

The last submitted patch, 1: core-token-info-initialise-theme-2483811-1.patch, failed testing.

msmithcti’s picture

Status: Needs work » Needs review
FileSize
767 bytes

Ah, syntax error there. Here's an updated patch.

DamienMcKenna’s picture

KeyboardCowboy’s picture

Patch #3 will fix the issue in the system module, but contrib modules may also introduce the same error. Please see the issue in #4 for a more comprehensive option.

DamienMcKenna’s picture

The answer is yes, this is a duplicate of #2086335.