Composer is a package manager similar to NPM for JavaScript, but for dealing with PHP packages. We use it to manage Drupal core, contributed modules (and other 3rd party libraries needed) and patches. The following section is a quick reference for common tasks. Ensure you have installed/updated Composer before proceeding.
*Note about Git: While this will be obvious to most, it bears mentioning that after you're finished installing, updating or patching with Composer, you'll need to add the changes/additions to version control.
Note: When a specific version isn't specified, composer prefers stable over RC over beta over alpha over DEV releases.
Install a new module.
composer require drupal/module_name --prefer-dist
Install a specific version of a new module:
composer require drupal/module_name 8.x-1.2 --prefer-dist
Note: --prefer-dist
is used to download the source of the module (Pantheon's recommendation since submodules are not supported). This will NOT work if:
- (a) the module doesn't have a
composer.json
file - (b) the version you are downloading doesn't have a
dist
value specified (which is the case for dev versions). In this case the Git repository will download (because this is all Composer knows about). This will be recognized as a Git submodule, which isn't supported on Pantheon. The current recommendation is to manually remove the.git
repository, which will allow you to commit the module source.
Update a module to latest preferred version (see above note) of installed module:
composer update drupal/module_name
Update to a specific version of an installed module:
composer require drupal/module_name 8.x-1.2
Remove a module:
composer remove drupal/module_name
To update Drupal core, use the require command and note the specific version:
composer require drupal/core 8.1.3
We're using the Composer Patches project to manage patches in an automatically via Composer. Check out its project README for further documentation. To apply a patch, and commit it to this environment, take the following steps:
- Open
composer.json
and find"extra": { "patches": { ... } }
.
- Add an entry for the patch you are working with, in the following format:
"drupal/module_name": { "Description of what the patch does": "https://www.drupal.org/files/issues/path/to/patch.patch" }
- Apply the patch with Composer:
```sh
composer install
-
Ensure the
composer.lock
file is up to date.
composer update --lock