How to Apply a Patch in Drupal Using Composer
In this tutorial, I’m going to explain how easy it is to patch a module.
Sometimes, when we use a contrib module in Drupal, we encounter a bug. Chances are that someone has already fixed it and contributed a patch to the Drupal community.
First, let’s assume our site root folder is /var/www/public/drupal_site.
This example will patch the module Scroll to destination anchors (https://www.drupal.org/project/scroll_to_destination_anchors)
These are the steps to apply a patch to a module using Composer:
Add the module with Composer
To download the module to our site, all we have to do is run this command in a terminal while being in the site root folder:
composer require drupal/scroll_to_destination_anchors
This command will download the module to /var/www/public/drupal_site/modules or /var/www/public/drupal_site/modules/contrib (if we have created this directory, which is recommended).
Find a patch
Finding a patch for the module is easy. It can be done from the module page (see example link above). There’s a column that says: “Issues for XXX”, in my example case…