5

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?

10

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.

2

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;
}
  • Thanks for the code stub. This seems like overlooked item in D8 core. Does this warrant submitting an issue to core? – amit Apr 18 '17 at 17:58
  • No, this is valid, see Berdir's answer for another valid approach. – Kevin Apr 18 '17 at 17:59
  • Thanks. I'll choose @Berdir's answer as that'll work once hooks are deprecated or eliminated in 9.x – amit Apr 18 '17 at 18:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.