In this post we want to share some recipes for using Composer, which we have accumulated while working with Drupal projects created using the Drupal Composer template. We will also look at how to transfer an existing Drupal project to Composer.composer require drupal/<MODULE_NAME>:~8.0 to install the latest stable release (or the latest dev version if there are no releases for Drupal 8 yet)composer require drupal/<MODULE_NAME>:dev-<BRANCH_NAME> to install the latest dev versioncomposer require drupal/<MODULE_NAME>:dev-<BRANCH_NAME>#<COMMIT_HASH> to install a specific versioncomposer update to update everythingcomposer update --dry-run to check for updatescomposer update drupal/<MODULE_NAME> to update a specific module "extra": { "patches": { "<PACKAGE/NAME>": { "<PATCH DESCRIPTION>": "<PATH/TO/PATCH/OR/URL>", ... }, ... } } "extra": { "patches": { "drupal/core": { "Fix language detection": "patches/2189267-24.patch" } } } composer install to apply patchcomposer update nothing (or composer update --lock ) so that the composer-patches plugin composer update --lock necessary changes in the composer.lock file "repositories": [ { "type": "vcs", "url": "https://github.com/<REPOSITORY/NAME>" }, ... ], composer require drupal/<MODULE_NAME>:dev-<BRANCH_NAME>#<COMMIT_HASH> to install the module. "repositories": [ { "type": "package", "package": { "name": "drupal/<MODULE_NAME>", "version": "dev-custom", "type": "drupal-module", "source": { "type": "git", "url": "git@github.com:<REPOSITORY/NAME>.git", "reference": "<BRANCH-NAME>" } } }, ... ], composer require drupal/<MODULE_NAME>:dev-custom#<COMMIT_HASH> to install the module. "extra": { "installer-paths": { "web/modules/custom/<MODULE_NAME>": ["drupal/<MODULE_NAME>"], ... } } "repositories": [ { "type": "package", "package": { "name": "enyo/dropzone", "version": "4.3", "type": "drupal-library", "source": { "url": "https://github.com/enyo/dropzone.git", "type": "git", "reference": "master" }, "dist": { "url": "https://github.com/enyo/dropzone/archive/v4.3.0.zip", "type": "zip" }, "require": { "composer/installers": "~1.0" } } }, ... ], ... "extra": { "installer-paths": { "web/libraries/{$name}" : ["type:drupal-library"], ... } } composer require enyo/dropzone:4.3 to install the library. Notice that we specified a specific version and added a “dist” section so that Composer could download the zip archive instead of cloning the repository. "repositories": [ { "type": "vcs", "url": "https://github.com/<REPOSITORY/NAME>" }, ... ], composer require <PACKAGE/NAME>:dev-<BRANCH_NAME>#<COMMIT_HASH>composer require specific version for each dependency. You will need to translate the Drupal version into the Composer version, here are some examples:drupal/core:8.1.8 it all fitsdrupal/admin_toolbar:8.1.15 implies admin_toolbar 8.x-1.15drupal/ctools:8.3.0-alpha26 implies ctools 8.x-3.0-alpha26drupal/config_installer:dev-8.x-1.x#a16cc9acf84dd12b9714def53be0ce280a5b0c1a implies the dev version of the config_installer created from the a16cc9a branch 8.x-1.xcomposer drupal-scaffold , this will create the necessary root Drupal files.Source: https://habr.com/ru/post/313298/
All Articles