Change record status: 
Project: 
Introduced in branch: 
11.2.x
Introduced in version: 
11.2.0
Description: 

You can now provide install time requirements in a special class with the following requirements:

  1. The filename must match the classname, for example, ModuleInstallExampleRequirements.php must contain the class ModuleInstallExampleRequirements
  2. It must be in the Drupal\<module>\Install\Requirements namespace and located in a sub-directory of the module src/Install/Requirements
  3. It must implement Drupal\Core\Extension\InstallRequirementsInterface;
  4. It must have a public getRequirements method that returns an array of requirements as specified in InstallRequirementsInterface.
  5. The code must not use any other code from the module as it loaded prior to the module being installed.

This works for profiles and modules.

These requirements will be merged with hook_requirements('install').

This is not a hook.

Before:

<?php

declare(strict_types=1);

function module_install_example_requirements($phase) {
  return [];
}

After:

<?php

declare(strict_types=1);

namespace Drupal\module_install_example\Install\Requirements;

use Drupal\Core\Extension\InstallRequirementsInterface;

class ModuleInstallExampleRequirements implements InstallRequirementsInterface {

  /**
   * {@inheritdoc}
   */
  public static function getRequirements(): array {
    return [];
  }

}
Impacts: 
Module developers
Site templates, recipes and distribution developers