I enjoy keeping my Drupal development skills sharp. One of the ways I do this is through code contributions in various contrib projects like Markdown Easy and Smart Trim. In this quicktip, I'll show you what my typical workflow is when working on a code contribution.
Often, working on issue forks and merge requests requires a local copy of the project's Git repository. If the project you're working on doesn't have any Composer dependencies, then the process is generally very straight-forward; just clone the project directly into your web/modules/contrib/ (or similar) directory and you're good-to-go.
But, if it does have Composer dependencies, cloning it into the modules/contrib/ directory won't trigger Composer to install dependencies. In this case, I:
Create a project-root modules directory.
Clone the contrib project into the new modules directory.
Modify the composer.json's repositories section as follows:
"repositories": {
"0": {
"type": "path",
"url": "./modules/*"
},
"1": {
"type": "composer",
"url": "https://packages.drupal.org/8"
}
},Note the new path repository, the new indexing of the repositories, and the curly braces for the entire object.
Finally, run composer require drupal/project_name (obviously replacing project_name with the project you're working on.)
Not only will this method gather the project's Composer dependencies, but it will also symlink the project into your site's web/modules/contrib/ directory. This method supports having multiple contrib projects cloned in the /modules directory and added to the site's codebase via composer require.
I also use this method when teaching people how easy it is to contribute during our weekly DrupalEasy office hours (available exclusively to DrupalEasy long-form course alumni) and just recently realized I didn't have it documented anywhere.
AI was not used in the authoring of this quicktip.
Comments
Great tip. I even use the…
Great tip. I even use the path repository when I start a module that has the potential to be contributed later. That way I don't have to declare the dependencies in my project composer.json and is easier later to move to contrib.
composer.json "only" key
Also note that if you use a lot of custom repositories with Composer, it's going to get slower and slower during updates because Composer doesn't know to not check every Git repository, and those are far slower to access than Packagist or similar Composer repositories. The way around this is to add an "only" array to your repository to tell Composer a set of packages should only be checked for in that repository: https://getcomposer.org/doc/articles/repository-priorities.md#filtering…
We use that pretty heavily in Omnipedia's composer.json where we have many custom modules, each with their own repository entry: https://gitlab.com/neurocracy/omnipedia/omnipedia/-/blob/main/composer…
PB and ddev-drupal-contrib
I’ve had this issue open for a bit - I wonder if this is perhaps the answer, too. “Clone, then ddev start”
https://www.drupal.org/project/project_browser/issues/3477288
Add new comment