English version was created automatically using Drupal module auto_node_translate and free DeepL translator.
How do I install a module that doesn't meet the minimum requirements for installation, but there is already a patch that addresses this?
zveřejněno 2023-01-17
There are still quite a few modules that don't have a version for Drupal 10. Yet there is often already a simple automatic patch created with the rector tool. With two tools - mglaman/composer-drupal-lenient and cweagans/composer-patches this can be elegantly solved.
Just like Drupal 9, Drupal 10 now requires a module compatibility update. Quite often this can be a change to just one line in the info.yml file. It's just that unless the maintainer of the module releases a new version, you can't install the module using composer. And any patches are applied after the installation, which doesn't happen.
This is what the composer-drupal-lenient tool allows us to do, which basically changes the info.yml content with the definition of the supported kernel to ^8 || ^9 || ^10. The change will only take place for composer installation, the real disk file will contain the original value, e.g. ^8 || ^9.
Installing module trim unsupported versions
https://www.drupal.org/project/trim
We have a trim module that is only compatible with Drupal 8 and Drupal 9.

Installation in Drupal 10 will not work:
composer require 'drupal/trim:^1.0'

But there is already a patch that fixes this "Automated Drupal 10 compatibility fixes" https://www.drupal.org/project/trim/issues/3290139
It's really simple
-core: 8.x
-core_version_requirement: ^8 || ^9
+core_version_requirement: ^8 || ^9 || ^10
But how to install it automatically?
1) Installing composer-drupal-lenient
https://github.com/mglaman/composer-drupal-lenient
Installation is not difficult. We install the package
composer require mglaman/composer-drupal-lenient
and then use a simple command
composer config --merge --json extra.drupal-lenient.allowed-list '["drupal/trim"]'
to edit composer.json. So during the next attempt, core_version_requirement will be temporarily replaced and the module will be successfully downloaded.

But this is not the end of our work, because the module(s) are downloaded, but with the original trim file content.info.yml

2) Install composer-patches
https://github.com/cweagans/composer-patches
This package will allow us to automatically apply selected patches for our modules. Again, the installation is not complicated:
composer require cweagans/composer-patches
We need to edit composer.json accordingly, adding a patches section with the module name and the path to the patch file.

But how come the installation fails again?

This is due to the fact that patches are always created for the latest development version. So we have to install that one.
composer require 'drupal/trim:1.x-dev@dev'

Everything has been successfully downloaded and autobatched, all that's left is to enable the module.

In conclusion
It may look complicated at first, but basically after installing composer-drupal-lenient and composer-patches we are done. If we come across a module that doesn't have a Drupal 10 version yet, but there is already a patch that brings the necessary compatibility, we just put it in the composer-drupal-lenient list and define the appropriate patch. The composer will take care of the rest.