Drupal World

The Rise of Composer within Drupal 8

In this blog we discuss what Composer is and how to use it in combination with — continue reading
Posted by Ronald te Brake
August 1, 2016

In this blog we discuss what Composer is and how to use it in combination with Drupal 8. 

What is Composer?

Composer is the most popular dependency management system for PHP. A dependency management system is becoming increasingly important to manage a project and keep the build consistent. One file is used to determine which version of which package has to be installed. The alternative system for Drupal is ‘Drush make’ which installs all software published on Drupal.org.

When to use Composer and Drupal

So why use Composer over Drush make? As a Drupal community we try to incorporate technologies outside of Drupal and to make our work more accessible for projects that do not use Drupal. A good example is the Address module, this module consist of integrating with an independent addressing project that can be used for all PHP projects. This separation allows all PHP developers to contribute back to the addressing project which benefits the Drupal module. Furthermore, Composer provides a gateway to include projects that have a license that is less restrictive than the GPL license which can be seen as a problem for strong ideological developers. For example the addressing project has a MIT license that allows modifications to the code without it having to be open sourced while the Drupal Address module is subjected to GPL.

Current problems when using Composer for Drupal

In Drupal 8 using Composer is encouraged and supported. Even when a module does not use external libraries it is encouraged to add a composer.json file so the module can be installed with composer. However, Drupal.org does not yet support Composer to package a distributions but requires Drush make files. The Address module requires the external addressing project to be installed with Composer but drupal.org is not able to package it. This result in the external libraries not being packaged in the tarball which caused a lot of installation issues after the initial Alpha launch of Open Social. Furthemore, the project can not be installed yet on simpletest.me which allows potential users to quickly test the platform.

Drupal.org is beginning to support composer packages for contrib modules and themes and is currently in beta but not yet for distributions or install profiles. There is significant pressure from the community to support Composer in the drupal.org infrastructure. The main driver is the CommerceGuys company that is behind the popular Commerce Kickstart distribution. They made most of their Drupal 8 modules rely on Composer. Furthemore, installing with Composer is also adopted by platform.sh, a popular Drupal hosting service.

The solution for using Composer with Drupal

For Open Social we made the decision to keep using Composer dependent modules and take the extra manual installation step for granted and support the initiative to further integrate Composer in drupal.org.

In the screenshot below you see the manual installation step of adding libraries for composer. ‘Address’ displays the library requirements in the composer.json file and by running a update the right libraries are downloaded. For detailed instructions we have set up a Documentation Guide on Drupal.org with installation instructions.

Using Composer with Drupal (8)

It is clear that Composer will fully replace ‘Drush make’ because of the many benefits and adaptation in the Drupal community. The infrastructure behind Composer with Drupal has not yet matured but we expect it will get mature soon.

Furthermore, we do our best to give support in in how to use Composer to the people that use Open Social. For the future we are evaluating the possibility to make certain features like the Activity Stream an independent project that can be used outside of Drupal and integrate it by using Composer.

Header image by Cat Sanchez, Creative Commons license.

In this article we discuss

Related articles