質問

Drupal 8.3 introduced some changes, which broke a custom module; fixing the changes causes the module to break in previous Drupal versions. One way to handle this would be to require Drupal core to above version 8.3+ for this module. However, the following changes to YAML file does not work.

core: '8.3'
core: '8.3.x'

Drupal shows the following incompatibility message.

This version is not compatible with Drupal 8.x and should be replaced.

The official documentation does not provide useful information for core keyword.

So how should Drupal core version requirement specified in the .info file? If not, is there any other way to specify such requirement?

役に立ちましたか?

解決

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;
}
ライセンス: CC-BY-SA帰属
所属していません drupal.stackexchange
scroll top