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
Comment #1
crea commentedComment #2
crea commentedComment #3
locomo commentedsubscribing..
this temporary fix works for me
Comment #4
EvanDonovan commentedSubscribing. Will test this.
Comment #5
EvanDonovan commentedActually, 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.
Comment #6
mitylite commentedThis 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.
Comment #7
EvanDonovan commentedI 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.
Comment #8
crea commented@mitylite, yes, Panels titles are affected too, same as any module setting page title by calling drupal_set_title() function.
Comment #9
nicholasthompsonI'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.
Comment #10
crea commentedSo do you think clearing whole cache is good idea ?
Comment #11
nicholasthompsonNo, 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! :-)
Comment #12
crea commentedIt 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.
Comment #13
crea commentedI've opened feature request in Token queue: #619892: Per-token cache and flushing.
Comment #14
nicholasthompsonI've committed the flush cache fix to dev for D5 & D6. D7 doesn't seem to cache anything token-wise...
Comment #16
EvanDonovan commentedReopening 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.
Comment #17
crea commentedYeah, this stopped to work, it seems
Comment #18
crea commentedOh, this is not because of Token cache. It's because Page Title has it's own cache.
Comment #19
crea commentedSee #1306206: Remove page title cache and change token logic to only process tokens in the final stage.. This issue is fixed because Token is not at fault here.