public function CoreRequirementsSensorPlugin::resultVerbose in Monitoring 8
Provide additional info about sensor call.
This method is only executed on request. It is guaranteed that runSensor() is executed before this method.
Parameters
\Drupal\monitoring\Result\SensorResultInterface $result: Sensor result.
Return value
array Sensor call verbose info as render array.
Overrides ExtendedInfoSensorPluginInterface::resultVerbose
File
- src/
Plugin/ monitoring/ SensorPlugin/ CoreRequirementsSensorPlugin.php, line 48 - Contains \Drupal\monitoring\Plugin\monitoring\SensorPlugin\CoreRequirementsSensorPlugin.
Class
- CoreRequirementsSensorPlugin
- Monitors a specific module hook_requirements.
Namespace
Drupal\monitoring\Plugin\monitoring\SensorPluginCode
public function resultVerbose(SensorResultInterface $result) {
$output = [];
$requirements = $this
->getRequirements($this->sensorConfig
->getSetting('module'));
$excluded_keys = $this->sensorConfig
->getSetting('exclude_keys');
if (empty($excluded_keys)) {
$excluded_keys = array();
}
$rows = [];
foreach ($requirements as $key => $value) {
// Make sure all keys are present.
$value += array(
'severity' => NULL,
);
// Map column key.
$row['key'] = $key;
// Map column excluded.
if (in_array($key, $excluded_keys)) {
$row['excluded'] = 'Yes';
}
else {
$row['excluded'] = '';
}
// Map column severity.
$severity = $value['severity'];
if ($severity == REQUIREMENT_ERROR) {
$severity = 'Error';
}
elseif ($severity == REQUIREMENT_WARNING) {
$severity = 'Warning';
}
else {
$severity = 'OK';
}
$row['severity'] = $severity;
// Map column message with title and description.
$titles = [];
if (isset($value['title'])) {
$titles[] = $value['title'];
}
if (isset($value['value'])) {
$titles[] = $value['value'];
}
$description = '';
if (isset($value['description'])) {
if (is_array($value['description'])) {
// A few requirements such as cron attach a render array.
$description = \Drupal::service('renderer')
->renderPlain($value['description']);
}
else {
$description = $value['description'];
}
}
$titles = array_map(function ($title) {
if (is_array($title)) {
$title = \Drupal::service('renderer')
->renderPlain($title);
}
return $title;
}, $titles);
$message = array(
'#type' => 'item',
'#title' => implode(' ', $titles),
'#markup' => $description,
);
$row['message'] = \Drupal::service('renderer')
->renderPlain($message);
// Map column actions.
$row['actions'] = array();
if (!in_array($key, $excluded_keys)) {
$row['actions']['data'] = array(
'#type' => 'link',
'#title' => $this
->t('Ignore'),
'#url' => Url::fromRoute('monitoring.requirements_sensor_ignore_key', array(
'monitoring_sensor_config' => $this->sensorConfig
->id(),
'key' => $key,
)),
'#access' => \Drupal::currentUser()
->hasPermission('administer monitoring'),
);
}
else {
$row['actions']['data'] = array(
'#type' => 'link',
'#title' => $this
->t('Unignore'),
'#url' => Url::fromRoute('monitoring.requirements_sensor_unignore_key', array(
'monitoring_sensor_config' => $this->sensorConfig
->id(),
'key' => $key,
)),
'#access' => \Drupal::currentUser()
->hasPermission('administer monitoring'),
);
}
$rows[] = array(
'data' => $row,
);
}
if (count($rows) > 0) {
$header = [];
$header['key'] = t('Key');
$header['excluded'] = t('Excluded');
$header['severity'] = t('Severity');
$header['message'] = t('Message');
$header['actions'] = t('Actions');
$output['requirements'] = array(
'#type' => 'verbose_table_result',
'#header' => $header,
'#rows' => $rows,
);
}
return $output;
}