If you're working with Drupal 10 and want to use Drupal 9 modules, you might run into some compatibility issues. In this guide, I'll show you a straightforward way to make them work together.
Step 1: Inclusion of Module Repository
First, you need to add the module's repository to your project's composer.json file. This file helps manage dependencies and compatibility.
Let's say that we want to use the "media_library_extend_youtube" module. Right now (05 Sep 23) this is how the status of the media_library_extend_module looks like
2.0.0-alpha1 released 25 September 2021
Works with Drupal: ^8.8 || ^9
Install:
composer require 'drupal/media_library_extend_youtube:^2.0@alpha'
Development version: 2.x-dev updated 20 Nov 2020 at 09:07 UTC
Here's how to do it:
Step 1: Inclusion of Module Repository
First, you need to add the "media_library_extend_youtube" module's repository to your project's composer.json file. This file helps manage dependencies and compatibility. The key here is instead of including it via drupal we use the drupal-gitlab prefix.
Here's how to do it:
"repositories": [
{
"type": "package",
"package": {
"name": "drupal-gitlab/media_library_extend_youtube",
"type": "drupal-module",
"version": "2.0@alpha",
"source": {
"type": "git",
"url": "https://git.drupalcode.org/project/media_library_extend_youtube.git",
"reference": "2.x"
}
}
},
Be careful here with the versioning because it really matters a lot! We should not put any restrains here (like ^2.0@alpha for example) because composer will start to complain about it.
Step 2: Module Key Update
Now, update or add the "media_library_extend_youtube" module key in your composer.json file. This tells Composer to treat the module as a dependency.
"require": { . . . .
"drupal-gitlab/media_library_extend_youtube": "2.0@alpha",
. . . .
}
Step 3: Patch Integration
You may need to apply patches to make the module compatible with Drupal 10. To do this, you'll need the "cweagans/composer-patches" package.
Add this to your composer.json file:
"require": {
"cweagans/composer-patches": "^1.7"
},
Next, add the patch information under the "extra" section:
"extra": {
"patches": {
"drupal/media_library_extend_youtube": {
"Drupal 10 compatibility": "patches/contrib/media_library_extend/media_library_extend_youtube_d10.patch"
}
}
}
You might want to use directly the patch url as well.
You can apply patches either from a patch file or a URL.
Step 4: Root Composer Dependency
Check if the module has a composer.json file within its repository. If it does, make sure to include its dependencies in your project's root composer.json.
Make sure to add them under the "require" section.
Testing
After following these steps, test your Drupal 10 instance with the "media_library_extend_youtube" module. You should be able to use it without issues.
Remember to remove the code related to patching and repository inclusion once the module gets a Drupal 10 release.
Conclusion
Upgrading Drupal 9 modules for Drupal 10 is essential to keep your website up to date. By following these simple steps, you can ensure compatibility and take advantage of the latest features and improvements in Drupal 10.
Originally inspired by https://www.specbee.com/blogs/how-incorporate-drupal-9-compatible-modul…