function config_inspector_requirements in Configuration Inspector 8
Implements hook_requirements().
File
- ./
config_inspector.install, line 14 - Install, update and uninstall hooks for this module.
Code
function config_inspector_requirements($phase) {
if ($phase !== 'runtime') {
return [];
}
$requirements = [];
$errors = [];
foreach (\Drupal::service('config.storage')
->listAll() as $name) {
$result = \Drupal::service('plugin.manager.config_inspector')
->checkValues($name);
if (is_array($result)) {
$text = \Drupal::translation()
->formatPlural(count($result), '@configuration_key: @count error', '@configuration_key: @count errors', [
'@configuration_key' => $name,
]);
$url = Url::fromRoute('config_inspector.list_page', [
'name' => $name,
]);
$errors[] = Link::fromTextAndUrl($text, $url)
->toString();
}
}
if (!empty($errors)) {
$requirements['config_inspector_report'] = [
'title' => t('Configuration inspector'),
'value' => t("The site's configuration does not match the associated schema."),
'description' => [
'#theme' => 'item_list',
'#items' => $errors,
],
'severity' => REQUIREMENT_ERROR,
];
}
else {
$requirements['config_inspector_report'] = [
'title' => t('Configuration inspector'),
'value' => t("The site's configuration matches the associated schema."),
'severity' => REQUIREMENT_OK,
];
}
return $requirements;
}