The .info file and other files
Hi,
I'm writing a module in Drupal 7 with both classes and functions. I want to split these over several files and call one function from another file. I notice that some files need to be declared in the .info file and others not. I'm having problems with 'seeing' functions whose definition resides in other files when called from another file.
What are the rules here? Can someone point me in the direction of some good documentation?
Thanks in advance.
Martin.
If anyone else is wondering about this, I found a good post on the buildamodule blog:
The correct way to include files in your drupal module
However, I do have one remaining question. Is there a way to run module_load_include() once only in each file? I seem to have to call it in each function that may need it.
I'm feeling a little lonely here. Is all this obvious to everyone or are massive code files in fashion now?
Cheers,
Martin
Hello Martin,
Here are some thoughts on your questions:
- You should add any file that includes function definitions in your .info file. After you edit the .info file, you will need to clear your caches in order to register the new data in the info file.
- You should be able to run module_load_include() in a hook_init() function if you want to load it on every page.
Let me know if this works for you!
Cheers,
Chris
Actually, one thing I have noticed is that if you edit the .info file without disabling and uninstalling the module, the Drupal installation itself becomes confused - understandably so. Having deleted the database followed by a complete re-install, it started to behave itself much better.