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) An instance of \Drupal\Core\Extension\Requirement\RequirementSeverity enum. Defaults to RequirementSeverity::OK.

Related topics

5 functions implement hook_update_requirements()

Note: the procedural functions in this list are found by pattern matching, so the list may include some functions that are not actually implementations of this hook.

ModuleUpdateRequirementsHooks::updateRequirements in core/modules/system/tests/modules/module_update_requirements/src/Hook/ModuleUpdateRequirementsHooks.php
Implements hook_update_requirements().
PackageManagerRequirementsHooks::update in core/modules/package_manager/src/Hook/PackageManagerRequirementsHooks.php
Implements hook_update_requirements().
PgsqlRequirementsHooks::checkRequirements in core/modules/pgsql/src/Hook/PgsqlRequirementsHooks.php
Implements hook_update_requirements().
SystemRequirementsHooks::updateRequirements in core/modules/system/src/Hook/SystemRequirementsHooks.php
Implements hook_update_requirements().
UpdateScriptTestRequirements::update in core/modules/system/tests/modules/update_script_test/src/Hook/UpdateScriptTestRequirements.php
Implements hook_update_requirements().
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 1311

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'] = RequirementSeverity::Error;
  }
  return $requirements;
}

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