Skip to main content
Drupal 8

Main navigation

  • Home
    • Question And Answer
    • NEWS
    • Projects
  • Tutorials - Drupal
    • Android
    • Other
User account menu
  • Log in

Breadcrumb

  1. Home

Apply a patch with composer

By editor , 23 November, 2021
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

 

Tags

  • Drupal 8
  • Code
  • Composer
Create and Apply Patches using GIT DIFF and APPLY

Comments

Plain text

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

Links

  • Drupal.org
  • Drupal core release cycle
  • Drupal events with ease
  • Unit test with Drupal using PHPUnit (Drupal 10)
  • Tokens for file upload url
  • Tips for Docker
  • CKEditor inline image files usage for custom forms.
  • Install Docker on Linux Mint
  • Install PHP 8.1
  • Drupal Security Best Practices
  • Order and sort items with tabledrag
  • Add a custom service YAML container
  • Apply a patch with composer