Contrib modules make it easy to add functionality to a website. But sometimes we need to modify one or more details in a module file.
To make this modification in the source code, we need to create a patch.
To make it easier to understand, our contrib module is called “commerce” and you also need to update it to use the latest version.
To make it easier to understand, we will divide it into two parts:
1 Creating the patch
Go to the module directory and initialize git.
public/web/modules/contrib/commerce$ git init
Next, we make our first commit:
public/web/modules/contrib/commerce$ git add .
public/web/modules/contrib/commerce$ git commit -m "init patch"
Make the necessary changes and make a second commit:
public/web/modules/contrib/commerce$ git add .
public/web/modules/contrib/commerce$ git commit -m "end patch"
Perform a "git log" :
public/web/modules/contrib/commerce$ git log
commit 11e55c90a33e28af05dbbdbead22ff03389b4d86 (HEAD -> master)
Author: kouwa stephane <kksasteph888@gmail.com>
Date: Fri Jun 7 15:54:41 2024 +0200
end pacth
commit 67b455e1c992c7f7a25acf49384a0bbb6b539c9c
Author: kouwa stephane <kksasteph888@gmail.com>
Date: Fri Jun 7 15:52:32 2024 +0200
init pacth
And finally, we will extract our patch using this syntax:
git diff [id 'init patch'] [id 'end pacth'] > [chemin absolue vers le fichier]
Example:
public/web/modules/contrib/commerce$ git diff 67b455e1c992c7f7a25acf49384a0bbb6b539c9c 11e55c90a33e28af05dbbdbead22ff03389b4d86 > /[absolute-route]/public/patches/commerce/payment-payment-gatewaybase.patch
2 Using the patch
To use the patch, you must add it to the project's composer file:
"patches": {
...
"drupal/commerce": {
"Redefinition du fournisseur d'identification des comptes de paiements": "patches/commerce/payment-payment-gatewaybase.patch"
}
...
}