Last updated July 2, 2015. Created on January 10, 2015.
Edited by rrfegade, webflo, moshe weitzman, davidwbarratt. Log in to edit this page.
Composer can be used to add dependencies to a Drupal project.
This can be done by modifying the included autoload.php.
Existing Project: Execute composer install
NOTE: Executing composer install will delete everything in your core directory and download the core version from the repository above. Any modifications in core will be lost.
New Project: Execute composer create-project drupal/drupal my_site_name 8.0.*@dev
Executing the command will download drupal/drupal into a folder named my_site_name and then execute composer install.
Point autoload.php to the proper vendor directory
By default, autoload.php is pointed to the core/vendor directory. Since we now have a custom <root>/vendor directory, autoload.php needs to be updated.
Change this line from:
return require_once __DIR__ . '/core/vendor/autoload.php';to:
return require_once __DIR__ . '/vendor/autoload.php';Now your Drupal project is using your custom vendor directory and has loaded all of Drupal core's dependencies. You can modify the root composer.json to require whatever project you'd like.
For instance, you can require the Guzzle OAuth Subscriber by adding this:
"guzzlehttp/oauth-subscriber": "0.1.*"and execute composer update or you could execute this command:
composer require guzzlehttp/oauth-subscriber 0.1.*which will modify your composer.json file for you and execute composer update guzzlehttp/oauth-subscriber.
You can also use Composer to manage modules, themes, etc. by using a Drupal Packagist. Composer downloads dependencies recursively. If a module defines a dependency, simply require the module and Composer will download the module and the module's dependencies.
Note the great starter kit for Drupal 8 projects and another for Drupal 7 projects.
Looking for support? Visit the Drupal.org forums, or join #drupal-support in IRC.