Modern Drupal Development with Composer

PHPSW Lightning Talks - November 2016

Oliver Davies

  • Senior Drupal/PHP Developer
  • Appnovation Technologies
  • @opdavies

The Old Ways

  • Download an archive from Drupal.org
  • Use Drush commands (drush dl)
  • Use Drush Make

Composer

  • Drupal Packagist (deprecated)
  • Composer endpoints on Drupal.org (beta)
  • Manage core and contrib as dependencies
  • Both Drupal 7 and 8

Why?

  • "Getting off the island"
  • Better versioning support
  • Easier updates
  • Automatic dependency management

Add a new repository


$ composer config \
repositories.drupal composer \
https://packages.drupal.org/8
					

composer.json


{
  "repositories": {
    "drupal": {
      "type": "composer",
      "url": "https://packages.drupal.org/8"
    }
  }
}
					

Custom directories


"extra": {
  "installer-paths": {
    "modules/contrib/{$name}": ["type:drupal-module"],
    "profiles/contrib/{$name}": ["type:drupal-profile"],
    "themes/contrib/{$name}": ["type:drupal-theme"]
  }
}

Adding Modules


$ composer require drupal/pathauto:^1.0

...

  - Installing drupal/token (1.0.0-beta2)
    Downloading: 100%

  - Installing drupal/ctools (3.0.0-alpha27)
    Downloading: 100%

  - Installing drupal/pathauto (1.0.0-beta1)
    Downloading: 100%
    				

Adding Modules with Dependencies


$ composer require drupal/address:^1.0

...

  - Installing commerceguys/addressing (v1.0.0-beta1)
    Downloading: 100%

...

  - Installing drupal/address (1.0.0-rc3)
    Downloading: 100%
    				

Composer template for Drupal projects

  • Downloads core into web/
  • Custom directories for modules, themes, profiles
  • Manages directories and file permissions
  • Includes Drush and Drupal Console

Composer template for Drupal projects


$ composer create-project \
drupal-composer/drupal-project:8.x-dev \
some-dir --stability dev \
--no-interaction
    				

Demo

Resources

  • Using Composer to manage Drupal site dependencies - https://www.drupal.org/node/2718229
  • Composer template for Drupal projects - https://github.com/drupal-composer/drupal-project

Questions?