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.
Problem/Motivation
- Configuration files for the configuration system are stored in a
/config
directory in the module root. - Many modules like Views have multiple modules (views.module and views_ui.module) sharing the same directory.
- As a result, configuration files from these submodules would be mixed together.
Proposed resolution
- Require that each module reside in its own directory.
- Update core to comply with this standard by placing all test modules in their own directories.
- Additionally move test files from
core/modules/simpletest/tests
to the more correct location incore/modules/system/tests
or to the tests directory for the appropriate core module.
Remaining tasks
- The change was discussed with maintainers of affected contributed modules and they agreed to the change.
- Core is now compliant with the standard, with each module located in its own directory.
- All automated test files for the core base system are now located within the system module directory.
- Automated test files related to a specific module are located within the appropriate module directory.
Comments
Comment #1
fabsor CreditAttribution: fabsor commentedIf we are picky about still having the possibility of having more than one module in the same directory we might rename the config directory to {module_name}_config.
Personally, I think one module per directory is fine.
Comment #2
Dave ReidI would much rather have a consistent behavior for modules and have separate directories per module.
Comment #3
merlinofchaos CreditAttribution: merlinofchaos commentedOk, so, I don't actually have a problem with module per directory.
HOWEVER
1) I object to magic naming of directories. It would be very to allow the actual name of the directory to be configured, either through a .info property or a hook or something.
2) Moving a .module file around is problematic for users who simply untar modules over their existing modules. It leaves dead files around and can confuse the system, particularly if the file gets included twice. This is probably mostly covered here because the deeper directory should be identified, but *should be* and *will be* are separate things.
I would object to requiring module per directory so that we can magic-name a subdirectory.
Comment #4
Crell CreditAttribution: Crell commentedSeparate module per directory is the natural evolution of having all modules in a directory; until Drupal 5 or so, module files were just a .module file in /modules, and that was that. Also, someone still needs to get back to this issue: #340723: Make modules and installation profiles only require .info.yml files
So if that gets resolved, I've no problem with "a module is defined by a .info file, and whatever that location is, that's the module's folder. And only one module per folder."
I don't see any value to allowing some modules to name their config directory "config", some "configuration", some "defaults", etc. That just makes it harder to figure out what a given module is doing... especially if we want (and we do) to make the .module file itself optional. (See issue above.)
Comment #5
moshe weitzman CreditAttribution: moshe weitzman commentedModule per directory is OK with me, as are magic names. I think there is a proposed standard for how to layout projects with multiple modules. The main module goes in the root dir or something. Maybe Dave Reid knows the URL?
Comment #6
gddMoving this to the core queue where it can get some more eyeballs and consensus.
Comment #7
donquixote CreditAttribution: donquixote commentedI don't have a strong opinion about this yet.
I think it will make a few things easier: autoloading, unique config directory, etc.
On the other hand it will make for a deeper directory structure, which in some cases can hurt DX. But that's the price.
One thing i want to mention though:
If each module gets its own folder, then it would be tempting to no longer have the module name as part of filenames.
The result would be that I have tons of "something.txt" open in my file editor (which is currently gedit), with no idea which module that is.
The typical file editor shows the filename in each tab, but not the directory name. Let's keep this in mind.
One decision we also need to make is, can one module live in a subfolder of another module?
As I understand, with the current proposal, this would still be allowed.
The consequence: Given a directory name, you can not always identify which module that is.
Or can you?
Now x.inc would be considered as part of "child" module, while y.inc would be considered as part of "parent" module, because parent-dir/misc does not contain a *.info file.
Also, do we care how the sub-module subfolders are to be named and structured? Is there a risk of conflict with other "magic" folder names? (for hooks, autoload, etc)
Comment #8
glennpratt CreditAttribution: glennpratt commentedI am very much for one module per directory.
The module directory name being magic, I'm somewhat indifferent about. If we're going to have PSR-0 autoloading in modules, there will be some magic directories in them, so I'm having trouble seeing the downside.
@donquixote - As for not having the module name in every single file, YES PLEASE. That level of redundancy has lead us to put meaning in the file extensions, rather than the name of a file (.info, .profile, .module). I would much prefer common extensions and having the meaning be in the filename, not the extension. For example, AndroidManifest.xml... in the Drupal pattern we would make that MySuperApp.AndroidManifest. Consider the context (path), and the reality is self describing and requires no special configuration of my editor. That kind of magic is worse to me then magic for locating files... that kind of magic means I'm dependent on documentation.
Comment #9
RobLoachlitwol did a grep through some of the modules he uses and it turns out some of contrib does this:
In Drupal core, core/modules/simpletest/tests is probably the biggest hit on this. Personally, I have no problems with it either way. Policy doesn't matter when you just want to get your stuff working.
[EDIT] litwol wanted to add that he used this command to find them:
Comment #10
sunThat is not within the scope of this issue and thus not up for debate. Thanks.
Comment #11
sunSince the initial config patch landed, this is a critical issue now (as we can't release without adding and enforcing the policy or changing the system).
Comment #12
webchickI haven't really seen any opposition of this change in this issue, even from people whose modules would be affected by it. RTBC?
Comment #13
bojanz CreditAttribution: bojanz commentedI'd like to see explicit approval from a few of the affected maintainers.
Comment #14
webchickOk, so who's going to reach out to them via e-mail/Twitter/IRC tell? We're over thresholds atm, and this might be an easy win.
Comment #15
chx CreditAttribution: chx commentedAs one of the affected, I don't care much. We are on git now, adding a git mv to the D8 porting process won't hurt me.
Comment #16
richthegeek CreditAttribution: richthegeek commentedI'm going to assume that there's something stopping the config files from not being merged (ie, using the file extension to identify the config file, like Views might have views.conf).
If it's simply a case of apathy on the file-based-config team versus apathy on the part of everyone else, I'd be in favor of going for the one that requires the minimum effort...
However, if it does go ahead with enforcing one module per directory, I'd like to see better documentation in bundling multiple modules into one download (ie Views + Views UI) because currently that's sort of a dark art (I don't even know if it's possible).
Anyway, i'll get back to the bikeshed now.
Comment #17
RobLoachWe shouldn't mess with things in the Drupal 7 contrib world. If we fix it in Drupal 8 Core, then contrib will follow the "standard". This doesn't really need to be a policy, as it actually means just cleaning up some of the file structure for tests and such.
Comment #18
sunComment #19
xjmI haven't seen anything more here about how we're going to handle the test modules inside
simpletest/
. Suggestions?Edit: I guess it's just a matter of moving a lot of files and rolling a patch, eh? Do we need to use
git am
to keep the history of the files?Comment #20
RobLoachThe following are the modules in Drupal 8 Core that have multiple .module files in the same directory:
@xjm, stick the following into your ~/.gitconfig:
What if we just moved each into their own specific folwer?
./core/modules/entity/tests/entity_cache_test.module --> ./core/modules/entity/tests/entity_cache_test/entity_cache_test.module
./core/modules/simpletest/tests/menu_test.module --> ./core/modules/simpletest/tests/menu_test/menu_test.module
Comment #21
dixon_I think it's very sensible to restrict to one module per directory. It enforces a clear structure.
Simply, I have no objections.
Comment #22
sunAs far as the modules in simpletest are concerned, those will have to be moved to sub-directories, too.
Comment #23
aspilicious CreditAttribution: aspilicious commentedOk everyone agrees. For this issue we need to do 2 more things.
1) create an issue that fixes the simpletest folder structure
2) add a new section on the coding standards
Something like this?
Folder structure
---------------------
In Drupal 8 and later each module must live in a seperate directory. The configuration system enforces this change, as it's otherwise unable to dissect which configuration files belong to which module. This only means that there cannot be two .info files in the same directory. A drupal.org project/repository/package may still contain multiple modules (e.g., typical API + UI modules, but also more). The modules merely need to be in separate directories.
Comment #24
xjmSo based on #9 it might be good to ping:
Comment #25
xjmThe restructure in #22 looks good to me.
Comment #26
webchick<kittens>
Hey, as long as we're moving stuff anyway, can we move those damned tests under system module instead, where they actually belong? :P</kittens>
I'm fine with the answer being no, btw. ;)Comment #27
sunActually, #22 was scripted to account for future re-rolls, but I forgot to attach the script.
To be executed from within core/modules/simpletest/tests.
Doesn't account for the additional modules mentioned in #20.
Comment #28
xjmAh, looks like we'll also want to run sun's script from within
node/tests
,search/tests
,update/tests
, andentity/tests
.Edit: Oh, and +1 for getting them out of the simpletest directory.
Comment #29
chx CreditAttribution: chx commentedmerlin http://twitter.com/merlinofchaos/status/176412657463738370 agreed
Comment #31
agentrickardJust so we're clear: submodules within subfolders would still be allowed?
Breaking that pattern would make me angry.
Comment #32
Dave ReidUnofficially on behalf of JohnAlbin menu_block won't be a problem at all.
Comment #33
Crell CreditAttribution: Crell commentedagentrickard: Yes.
foo/foo.info
foo/config (for config files)
foo/lib (for classes)
foo/bar/bar.info
foo/bar/config (for config files)
foo/bar/lib (for classes)
All in one download from drupal.org/project/foo.
Totally fine.
And +1.
Comment #34
bleen CreditAttribution: bleen commentedGenerally I support this as well (now that #31 has been clarified) but I do have a couple questions:
What would the behavior be if someone did have two .module files in the directory? Which .module would be used? I'm guessing that if the main folder is /foo then foo/foo.module would "win" over foo/bar.module? If I'm correct about that, are we enforcing the convention that given a folder name of /foo, then the module *must* be named foo.module?
Comment #35
Crell CreditAttribution: Crell commentedAssuming that the rest of the current logic is intact, then I suspect what will happen is something like:
(assuming someone fixes #340723: Make modules and installation profiles only require .info.yml files, please do so!)
Which in turn means that both modules in the one directory would "claim" config and lib and so forth, which in turn would cause all sorts of weird undefined behavior when those config files are loaded twice. Whether or not that would break anything in practice is, I suppose, dependant on what those files are doing. Let's not find out. :-)
Comment #36
merlinofchaos CreditAttribution: merlinofchaos commentedPlease note that my agreement is grudging and I really think we should make sure that the alternatives are explored before we do it. It would be sad if we remove this sorta feature without really thinking about whether or not we can do it a better way. As I said previously, I'm against more magic naming.
Comment #37
fagoI'd be fine with a "one module per directory" rule - as I think it's going to group things better together and makes clear what file belongs to which module.
Updating modules which move around is currently quite a pain though - in particular if your module might be invoked before update.php does its work... I hope the new PSR-0 autoloader should be a help then.
Comment #38
fagoComment #39
chx CreditAttribution: chx commentedthis is unacceptable, plain and simple. Plenty of countexamples in contrib.
Comment #40
sunyeah, #39 is not the proposal.
Comment #41
Dave Reidre #39/40: It should however still remain a best practice (unrelated to this issue).
Comment #42
chx CreditAttribution: chx commentedagreed. best practice yes, hardwire, no.
Comment #43
jonhattanDrush has a lot of black magic to:
* figure out what's the project for a given module
* obtain the installation path of a project
* fight wrong practices as adding the same
project=
line to separate projects' .infoThe lack of policy in this area has been a continuous source of failures in drush package management (I figure out a similar problem is present in the update manager). So in what concerns drush, I don't mind best practices, but policies.
In concrete I'd like to see the main module in the root dir (per #5) or something like projectname.info (or projectname.project or whatever) in the root dir. Would be great if in addition such a file declares its extensions there explicitly, instead of using the
project=
key added by the d.o packaging system to each .info file it finds.Comment #44
Niklas Fiekas CreditAttribution: Niklas Fiekas commented#22 + found some half-hardcoded paths.
@xjm: No,
git am
is not required. Git doesn't do anything special to store renames, it just works by being the same or a similar file.Comment #45
Niklas Fiekas CreditAttribution: Niklas Fiekas commentedOk. Now moving node, search, update and entity tests around, too. Naively. Let's see what the results are.
Comment #47
sunwow, I wouldn't have thought that this would require so many file changes...
In light of that, I'm inclined to agree with @webchick... it would make sense to move the testing modules from
simpletest/tests
tosystem/tests/modules/$module
, since we're already moving them here, and moving them to System is on the table since D7 already, so in the end, we'd move them twice for D8 unless we'd move them to the final destination now already. Merely not sure whether it's acceptable to only move the modules for now (not the .test files).Comment #49
Niklas Fiekas CreditAttribution: Niklas Fiekas commentedgit.d.o down, so #45 might or might not be valid.
This would move modules and .test files to system module.
Comment #51
Niklas Fiekas CreditAttribution: Niklas Fiekas commentedRetesting both:
#45: 1299424-test-directory-structure-45.patch queued for re-testing.
Comment #52
Niklas Fiekas CreditAttribution: Niklas Fiekas commentedAnd:
#49: 1299424-test-directory-structure-49.patch queued for re-testing.
Comment #54
Niklas Fiekas CreditAttribution: Niklas Fiekas commentedLet's see how this works.
Comment #56
Niklas Fiekas CreditAttribution: Niklas Fiekas commentedUpgrade path tetsts passing locally now :)
Comment #58
Niklas Fiekas CreditAttribution: Niklas Fiekas commentedNext round.
Comment #60
Niklas Fiekas CreditAttribution: Niklas Fiekas commentedThose update tests are passing locally now, too.
Comment #61
glennpratt CreditAttribution: glennpratt commented#60 looks good to me. Installs and tests fine locally.
Does this policy also apply to themes? Seems like that would be a valuable consistency when we think about detecting projects and DX.
Comment #62
Crell CreditAttribution: Crell commentedI don't know that you can put multiple themes in one directory now in the first place. I agree that we want to be consistent between modules and themes, though.
Comment #63
xjm#60: 1299424-test-directory-structure-60.patch queued for re-testing.
Comment #64
aspilicious CreditAttribution: aspilicious commented#60: 1299424-test-directory-structure-60.patch queued for re-testing.
Comment #65
Niklas Fiekas CreditAttribution: Niklas Fiekas commentedNote that this applies and tests well, but that new unmoved test cases have been added in the meantime. Reroll attached.
Comment #66
Crell CreditAttribution: Crell commentedGiven its fragility, should we consider committing #65, then following up with another patch to catch the new test cases? In the mean time we can start insisting that any new test cases/test modules follow the new approach once this goes in.
Comment #67
Niklas Fiekas CreditAttribution: Niklas Fiekas commentedSorry. More clear: #65 contains all new test cases (as of now), just not the patch requeued in #64.
Comment #68
xjmLet's do this thing.
Comment #69
MichelleFYI: Commerce is a big one for sub-modules and I just looked and it already is putting modules in separate directories (aside from the UI module).
Comment #70
aspilicious CreditAttribution: aspilicious commented#65: 1299424-test-directory-structure-65.patch queued for re-testing.
Comment #72
Niklas Fiekas CreditAttribution: Niklas Fiekas commentedAh, yes: #1503184: Convert Graph.inc to PSR-0 (and make its documentation clearer). Thank you. Btw. you forgot to remove the
file[]
entry, there ;)Comment #73
Niklas Fiekas CreditAttribution: Niklas Fiekas commentedOh ... and I forgot to remove the
file[] = graph.test
, too.Comment #74
Niklas Fiekas CreditAttribution: Niklas Fiekas commented(Upload failed, doing wierd things to the issue. Retagging.)
Comment #75
aspilicious CreditAttribution: aspilicious commentedBack to rtbc, time to commit!
Comment #76
catch#74: 1299424-test-directory-structure-73.patch queued for re-testing.
Comment #77
catchCommitted/pushed to 8.x, this is less prescriptive than PSR-0 and much smaller in terms of directory changes given the surveys of contrib modules done above. Will need a change notice.
Comment #78
webchickDone. http://drupal.org/node/1532250
Comment #79
xjmComment #80
xjmThere are two separate but complementary changes in the patch: We moved all core modules into their own directories (which in practice mostly meant test modules), and we also moved base system tests out of the simpletest module directory into the system module directory. We need a second change notification for the second change.
Tagging novice for the change notification because this one is nice and straightforward. See http://drupal.org/node/1487226 for instructions. Please also update the issue summary to summarize both changes when you create the change notice. Thanks!
Comment #81
Paul Simard CreditAttribution: Paul Simard commentedI can get to this later today.
Comment #81.0
Paul Simard CreditAttribution: Paul Simard commentedUpdated issue summary.
Comment #82
Paul Simard CreditAttribution: Paul Simard commentedI think http://drupal.org/node/1540510 covers it. As this impacts those using system tests in their own testing, and devs writing in core only, it seems sufficient as is. If not, feel free to let me know, and I'll try again.
If all is OK, though, feel free to switch to RTBC or fixed as appropriate.
Comment #83
Niklas Fiekas CreditAttribution: Niklas Fiekas commentedExcellent, that looks good. Thank you.
Comment #84
xjmThanks @Paul Simard! I added an example to the change notification and simplified the wording a little.
Comment #84.0
xjmUpdated issue summary.
Comment #85
xjmAlso updated the summary to more closely reflect the status of the issue.
Comment #85.0
xjm(xjm) Update summary with current status.
Comment #85.1
neclimdulNot that some tests also moved to their respective modules testing directory, not just to the system module.
Comment #85.2
xjm(xjm) Grammar fix.
Comment #86
c960657 CreditAttribution: c960657 commentedRegression:
This caused the database tests to go missing, see #1558268: Database tests are not available.
Comment #87.0
(not verified) CreditAttribution: commentedUpdated issue summary.