I just learned now that you should not include composer.json files in submodules.

But can I have a reference to a submodule as a dependency?

Imagine I have a module named AAA with a submodule named BBB and I have a module named CCC with a submodule named DDD with a dependency on the submodule BBB.

Now it is clear to me I don't need to put a composer.json file inside the submodule DDD, I need to put the composer.json file inside the module CCC folder.

But I need to make the dependency with the module AAA or with the submodule BBB?

Something like this for module CCC is correct?

  "require": {
    "drupal/BBB": "^1",
  • Composer deals with package dependencies, and packages are defined by a composer.json file in the root of the package. It might be possible to create a pseudo package which references a sub-folder of another package (not sure), but conceptually, if, in your example, module CCC requires BBB, then by definition the package dependency is on AAA, as that's the package that contains the files you need. Composer doesn't know about Drupal module installation dependencies, those are a separate thing which, for sanity's sake, you probably don't want to get mixed up with Composer dependencies – Clive Mar 24 at 9:19
  • @Clive made sense for me but I tried composer require drupal/BBB and the module AAA was downloaded. It is true is a little weird as the namespace BBB doesn't exist in drupal.org. In the other hand even if you add the module AAA as a dependency you should have as a dependency the submodule BBB in the info.yml file of the submodule DDD and there is clear you only need BBB and not AAA in your project. – Adrian Cid Almaguer Mar 24 at 14:01
  • Oh fair enough, that's interesting. In that case, maybe the packager on d.org is doing a lot more than I knew it was, and facilitating this through composer.json by declaring the submodules as "proper" packages – Clive Mar 24 at 14:11

Your Answer

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

Browse other questions tagged or ask your own question.