function security_review_requirements in Security Review 8
Same name and namespace in other branches
- 7 security_review.install \security_review_requirements()
Implements hook_requirements().
File
- ./
security_review.install, line 26 - Install, update and uninstall functions for the security_review module.
Code
function security_review_requirements($phase) {
$requirements = [];
// Provides a Status Report entry.
if ($phase == 'runtime') {
/** @var \Drupal\security_review\Checklist $checklist */
$checklist = Drupal::service('security_review.checklist');
$failed_checks = FALSE;
$no_results = TRUE;
// Looks for failed checks.
foreach ($checklist
->getEnabledChecks() as $check) {
$result = $check
->lastResult();
if ($result instanceof CheckResult) {
$no_results = FALSE;
if ($result
->result() === CheckResult::FAIL) {
$failed_checks = TRUE;
break;
}
}
}
$module_url = Url::fromRoute('security_review')
->toString();
if ($no_results) {
$severity = REQUIREMENT_WARNING;
$value = t('The Security Review checklist has not been run. <a href=":url">Run the checklist</a>', [
':url' => $module_url,
]);
}
elseif ($failed_checks) {
$severity = REQUIREMENT_WARNING;
$value = t('There are failed Security Review checks. <a href=":url">Review the checklist</a>', [
':url' => $module_url,
]);
}
else {
$severity = REQUIREMENT_OK;
$value = t('Passing all non-ignored Security Review checks. <a href=":url">Review the checklist</a>', [
':url' => $module_url,
]);
}
$requirements['security_review'] = [
'title' => t('Security Review'),
'severity' => $severity,
'value' => $value,
];
}
return $requirements;
}