How to apply a patch to Drupal using Composer

Apply a patch to Drupal using Composer

Intro

This guide is for users who need to apply a specific update or change that has not yet been incorporated into a module's official release.

A patch is a small piece of code used to fix a bug, correct a security vulnerability, or add a new feature to a software program without replacing the entire file. Think of it as a quick fix or a bandage for code. It's essentially a set of instructions that tells the program what lines of code to remove and what new lines to add or change.

Patches for Drupal modules and core are available on Drupal.org

 

Setup:

Web server running on Ubuntu 18.04, 20.04, 22.04, LAMP stack
Drupal 8,9,10,11
Installed Drush, Composer

 

Prepare

In order to install and manage patches using Composer, we must first require the cweagans/composer-patches plugin. This will then allow us to apply patches automatically.

Warning

Before starting the update, the most important step is to backup the entire site.

 

Add required package to be able to apply patches
composer require cweagans/composer-patches

Install cweagans/composer-patches package

 

Specify the patch to install via Composer

The next step is to put the patch installation directive in the composer.json file

Edits to composer.Json file
"patches": {
"drupal/core": {
"FileUploadResource declares a non-existent deprecated property service patch": "https://www.drupal.org/files/issues/2025-07-14/3519726-21.patch"
}
},

We would need to edit composer.Json file, 
add the code that will tell Composer to install our patch.

 

Final step: Run Composer update

After we've placed our patch for Drupal core in composer.json file, we need to run the Composer update command. This will launch the update operation and install our specified patch.

Running Composer command to trigger custom patch installation
composer update drupal/core

We need to run composer update command so the patch will be installed to our Drupal installation

Updating the Drupal core with a custom patch via Composer
Updating the Drupal core with a custom patch via Composer

Summary

This guide explains how to apply a patch to a Drupal 10 project using the cweagans/composer-patches plugin. The process involves adding the patch details to your composer.json file and then running composer update to apply the fix.