git apply

Drupal 9 Upgrade: Patching Modules 101

Not all contributed D8 modules have D9 compatibility built into their latest releases. More than a few, however, will have a patch available in their open issues that will get you there. I've had several occasions to patch a module, but it's not something I do with enough frequency to immediately recall how it's done. On the command line I often forget which is the right way to do it: git apply or patch?

Prepping for a Patch

As with all things Drupal--attention to detail is paramount. It's easy to get ahead of yourself when looking for and applying a module patch, but one of the first things you'll want to do when you find one is to ensure that the patch was built for the module version you're using. A patch is a file that applies very specific changes to an already existing file. If the existing file you have on your site (say, the info.yml file associated with a module) differs from the one the patch was created for, the patch will likely fail.