The new core_version_requirement
key in *.info.yml
files for modules, themes, and profiles now supports semantic versioning as implemented by the Composer project. This allows modules, themes, and profiles to also specify that they are compatible with multiple major versions of Drupal core.
For example a module that is compatible with Drupal 8 and Drupal 9 can have a info.yml file like this
name: My Module
type: module
core: 8.x
core_version_requirement: ^8 || ^9
This specifies that the module is compatible with all versions of Drupal 8 and 9. The core:
is required here because Drupal Core versions before 8.7.7 do not recognize the core_version_requirement:
key.
To define a module as compatible with all versions of core from 8.7.7 onwards, you may use the notation ">=8". If your module is unaffected by Drupal 8 or Drupal 9 deprecations, this will allow it to continue to be installed on Drupal 10 and later releases without having to update the .info.yml each time.
name: My Module
type: module
core_version_requirement: ">=8"
Many modules however will have to remove deprecated code to be compatible with Drupal 9. Therefore they will not able to be compatible with all versions of Drupal 8.
For example a module that is compatible with Drupal 8 versions after Drupal 8.8.0 and also Drupal 9 will need a info.yml file like this:
name: My Module
type: module
core_version_requirement: ^8.8 || ^9
The core:
key must not be used here to make sure that versions of Drupal before 8.7.7 will not install the module. Adding both core and core_version_requirement with anything other than core_version_requirement: ^8 || ^9
will result in an exception.
The core_version_requirement
cannot be used to restrict to core version before 8.7.7. For instance, core_version_requirement: ^8.7 || ^9
would throw a parsing exception: This is not valid because ^8.7
would include versions like 8.7.0 which do not recognize the core_version_requirement:
key.
It is important when using the new core_version_requirement
key with anything other than core_version_requirement: ^8 || ^9
that module be tested on Drupal 8.7.7 or later.
It is also possible to specify the same requirement in composer.json, but if no drupal/core requirement is defined there, one will automatically be generated based on core_version_requirement
. This has been implemented in #3084063: Use information in info.yml files to determine project requirements.
{
"require": {
"drupal/core": "^8.7.7 || ^9"
}
}
Test modules
Note that test modules can omit the core_version_requirement key entirely as of Drupal 8.8.2, so that they will work with any core version they are tested against. Prior to 8.8.2, the value is required for test modules and will cause site errors if it is not included. These errors are even encountered if $settings['extension_discovery_scan_tests'] = TRUE;
is not enabled in settings.php.
Add the following to the test module info.yml files:
package: Testing
Drupal 10 compatibility
For Drupal 10 compatibility, core_version_requirement
is still used. Once you ensured the project is otherwise compatible with Drupal 10, specify the version constraint to allow Drupal 10 compatibility. Such as for a project compatible with both Drupal 9 and 10:
name: My Module
type: module
core_version_requirement: ^9 || ^10
Comments
If you are also rolled your
If you are also rolled your head around when you saw this CR because you expected [PP-3] Provide optional support for using composer.json for dependency metadata lands in the core then
check this comment which tries to explain why info.yml-s got extended with an additional "feature" that is again a duplication of what Composer can/should handle.
IOW, you still need to add constraints to both composer.json and info.yml-s...
⚠️ As of January 9, thanks to
⚠️ As of January 9, thanks to #3084063: Use information in info.yml files to determine project requirements, this is no longer necessary! 🥳
The single pipe logical OR
The single pipe logical OR operator is deprecated in composer.json (|), and shouldn't be used. The correct syntax to use in composer.json is the double pipe logical OR operator (||).
So the example should be e.g.
Test modules core key needs to be removed also
In test modules I also had to remove the "core" key in the info.yml file to make tests pass in Drupal 9.
I've noticed that unless I
I've noticed that unless I put the core_version_requirement in quotes in my yaml, Drupal doesn't recognize the module.
Version ranges other than 8.8 - 9.
Prior to this change, it was possible to specify a minimum minor version using a dependency on the system module (or any other core module) eg
drupal:system (>=8.5)
.I would assume that a range of "
^8.5 || ^9
" (or other ranges not achievable with core_version_requirement alone) can therefore still be achieved by combining the newcore_version_requirement: ^8 || ^9
with the oldcore: 8.x
anddependencies: [ 'drupal:system (>=8.5)' ]
.Update many .info.yml files at once
To simply update many .info.yml files, use this Bash beauty:
find web/modules/contrib/your_module | grep .info.yml | xargs sed -i 's/core: 8.x/core_version_requirement: ^8 || ^9/'
It removes the "core" line, so you need to be at least running Drupal 8.8.0.