How to apply a Drupal / contrib patch with the cweagans/composer-patches package


Applying patches in drupal 8 is different compared to drupal 7.

Composer does a decent job alleviating the headaches of managing several sites with different dependencies. However, out of the box Composer will revert patched core files and contrib modules and it is for that reason composer-patches project was created. In this blog post, we are going to review how to set up composer-patches for a composer managed project and how to specify local or remote hosted patches. [from

If you have not yet installed then you should first install the cweagans/composer-patches package ( via composer

composer require cweagans/composer-patches:~1.0 --update-with-dependencies

Now after this you can open your /root/composer.json file and add this section within the extra section like this

   "extra": {
        "drupal-scaffold": {
            "locations": {
                "web-root": "web/"
        },//This is where you apply the patches
        "enable-patching": true,
        "patches": {
            "drupal/username_policy": {
                "username policy default value issue": ""
            "drupal/core": {
                "Fix Admin Toolbar Language Issue": "",
                "FIx Permissions Translate Content Can Edit Issue": ""

The format for each patch is : “Patch description”: “path to patch file”

Run composer validate in order to make sure your json format is valid, and then run composer update

If everything is ok you should see the applying patches for drupal/core message with success

Good Luck!
this is an arrow pointing back to the top of the page