function hook_update_requirements

Check requirements before running database updates.

This hook is invoked when update.php is run and when database updates are triggered via the CLI.

Return value

array An associative array where the keys are arbitrary but must be unique (it is suggested to use the module short name as a prefix) and the values are themselves associative arrays with the following elements:

  • title: The name of the requirement.
  • value: The current value (e.g., version, time, level, etc).
  • description: The description of the requirement/status.
  • severity: (optional) The requirement's result/severity level, one of:

    Defaults to REQUIREMENT_OK.

Related topics

1 invocation of hook_update_requirements()
update_check_requirements in core/includes/update.inc
Checks update requirements and reports errors and (optionally) warnings.

File

core/lib/Drupal/Core/Extension/module.api.php, line 1297

Code

function hook_update_requirements() {
    $requirements = [];
    // Test PHP version
    $requirements['php'] = [
        'title' => t('PHP'),
        'value' => phpversion(),
    ];
    if (version_compare(phpversion(), \Drupal::MINIMUM_PHP) < 0) {
        $requirements['php']['description'] = t('Your PHP installation is too old. Drupal requires at least PHP %version.', [
            '%version' => \Drupal::MINIMUM_PHP,
        ]);
        $requirements['php']['severity'] = REQUIREMENT_ERROR;
    }
    return $requirements;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.