Apply a patch with composer | Drupal 8

Apply a patch with composer

Submitted by editor on Tue, 11/23/2021 - 14:40
Question

How to apply a patch on composer install or update ?

Step 1 : Add the package cweagans/composer-patches
composer require cweagans/composer-patches

Step 2 : Add path to the composer.json under extra section.
Syatax:
"patches": {
  "package": {
    "A description": "Url/Path"
  }
}

The Url/Path can be an external url or path to patch file.
The description is a free text, You can add something like [issues-id][Status][Short description]
Example 1: Single patch for drupal core
"extra": {
  "patches": {
    "drupal/core": {
      "Add startup configuration for PHP server": "https://www.drupal.org/files/issues/add_a_startup-1543858-30.patch"
    }
  }
}

Example 2: 2 patches for a contrib module
"extra": {
  "patches": {
    "drupal/mimemail": {
      "Fix mimemail error on admin form": "https://www.drupal.org/files/issues/mime-mail-error-message-on-admin-form-with-webprorfiler-2719981-3.patch",
      "patch 2": "https://www.drupal.org/files/issues/mime-mail-error-message-on-admin-form-with-webprorfiler-2719981-3qdqsdqsd.patch"
    }
  }
}

Example 3: 2 patches for multiple packages
"extra": {
  "patches": {
    "drupal/core": {
      "Add startup configuration for PHP server": "https://www.drupal.org/files/issues/add_a_startup-1543858-30.patch"
    },
    "drupal/mimemail": {
      "Fix mimemail error on admin form": "https://www.drupal.org/files/issues/mime-mail-error-message-on-admin-form-with-webprorfiler-2719981-3.patch"
    }
  }
}

The patches will apply on composer update or composer install.
You can also apply patch by updating the .lock file or re installing a package like:
composer update --lock
or
composer reinstall drupal/core

 

Add new comment

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.