Install patches in Drupal with composer

To enable patching with composer on a Drupal site, we need to install composer-patches.

composer require cweagans/composer-patches

Next, open the site's composer.json file and find the "extra" section that looks like this:

    "extra": {
        "drupal-scaffold": {
            "locations": {
                "web-root": "web/"
            }
        },
        "installer-paths": {

And make it look like this:

    "extra": {
        "patches-file": "composer.patches.json",
        "enable-patching": true,
        "drupal-scaffold": {
            "locations": {
                "web-root": "web/"
            }
        },
        "installer-paths": {

This will enable patching in a referenced external file, but first we need to create the file, "composer.patches.json" in the root directory along-side the composer.json. It can look like this to start:

{
  "patches": {
  }
}

When Drupal core or other modules require patches, add them to the composer.patches.json file in this format:

    "drupal/core": {
        "Twig debug output does not display all suggestions when an array of theme hooks is passed to #theme": "https://www.drupal.org/files/issues/2020-01-13/2118743-181-twig-debug-info.patch",
        "#3045171-140: Forms break Layout Builder saving.": "https://www.drupal.org/files/issues/2020-02-04/layout-builder-save-issue-3045171-140.patch"
      },
    "drupal/token": {
        "Consistent tokens support across all entities and fields": "https://www.drupal.org/files/issues/2019-04-12/token-consistent-entity-and-field-support-3047568-6.patch"
      },

And, after updating the patches file with a new patch, run:

composer update

 

Article Reference

Add new comment

The content of this field is kept private and will not be shown publicly.
Enter a comment.