I have put together a module package that has 3 sub-modules. They must be contained in a single folder to be distributed and used by other devs. Are there drupal best practices for how a module's files structure should be if it contains just multiple modules?







For what i've seen, putting sub modules in a modules folder like your first example is most common best practice.

| improve this answer | |
  • Agreed. Views does this, as does Rules. Though, I think most also put the common / base module at the top-level. – mpdonadio Jun 24 '12 at 16:04
  • In commerce it's done like that aa well. – BetaRide Jun 24 '12 at 17:18

There aren't Drupal best practices about where to put submodules. You could:

  • Put them in a separated sub-directory of "modules" contained in the directory containing the main module
  • Put them in a separated sub-directory of the directory containing the main module
  • Put them in the same directory containing the main module

Any of those directory structures is used:

  • The Views module has a "modules" sub-directory, but that is not for sub-modules; both view.module and views_ui.module are in the same directory that contains the main module.
  • The CCK module has a "modules" directory where all the sub-modules are each contained in a separated directory.
  • The Panels module has its sub-modules saved in a separated directory contained in the main directory.
  • The Views Bonus Pack module uses three different sub-directories of the main directory.

There isn't actually a reason related to how Drupal handles modules, to choose a structure or another one.
There is a reason to choose the first two structures instead of the third one, and that is generally that each module comes with other files that are grouped in directories with the same name (e.g., css, js, templates), and you don't want to mix files that are for different modules.

| improve this answer | |

I do the second one. Also please realize that the modules directory in Views does not contain modules at all.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.