By larskhansen on
Hi,
I've read here on drupal.org that a .module shouldn't be more than 50 lines.
My question is, how do I split a node module file that contains the following functions:
_menu, _node_info, _perm, _access, _form, _insert, _update, _delete, _view and a bunch of "home-made" functions.
I would like to split it into inc files in order to keep the module file to a minimum for better performance.
Regards,
Lars Hansen
Comments
You need to keep your hook
You need to keep your hook functions in the main .module file. They cannot be in the .inc files.
The rest of your functions can go in .inc files. If you have theme functions that you are putting into .inc files, make sure you set 'file' in your theme declaration in hook_theme().
Contact me to contract me for D7 -> D10/11 migrations.
None?
Hi Jay,
So none of the hook_ functions from the core can be moved?
Thanks for your reply.
Regards,
Lars Hansen
The best you can do is put
The best you can do is put stubs in your module file which loads and then executes he main routine in an .inc file:
but for the example hooks you've provided they are usually pretty short, you need to weigh up the load time against space saved. Performance isn't just about size of file, every additional file load can have a significant overhead.
It's only a worthwhile trick for code which is infrequently executed (like a settings page) or if the code required is particularly big.
Steve Turnbull, D8 developer
Like Science Fiction, Fantasy or Steampunk stories? Check out https://taupress.com/book-list