Closed (fixed)
Project:
Ubercart Out of stock Notification
Version:
6.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
13 Oct 2011 at 18:41 UTC
Updated:
28 Oct 2011 at 18:10 UTC
uc_out_of_stock module seems to be invoking hook_init a second time with different path arguments when I am on a product page. I have a drupal_set_message in a custom implementation of hook_init, and the first time hook_init is called my logic for checking the current path works fine, but then it's called again with uc_out_of_stock/query as the path arguments and my logic gets screwed up because it thinks I'm on a different page now.
I'm not totally sure this is a valid bug, is the problem that hook_init is being called a second time, or is the problem that my call for drupal_set_message is in the wrong place?
- uc_out_of_stock 6.x-1.x-dev
- Drupal 6.22
Thanks,
Eric
Comments
Comment #1
hanoiiThis module does not invoke hook_init by itself. The only reason why you experience this is because this module makes an ajax call to uc_out_of_stock/query, which is, on itself, a different page, so you get another hook_init() call how drupal works. You should probably not add messages on hook init or if you have to do so, just use the argument to decide whether not to do so on certain paths. But this is not something I am doing, is how drupal works and because of the ajax call.
Comment #2
ericbroder commentedWow, thanks for the super quick response hanoii!
Any suggestions for where this should go instead? I'm trying to do something like, "show this message unless user is on path X".
Comment #3
hanoiiWell, not really sure, but even if you want to do it there, you can.. just do show this message unless ser is on path x or user is on uc_out_of_stock/query and that should do it for you.
Comment #4
ericbroder commentedThanks for the advice hanoii. I just found another case where hook_init is also being called a second time, by imagecache module, so I think it's not really practical to put a comprehensive list of path exceptions for the message.
I saw that update module is actually using hook_help for error messages, so I tried that instead. And there's an interesting comment in the docs:
http://api.drupal.org/api/drupal/developer--hooks--core.php/function/hoo...
And apparently ctools module is making sure that hook_help is only called once:
http://drupalcontrib.org/api/drupal/contributions--ctools--includes--men...
I'm not exactly a hook_help expert, but so far so good on this method. Thanks for your help!