Posted by Corneloues on June 9, 2010 at 11:59am
I''ve added a dependency to my modue by adding the line dependencies[] = token to my .info file.
However when I try to call the token_replace() or any other token function I get the "Call to undefined function" error from php.
Have I missed something? Have searched for site for a "How To" for dependencies without any joy.
Cheers,
Roy
Comments
Is token downloaded and
Is token downloaded and installed? It may seem like a stupid question, but if you already had your module installed before adding the dependency, the token module may not be installed.
Full-time freelancer, always looking for work.
jaypan.com (my portfolio)
Token is installed... but after...
I've downloaded, installed and activated token. I can even see in the module list that my module shows the dependency and that it is enabled.
However I did install token after I started developing this module. Do I need to uninstall and re-install my module now?
Thanks for the quick reply,
Roy
info file
The dependencies[] inside the info file is called when installing the module. If you activated the module before adding the line, of course it wont spit out any error after you added it.
OK...
So by uninstalling my module and re-installing it all should be fine...?
Uninstall/Reinstall - Still No Joy...
So I disabled the module and then unistalled it. I could see that the variables had been removed from the table so I know the unstall had been called.
Went back to the module list and re-enabled it.
Same error.
Roy
Try including the module
Try including the module file:
module_load_include('module', 'token', 'token.module');I have no idea if that will work or not (I've only ever used it with .inc files) but it's worth a try.
Full-time freelancer, always looking for work.
jaypan.com (my portfolio)
Where do I put it? Also, just
Where do I put it?
Also, just seems odd that there is no immediately available documentation on this. A lot of modules appear to depend on others, so it must be quite common to get this working. All the threads I've seen on this all seem to take the same approach: try this, try that... What is the "Drupal Way" to do this??? Is there a link anywhere to explain this?
Cheers,
Roy
Well the Drupal way is that
Well the Drupal way is that the file should automatically be included if it is installed, so you don't need to do anything. All module dependencies mean is that a module cannot be installed without it's dependencies first being installed. But all .module pages for all modules are compiled together when Drupal bootstraps. Since the function in question is not working for you, it means one of three things:
1) The token module isn't installed
2) The function for some reason doesn't exist in the token.module file (maybe the file got erased)
3) Something is wrong with your Drupal setup and/or the core files have been modified, causing it for so for some reason it isn't including the .module file.
The reason that you get 'try this' 'try that' is because we don't have access to your site to figure out what the problem is so we are basically taking shots in the dark.
You could try being thankful instead of being pissy about it.
Full-time freelancer, always looking for work.
jaypan.com (my portfolio)
Not being pissy...
I didn't mean to come across that way, so I apologise...
The site is a very fresh 6.17 deployment. I'm purely working on this module so there is no content and no users apart from the admin user.
I am however, tweaking the module via my cPanel interface using the editor to change the files...
All has been working great. If I remove the dependency to token and revert back to my own token functions everything is fine. I realise however that reinventing the wheel is not the done thing, so using token is the next logical step for my module and for my own learning...
The docuemntation on module development has been really useful. It just seems to stop short of, or mention, module dependencies. Now I know that they should "just work", I can focus my attention on this issue.
Cheers,
Roy
You can put the code I gave
You can put the code I gave you before the function call to token_replace().
You can also try uninstalling and re-installing both modules.
And finally, when you say you are changing stuff through the cpanel, do you mean you are editing your database directly? You really shouldn't do that until you know for sure exactly what you are doing, and even then it's a little risky.
Full-time freelancer, always looking for work.
jaypan.com (my portfolio)
No database changes
No I'm not changing the database. There are no DB requirements for this module. I'm simply editing the php in the cPanel code editor.
Cheers,
Roy
That's all good then. I
That's all good then.
I didn't know that cpanel had a code editor actually.
Full-time freelancer, always looking for work.
jaypan.com (my portfolio)
Now I get a different undefined function call...
Now I would assume drupal_get_path() is a core function..
Fatal error: Call to undefined function drupal_get_path() in /home/.../public_html/includes/module.inc on line 271
Cheers,
Roy
It is. That means you've got
It is. That means you've got something funky going on in your site.
To track it down, you can/should do two things. First, re-upload Drupal as a whole. This is to make sure you have a clean core. If this doesn't fix the problem, start disabling modules one at a time until you figure out which one is causing your troubles.
Are you running hook_boot in your module by the way?
Full-time freelancer, always looking for work.
jaypan.com (my portfolio)
I am actually...
I'm using an exsting module as a template.
Cheers,
Roy
drupal_load()
Just read some more on the site and found out about drupal_load(). Added this to hook_boot() and the errors have gone away.
Just need to get token to respond now...
Thanks for your help,
Roy
You shouldn't need to do
You shouldn't need to do that. You have repaired the problem, but you would be better to find out where it was coming from in the first place for two reasons:
1) Since the problem is still in there somewhere, it may show itself in other places in the future
2) It may already be doing #1 - which could be where your problems with the token module is coming from.
Did you try to track down the problem the way I suggested a couple of posts back by disabling modules.
Full-time freelancer, always looking for work.
jaypan.com (my portfolio)
Disabled all modules
Yep, disabled them all - included the optional core modules that were ticked.
Only modules enabled were mine and token. Problem still persists unless I add the drupal_load() function.
Also replaced all the core files (everything except the sites folder) and still no joy...
Cheers,
Roy
That's good news then - it
That's good news then - it means the problem is in your module. You managed to track it down to that.
Now start taking code out of your module until you figure out exactly what is causing the problem.
Full-time freelancer, always looking for work.
jaypan.com (my portfolio)
I see where you're coming from...
The module works just fine until I integrate token!!!
I'll have a play though and see if I can narrow it down. There are no other dependencies - very little at all to be honest... Which is what is confusing me the most...
Cheers,
Roy