Skip to content

Instantly share code, notes, and snippets.

@jacine
Last active August 31, 2016 19:13
Show Gist options
  • Save jacine/3ce8c9f9aef3ea5891270af0f1995f07 to your computer and use it in GitHub Desktop.
Save jacine/3ce8c9f9aef3ea5891270af0f1995f07 to your computer and use it in GitHub Desktop.
Composer

Composer Workflow

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.

Contributed Modules

Note: When a specific version isn't specified, composer prefers stable over RC over beta over alpha over DEV releases.

Installation

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.

Updates

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

Removal

Remove a module:

composer remove drupal/module_name

Updating Drupal Core

To update Drupal core, use the require command and note the specific version:

composer require drupal/core 8.1.3

Applying and Managing Patches

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:

  1. 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment