Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By esnyder on
I have enough functions in this module that I want to split them into different files to keep them organized. I have:
my_module.info
my_module.module
my_module_more_functions.module
In my .info file I have the line:
files[] = my_module_more_functions.module
I call a function in the more_functions file and I get the error. Drupal is not seeing the functions in the second file.
Before you ask...I am clearing the cache.
How do I split functions into different files So I don't get one gigantic .module file?
Comments
I would use '.inc' as your
I would use '.inc' as your file extension rather than '.module' as that might cause Drupal to behave a bit funny. You're doing it the right way though, using the files array in the .info file
You have to explicitly include the file
Check out module_load_include(): http://api.drupal.org/api/drupal/includes--module.inc/function/module_lo.... Also, you would generally load your different functions as needed, not unconditionally.
OK. That did the trick. I did
OK. That did the trick. I did change the name of the file extension but that did not help.
Thanks, Keith! This has
Thanks, Keith! This has helped me a lot, too! Funny thing is, that I could not find this trick described anywhere else on the API. I have simply included the line in my .module file at the very top (no idea if this is best practice ;-) but it simply works!