How do I install my own, custom module dependant on Composer?

au flag

I've looked all over, but there seems to be no advice on this online.

I've recently updated a Drupal 8 site to Drupal 9. I wasn't using composer before, and so I've used composerize-drupal to make the site composer compatible.

I have my own custom module on the site, and I had to uninstall it to get the composerize-drupal and then the upgrade to work.

I'm now trying to reinstall it, but there is a complete lack of guidance on this coming up in google searches, and if I just upload it to the site as before, the site breaks.

Can anybody please help shed some light on how this can be done on a Compserized Drupal 9 site?

miststudent2011 avatar
fr flag
If the custom module has dependencies they wont be installed. Refer
ne flag

In composer.json you tell Composer in which directories it should put certain types of dependencies.

"installer-paths": {
    "web/core": ["type:drupal-core"],
    "web/libraries/{$name}": ["type:drupal-library"],
    "web/modules/contrib/{$name}": ["type:drupal-module"],
    "web/profiles/contrib/{$name}": ["type:drupal-profile"],
    "web/themes/contrib/{$name}": ["type:drupal-theme"],
    "drush/Commands/contrib/{$name}": ["type:drupal-drush"]

These directories are now managed by Composer. For example web/modules/contrib for type drupal-module dependencies. While at the same time everything put in web/modules/custom or any other custom location will be preserved.

Your repo in the end basically only contains the composer.json/lock files at the repo root and all custom code (custom themes, custom modules, custom scripts, custom patches etc.) and config YAML files in their desired directories.

You should gamble around a bit with the official recommended-project template or the community drupal-project template. Learn to read the composer.json file. Run composer install, manually delete certain directories, composer install again and observe what happens.

in flag

composerize-drupal creates the following directories for Composer dependencies:

  • [drupal-root]/modules/contrib
  • [drupal-root]/themes/contrib
  • [drupal-root]/profiles/contrib

By convention (or at least the convention I follow), custom stuff goes in a custom directory.

  • [drupal-root]/modules/custom
  • [drupal-root]/themes/custom
  • [drupal-root]/profiles/custom

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.