Apply Drupal 9 patches with composer

Stavros Kounis
Appseed IO
Published in
1 min readJan 11, 2022

Prerequisites

For applying patches composer needs the “cweagans/composer-patches” package. Install it with the command:

Request the patch

In the composer.json locate the “extra” section and adjust it as follows.

  • Line 4, “drupal/core”: The package the patch targets.
  • Lines 5,6:
    - Description: A friendly description in free text.
    - Path/URL: A path in the filesystem or online URL that points to the .patch file

Note: If the “extra” section is missing create it as a root element.

Example

Let’s assume that an issue, such the one that follows, is resolved and a patch is attached to it. It is however not yet merged into the main branch.

For using the fix the initial codebase need to be adjusted by applying the changes the provided patch introduces.

Patch URI:

The “extra” section in composer.json will look as follows:

Delete the composer.lock and run composer install. The patch will be applied on top of the downloaded codebase.

For packages which are already required and locked deleting the composer.lock may bring updated versions. I this case keep the composer.lock as it is, and just run composer update --lock.

--

--

Stavros Kounis
Appseed IO

Software developer and Javascript enthusiast, passioned with web and mobile technologies, skounis.github.io