The site I manage has a custom module that makes the drupal_get_path_alias() function call. Every once in a while, this call was failing and, instead of showing the site, it would show a PHP error: Fatal error: Call to undefined function drupal_get_path_alias() in /home/asiaweb/www.asiasociety.org/htdocs/sites/all/modules/as/as_taxonomy_nav/astn.module on line 464
Someone on my web team poked around and saw that this error had occurred with a bunch of modules once Drupal was updated to 5.1.1.
To fix the error, we have put the following line of code in as instructed:
// If cache is enabled we need to load the path system
if (variable_get('cache', CACHE_DISABLED) != CACHE_DISABLED) {
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
}
before the drupal_get_path_alias function call.
However, I have some questions. Is this a hack or has the community accepted that this is the correct way to solve this problem? Has this been fixed with Drupal 5.2.1 or 5.2.0? I can find no documentation saying that it has.
Thanks.
Comments
Comment #1
catherinecolman commentedI should also mention that, as many others observed, this error was NOT showing up for logged in users, only for anonymous users.
Comment #2
grendzy commentedCan you clarify which version of Drupal you're using? There is no such version as 5.2.1 or 5.2.0.
According to http://api.drupal.org/api/function/hook_init/5:
If you implement this hook and see an error like 'Call to undefined function', it is likely that you are depending on the presence of a module which has not been loaded yet. It is not loaded because Drupal is still in bootstrap mode. The usual fix is to move your code to hook_menu(!$may_cache).
Also since this is a question about a custom module (astn.module), it may be more appropriate in the module development forum:
http://drupal.org/forum/4
Comment #3
catherinecolman commentedMy apologies. The extra '.' was unintended. We are using 5.19 and I was referring to 5.20 and 5.21.
I appreciate your reply. I agree that this relates to a custom module and will certainly direct my question to that forum. However, as previously referenced, there seem to be some documented occurrences of this happening with other modules (and possibly core modules?) and discussion that an update of Drupal caused the problem. I thought it was possible, given the limited information I have, that it warranted a bug report. Thanks!
And if anyone else has any thoughts, please let me know.
Comment #4
catherinecolman commentedComment #5
catherinecolman commentedAlso, is there a reason why you directed me to this page when we are getting the error when calling the drupal_get_path_alias() function and not when calling hook_init()? Are you suggesting that we should be using hook_menu(!$may_cache) and if so, can you elaborate?
Comment #6
grendzy commentedAs I understand your post, the error is from a call to drupal_get_path_alias() inside of hook_init(). If so, moving that code from hook_init, to hook_menu should resolve your issue.
FYI, the "needs review" status is generally used when a patch file has been uploaded for review.
Comment #7
dave reidIssues need to be filed against the modules responsible for calling drupal_get_path_alias() when Drupal hasn't been fully loaded. There's nothing we can do to fix that in core.