function hook_runtime_requirements
Check runtime requirements and do status reporting.
Requirements are displayed on the 'Status report' (/admin/reports/status).
Runtime requirements do not impact installation or updates of modules that define them. These requirements are only used to display information on the status report but do not impact site behavior. They can be used for more general status information like maintenance tasks and security issues. The returned requirements will be listed on the status report in the administration section, with an indication of the severity level. Moreover, any requirement with a severity of REQUIREMENT_ERROR will result in a notice on the 'Configuration' administration page (/admin/config).
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 severity level, one of:
- REQUIREMENT_INFO: For info only.
- REQUIREMENT_OK: The requirement is satisfied.
- REQUIREMENT_WARNING: The requirement failed with a warning.
- REQUIREMENT_ERROR: The requirement failed with an error.
Defaults to REQUIREMENT_OK.
Related topics
2 invocations of hook_runtime_requirements()
- RequirementsTest::testUploadRequirements in core/
modules/ file/ tests/ src/ Kernel/ RequirementsTest.php - Tests the file upload requirements.
- SystemManager::listRequirements in core/
modules/ system/ src/ SystemManager.php - Displays the site status report. Can also be used as a pure check.
File
-
core/
lib/ Drupal/ Core/ Extension/ module.api.php, line 1216
Code
function hook_runtime_requirements() : array {
$requirements = [];
// Report Drupal version
$requirements['drupal'] = [
'title' => t('Drupal'),
'value' => \Drupal::VERSION,
'severity' => REQUIREMENT_INFO,
];
// Test PHP version
$requirements['php'] = [
'title' => t('PHP'),
'value' => Link::fromTextAndUrl(phpversion(), Url::fromRoute('system.php'))->toString(),
];
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;
}
// Report cron status
$cron_last = \Drupal::state()->get('system.cron_last');
$requirements['cron']['title'] = t('Cron maintenance tasks');
if (is_numeric($cron_last)) {
$requirements['cron']['description'] = '';
$requirements['cron']['value'] = t('Last run @time ago', [
'@time' => \Drupal::service('date.formatter')->formatTimeDiffSince($cron_last),
]);
}
else {
$requirements['cron']['description'] = t('Cron has not run. It appears cron jobs have not been setup on your system. Check the help pages for <a href=":url">configuring cron jobs</a>.', [
':url' => 'https://www.drupal.org/docs/administering-a-drupal-site/cron-automated-tasks/cron-automated-tasks-overview',
]);
$requirements['cron']['value'] = t('Never run');
$requirements['cron']['severity'] = REQUIREMENT_ERROR;
}
$requirements['cron']['description'] .= ' ' . t('You can <a href=":cron">run cron manually</a>.', [
':cron' => Url::fromRoute('system.run_cron')->toString(),
]);
return $requirements;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.