Drupal users need to know how to use Composer to manage a Drupal codebase and its dependencies, including installing and updating packages, and Drupal specific Composer configuration options.
This course covers Composer basics, specifying package versions, configuring Composer for Drupal-specific needs, deploying projects to hosting environments, and troubleshooting common issues. By the end of the course, you will be able to use Composer to streamline your Drupal development workflow, ensuring efficient dependency management and project maintenance.
Key topics
- Understanding what Composer is and how it benefits Drupal projects
- Installing Composer and running basic commands to get started
- Structure and components of a Composer project
- Managing different versions of Composer packages
- Drupal-specific requirements and configuration
- Deploying a Composer-managed Drupal project to a production environment
- Identifying and resolving common issues that arise when using Composer with Drupal
What Is Composer?
FreeComposer is the preferred dependency management solution for PHP. List your project's dependencies in a composer.json file and, after issuing a few commands in the CLI, Composer will automatically download your project's dependencies and set up autoloading for you. Composer is analogous to NPM in the Node.js world, or Bundler in the Ruby world.
Drupal core uses Composer to manage non-Drupal dependencies like Guzzle and PHPUnit. An increasing number of contributed modules also use Composer to integrate third party PHP libraries into Drupal.
This series provides guidance for Drupal developers and site builders who would like to learn to use Composer to build and maintain a Drupal application.
It covers high-level concepts about Composer and walks you step-by-step through creating a new application, downloading PHP libraries, and implementing them using Composer!
It also covers Drupal-specific Composer configuration and provides guidance for accomplishing common Drupal tasks like updating core and installing a new module.
In this tutorial we'll:
- Familiarize ourselves with the general concepts of dependency management
- Learn about Composer and the role it plays in a PHP/Drupal project
- Learn about some advantages and disadvantages of using Composer
By the end of this tutorial you should be able to explain what Composer is, what it's used for, and make the case for using it in your own projects.
This tutorial demonstrates the value of using Composer. This demonstration will employ the most basic use case of using Composer to create a new, non-Drupal application that writes a message to the system log. It will encompass the fundamental concepts of Composer installation, requiring (installing) a new dependency, autoloading it, and implementing it.
In this tutorial we'll:
- Install Composer
- Use Composer to start a new project
- Use Composer to require a 3rd party dependency
- Use the required code in an example application
By the end of this tutorial you should be able to explain the value of Composer, and have Composer installed and working on your local machine.
Every Composer project is made up of a few standard files and directories. This tutorial provides an overview of the anatomy of a Composer project, and the essential files and directories used by Composer, including:
- What are composer.json and composer.lock files?
- What is in a composer.json file?
- What is the /vendor directory?
By the end of this tutorial you should be able to recognize the standard files and directories in a Composer project and know what they are each used for.
Composer packages use semantic versioning to allow you to differentiate among different releases of a project. Knowing how this works, and how to specify a version constraint when requiring a Composer package are an important part of using Composer.
In this tutorial we'll:
- Get an overview of semantic versioning
- Look at how Composer version constraints work and related best practices
- Learn how to define Composer package requirements such that you can quickly update all of your application's dependencies without breaking existing functionality
By the end of this tutorial, you should understand how semantic versioning relates to Composer, and how to specify version constraints for packages in your Composer project.
Managing a Drupal application with Composer requires a few modifications to Composer's default behavior. For instance, Drupal expects that specialized packages called "modules" be downloaded to modules/contrib rather than Composer's default vendor directory.
Additionally, it is common practice in the Drupal community to modify contributed projects with patches from Drupal.org. How do we incorporate Drupal-specific practices like these into a Composer workflow?
In this tutorial we will:
- Address all of the Drupal-specific configuration necessary to manage a Drupal application using Composer
By the end of this tutorial you should know how to configure Composer to work with Drupal, and drupal.org.
When managing your Drupal project with Composer you'll use Composer commands to download (require) modules and themes that you want to install, as well as issuing commands to keep those modules and themes up-to-date when new versions are released.
In this tutorial we'll:
- Cover step-by-step instructions for performing common Composer tasks for a Drupal application
- Install and update Drupal projects (core, modules, themes, profiles, etc.) using Composer
- Convert an existing application to use Composer
By the end of this tutorial you should know how to use Composer to install, and update, Drupal modules and themes.
This tutorial provides an overview of the concept of an "artifact" and provides step-by-step instructions for deploying a Composer-managed Drupal application to a hosting environment.
In this tutorial we'll:
- Define what an "artifact" is
- Look at how to use Composer and a build process to create and deploy an artifact
- Talk about the benefits of this approach
By the end of this tutorial you should have a general understanding of the steps required in order to deploy a Composer-managed project into production.
You will inevitably encounter Composer issues that require troubleshooting. This tutorial aims to provide some general troubleshooting advice for common Composer issues.
In this tutorial we'll look at:
- Common issues you'll encounter when using Composer
- Solutions to these common issues
By the end of this tutorial you should have some ideas of how to solve common issues that you might encounter when using Composer to manager your application's dependencies.