As part of developing my future Drupal site, I'm planning to write a private custom module that will provide glue code for the various components, as well as customize the site as necessary. Since this will affect many unrelated parts of the website, it seems too monolithic and unmaintainable to stick everything into one module file. Writing a whole bunch of modules for one site also seems like an overkill.
What about keeping one logical module, but creating a separate include file for each piece of functionality? Is it OK to have a bunch of require_once('mymodule_search.inc') etc. calls at the top of mymodule.module or will this cause performance issues? Maybe I should be doing require_once calls right before calling into the include files (this way the file is included only when it is really necessary)?
Does anybody else organize their files this way? Is there a better way maybe?
Comments
There's actually nothing
There's actually nothing wrong with several modules for your purpose.
Also, you can have several modules in one folder, by the way. Just look at CCK.
And actually, it's far easier to maintain several modules, then one module that calls back to several non-module PHP files. This is because you are stepping outside the framework for extending Drupal. Or to put it another way, Drupal has a standard by which it's own functionality is extended. That "standard" is modules. Following this "standard" means that you'll have fewer problems than what you would have with regular old PHP files that try to tunnel into Drupal's running code. I hope this make some sense?
Good luck...
Thanks aj045, your answer
Thanks aj045, your answer makes sense. I guess I was just worried about the number of modules spinning out of control, but I can see situations where having a separate module will be more maintainable than just another include file.
I have used both approaches
I have used both approaches (all in one module vs dozens of smaller ones).
I have to say that even though it's a pain in the ass to create an separate module for something as simple as creating a menu callback and displaying some content, it's worth it just for the ability to easily enable/disable/transfer functionality to another site.
Don't worry about writing too many modules. I've had sites where I've used 50-60 modules - no problems.
However, if the code you're writing is "related," then by all means keep it in one module and use includes if necessary.
By the way, organizing your code into sections works magic for big modules:
etc.
Keeps stuff clean :)
---
Yuriy Babenko
www.yubastudios.com
---
Yuriy Babenko | Technical Consultant & Senior Developer
http://yuriybabenko.com