I was lead to this problem by a bug (#264187) that Summit posted on my project. It really took me some time to follow it but I believe I found a proper solution.
The problem is that token_replace() is a function that caches its results, thus, my module was calling it, and token was calling yours to respond to your tokens ([page-title]) but the actual page title at the time of calling was not the latest one. Then, when your module calls token_replace() agian, the cached results are returned with an incorrect title.
I am attaching a patch to your module where I 'flush' the token internal array before calling all the substitutions your module performs, then assuring that the latest page title would be available for the [page-title] token.
Hope this helps.
a.=
| Comment | File | Size | Author |
|---|---|---|---|
| #21 | page_title.module.264662.token_replaced_too_early.patch | 1.42 KB | hanoii |
| #14 | page_title.module.patch | 1.92 KB | hanoii |
| #7 | page_title.module.patch | 1.02 KB | hanoii |
| #6 | page_title.module.patch | 821 bytes | hanoii |
| page_title.module.patch | 821 bytes | hanoii |
Comments
Comment #1
hanoiiI misstyped the proper formatting for the link to the bug reported on my module, adding it here: #264187: Interfering with page_title module?
Comment #2
nicholasthompsonI believe this was also a problem when Custom Breadcrumb was used... I'll have to speak to the Token maintainer about this...
Comment #3
hanoiiWell, I first thought that it was a token module problem as well, but then I don't think that caching is a bad idea, and as they give developers a chance to flush the cache and in the case of your module I believe that flushing it before replacing the actual token is a proper way of using the token module.
Just a thought.
Thanks,
Ariel.=
Comment #4
summit commentedHi,
I try to get this working. In the patch there is referring to removing:
But I can't find token_get_values('global', null, TRUE); on the alpha5 page_title.module sourcecode?
Shouldn't it not be:
greetings,
Martijn
Comment #5
nicholasthompsonLooks like the patch was built the wrong way around - it seems to be patching from modified to unmodified.
Comment #6
hanoiiIt certainly was... sorry.. here's the proper one
Comment #7
hanoiiBy following another reported conflict on my module with this one #276355: Losing my Page Title and Tabs when adding tags on nodetypes I detected another issue that led me to a patch on this module. Now, in this case, is a very strange thing. I will try to explain in the best way I can. It's not a real 'bug' of this module but a chain of things triggered by my module, although there's nothing I can really do about it on my own.
The actual problem is that the tabs are disappearing if both my module and page_title are enabled.
If drupal_get_title() gets executed in the hook_menu() of any module, tabs will disappear because of some internal core menu.inc function.
Does page_title do this? Well, not directly, but it does indirectly.
My module relies on a nodewords hook where I do a bunch of token replacements. That hook is invoked on the nodeworkds_menu hook, where I trigger some token replacements. Those token replacements also trigger the token hooks on all installed modules (such as page_title) which eventually executes drupal_get_title(), triggering the tabs disappearing problem.
The best fix I found, which is a design decision for the maintainers of this module was to use a slightly different approach for retrieving the current page title.
By looking at the actual code of drupal_get_title() I noticed it does two things, first it retrieves the stored title, and if it's null, executes the actual conflicting function. As I see the logic of this module, when the function is run there will definitely be a stored title within drupal internals, so I think this is a reliable fix, or better say, change for this module.
I hope it's clear.
I am attaching a new patch that includes the two fixes mentioned on this issue.
Comment #8
nicholasthompsonI'm going to put the token cache clearing thing in as it seems the only/the most sensible fix for that problem of multiple use of tokens on 1 page...
As for not using drupal_get_title... I'm not so pleased about hearing this.
drupal_set_title to get the title only works if a call has been made to it to override the callback title. If it hasn't then Drupal falls back to the menu system to ask the menu system what the callback title is...
So are you saying that you have a module which has something which invokes the token hooks when you call drupal_get_title? Which is your module?
Comment #9
hanoiiMy module is Meta Tags Node Type and no, I am not saying exactly that.
In the issue I mentioned on #7 it was reported that the node tabs (VIEW/EDIT, etc) were disappearing if both modules were enabled.
Following that issue I found this drupal_get_title() issue. If you add drupal_get_title() just for testing in your hook_menu() function you should notice this tabs disappearing issue, even without my module enabled at all.
My module depends on a nodewords hook. That hook is invoked in nodewords_menu() hook. The nodewords hook on my module calls to token_replace() to perform some token replacements and that function invokes the token hooks on your module which eventually calls drupal_get_title().
It's the actual menu fallback function that triggers this tabs disappearing problem. My suggestion of using drupal_set_title() instead was to avoid calling to that function, but now you put it that way, it makes sense to think that if no previously drupal_set_title() was made you MUST fall back to the menu system function, thus drupal_get_title() is the function that should be used.
The problem I am facing is that I can't do anything about it on my side because IT IS the drupal_get_title() of page_title module that's triggering the problem, although triggered because it ends up being called from a hook_menu() hook through my module.
I will have to think of another solution, I already have one on my mind but I it's not very clean as well. I want to hear your thoughts first though. Did this post make things clear?
Thank you very much for replying,
a.=
Comment #10
nicholasthompsonI seeeeeee!!!
This is truely a strange problem.
So in this case I imagine the following is happening...
So you must have something in hook_menu which is invoking hook_token_values? This is obviously not your fault - I am fairly certain you should be able to ask Drupal what the title of a page will be without it deleting tabs as an act of revenge...
On one hand, using drupal_set_title is a workaround for this... but in other ways its not. The drupal_set_title command only works if a title has been SPECIFICALLY set whereas some menu callbacks wont use drupal_set_title (I imagine)...
I wonder if this is something which should be cleanly filed against drupal core?
Comment #11
hanoiiIt might be a bug for the drupal core, I would have to check this on newer versions and see if it worth a posts, I do believe as well that that shouldn't be a function that conflicts in anyway with drupal's logic.
However it's going to be definitely faster to try and find a workaround on your module and hope that you'll like it.
I'll probably post soon with more thoguhts.
Comment #12
joncup commentedsorry for the ping here, im just subscribing to the issue so I can follow it better.
Comment #13
nicholasthompsonI'm still not keen on using drupal_set_title though because that ONLY gets the title if its specifically set which, in a lot of cases, it wont be.
Another way of looking at this is that the problem ONLY happens if Tokens are initialised during hook_menu. Is there a function anywhere in Drupal where I could find out the "history" of the tree of command... Ie, "what called this?"
Comment #14
hanoiiHi Nicholas,
I spent some more time looking at this, it's really an annoying issue and I think I have come up with another solution that might be a lot better. I agree with you that drupal_set_title() is not the way to go.
Now I am attaching another patch. This patch actually fixes this issue as well as the first one posted in this thread but you don't need to flush the token's cache anymore.
The idea behind this patch is not to define your token replacements withing the token global scope. As your replacement should happen on a very specific moment (when run through the template.php hook) and considering that having it in the global may lead to this problem if my or any other module somehow triggers token replacements within the hook_menu of that module, I am defining a new token scope just for your module (page_title).
In this way, it's just your module or, if needed, any other module that needs to trigger your replacements can use this scope as well. I modified the lines wehre you called token_replace() function.
I believe this one is a better/cleaner fix and still respects the logic on your module.
I am probably going to use this module pretty soon so interested in getting this fixed as well :)
Thanks!
a.=
Comment #15
jdcllns commentedExcuse me if this isn't the right place to post in, but I found this thread while searching for answers to a problem I'm having. I'm using the page title module and the title on my home page is showing up as "!page_title". Is this caused by the situation that you're discussing here? If so, will the patch fix it? I'm sorry, but I don't really understand how to apply the patch or I'd test it out for myself.
Thanx
jdcllns
Comment #16
nicholasthompson@jdcllns: This is the wrong place - probably best to open another support issue. But in the mean time...
!page_titleis the 'token' from version 1, this is an issue regarding version 2 where the token in[page-title]. Sounds like you've configured the module incorrectly. If this doesn't fix it, please open a separate issue.@hanoii: Thanks for the patch! Looks interesting. I may try this one out at some point today. If this works then there will be a mention on the project page :)
Comment #17
EvanDonovan commentedI can confirm that the patch in #14 works on Drupal 5.7 when you have Page Title 5.x-2.0-alpha5, Token 5.x-1.11, and Meta tags node type 5.x-1.1 installed.
Comment #18
joncup commentedworks for me too. lets try to get this committed
Comment #19
nicholasthompsonCommited into Alpha 6
Comment #20
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.
Comment #21
hanoiiI believe I have to bring this issue back to life. Even after a while of upgrading the module I wasn't aware of this until recently where I noticed that the page_title on all my nodes read "Content" as also reported on #565542: Either "Content" or menu item title or a blank empty string swaps in for [page-title] token, after upgrading.
I noticed that what this patch, which was committed on alpha-6 attempted to fix was indeed happening again. By looking at the code and the CVS I noticed that somehow, the change provided by this patch was lost in Revision 1.12.2.21 of page_title.module. Funny I just noticed it now.
Attached is a patch for latest page_title version, and I think it should be applied in D6 branch as well, not sure if it'd apply clean, but I'd think so.
Hopefully you can go over the full extent of this issue as a reminder of what was happening, as same things are happening again.
Comment #22
ericbroder commentedThank you hanoii, I applied the patch in my testing environment, so far so good.
Comment #23
hanoiiJust upgraded to 2.3 and w/o my patch on #21, page-title seems to be fine now. I still consider the what the patch does to be a better practice for tokens, so probably worth a review. At least, it was accepted once.
Comment #24
nicholasthompsonI've decided that 2.3 shall be the last of the DRUPAL-5 releases. I simply do not have the bandwidth or energy to maintain that branch anymore. If anyone wishes to become a co-maintainer for the DRUPAL-5 branch, please contact me.
If this is still an issue with DRUPAL-6--2 or DRUPAL-7--2, please re-open and change the version.