Because tokens are cached in Token module and Page Title declares global token type, token replacement happens too early, before we want it to run, i.e. before all preprocess functions. That causes page_title_get_title() to run too early, which causes drupal_set_title() to return empty string (cause other modules don't set page title yet), and drupal_get_title() to return value of menu_get_active_title() instead of actual page title. Than this value is cached in Token module and later in preprocess function when we want to fallback to defaul title, we actually fallback to wrong cached value.

Proof, and temporary workaround:
In function page_title_page_get_title() insert following line before calling token_replace_multiple($page_title_pattern, $types):

token_get_values('global', NULL, TRUE);

This forces flushing of Token static cache and causes Token to actually call page_title_get_title() instead of using cached value and everything starts to work as we want.
Ofcourse, this workaround should not be made bugfix, cause flushing entire token cache to clear single value is probably bad idea. However, until this is fixed properly, it's good as temporary fix.

Comments

crea’s picture

Status: Needs review » Active
crea’s picture

Title: Usage of global token breaks default page titles because of Token caching » Usage of global token breaks default page titles because of early Token caching
locomo’s picture

subscribing..

this temporary fix works for me

EvanDonovan’s picture

Subscribing. Will test this.

EvanDonovan’s picture

Actually, I decided I can't test this because flushing the entire Token cache would kill performance on my site. I'll wait till a better fix is found. Till then, I'll continue using my patch, despite its flaws.

mitylite’s picture

This accounts for panel page titles not being printed out, right? Sorry if that's obvious. The description of the problem was a little technical for me.

EvanDonovan’s picture

I think this is about the issue of your ordinary page titles (such as the ones set by panels) to be stomped by the default page title set in the Page Title module. Anyway, the issue creator referenced this issue in my issue #370856: Make Page Title show proper titles for Panels -- requires Token cache fix.

crea’s picture

@mitylite, yes, Panels titles are affected too, same as any module setting page title by calling drupal_set_title() function.

nicholasthompson’s picture

Version: 6.x-2.2 » 5.x-2.x-dev
Status: Active » Patch (to be ported)

I've committed the fix to clear the token cache to DRUPAL-6--2. It'll come out in 2.3. I'll need to apply this to the 5.x branch too.

crea’s picture

So do you think clearing whole cache is good idea ?

nicholasthompson’s picture

No, you're right. It's a bad idea!

Thing is, Page Title is broken right now, I have no other solution and the one provided "works". I understand it works only because it's enforcing an inneficiency, but I can't see any other fix right now.

I'm happy to commit a better solution if one presents itself! :-)

crea’s picture

It seems flushing token cache in case of problems is now commonly accepted practice.
And dev version of Token even has FLUSH argument built into token_replace_multiple() function. See #262360: Expose control of token caching to functions that call token_replace. It simply gets flush argument and passes it to token_get_values() function, like we are doing here directly.
So unless Token implements per-token granular cache flushing, we are stuck here. So either it should be fixed in Token module itself, or Page Title should avoid using token for default title replacements.

crea’s picture

I've opened feature request in Token queue: #619892: Per-token cache and flushing.

nicholasthompson’s picture

Status: Patch (to be ported) » Fixed

I've committed the flush cache fix to dev for D5 & D6. D7 doesn't seem to cache anything token-wise...

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

EvanDonovan’s picture

Version: 5.x-2.x-dev » 6.x-2.x-dev
Priority: Critical » Major
Status: Closed (fixed) » Active

Reopening as per my latest update to #252638: [page-title] token empty for Panels pages. Seems like this didn't fix the issue, at least in the case of Panels.

crea’s picture

Yeah, this stopped to work, it seems

crea’s picture

Oh, this is not because of Token cache. It's because Page Title has it's own cache.

crea’s picture

Status: Active » Closed (fixed)