Drupal - How to restrict a module to a specific core version?
Using core only supports the major version, but you can add a dependency on the system.module with a specific version.
dependencies:
- system (>=8.3)
Due to a bug in version parsing, you can only do this with the minor version. You can't specify a patch release like 8.3.1.
You can check in hook_requirements like so:
function mymodule_requirements($phase) {
// code
$version = \Drupal::VERSION;
// code that checks version info here
return $requirements;
}
If $version
is not what you're expecting, throw a REQUIREMENT_ERROR. In fact, there is sort of an example on the docs page.
function mymodule_requirements($phase) {
$requirements = [];
// code
$version = explode('.', \Drupal::VERSION);
// code that checks version info here
if ($version[0] == 8 && $version[1] < 3) {
$requirements['mymodule'] = [
'title' => t('My Module'),
'description' => t('This module requires Drupal 8.3.0 or higher before it can be installed.'),
'severity' => REQUIREMENT_ERROR
];
}
return $requirements;
}