By nicxvan on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
11.2.x
Introduced in version:
11.2.0
Issue links:
Description:
You can now provide install time requirements in a special class with the following requirements:
- The filename must match the classname, for example,
ModuleInstallExampleRequirements.phpmust contain the classModuleInstallExampleRequirements - It must be in the
Drupal\<module>\Install\Requirementsnamespace and located in a sub-directory of the modulesrc/Install/Requirements - It must implement
Drupal\Core\Extension\InstallRequirementsInterface; - It must have a
public getRequirementsmethod that returns an array of requirements as specified inInstallRequirementsInterface. - 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