function build_varnish_status in Varnish 8
theme build function for 'varnish_status'.
1 string reference to 'build_varnish_status'
- varnish_theme in ./
varnish.module - Implements hook_theme().
File
- ./
varnish.module, line 166 - varnish.module
Code
function build_varnish_status($variables) {
$status = $variables['status'];
$items = [];
foreach ($status as $terminal => $state) {
list($server, $port) = explode(':', $terminal);
if ($state === VARNISH_SERVER_STATUS_UP) {
$icon = [
'#theme' => 'image',
'#uri' => 'core/misc/icons/73b355/check.svg',
'#alt' => t("Server OK: @server:@port", [
'@server' => $server,
'@port' => $port,
]),
'#title' => "{$server}:{$port}",
];
$icon_markup = \Drupal::service('renderer')
->render($icon);
$items[] = t('@status_icon Varnish running.', [
'@status_icon' => $icon_markup,
]);
}
else {
$icon = [
'#theme' => 'image',
'#uri' => 'core/misc/icons/e32700/error.svg',
'#alt' => t("Server down: @server:@port", [
'@server' => $server,
'@port' => $port,
]),
'#title' => "{$server}:{$port}",
];
$icon_markup = \Drupal::service('renderer')
->render($icon);
// Present a different "Server Down" message if the error is caused by an
// authentication failure.
if ($state === VARNISH_SERVER_STATUS_AUTHENTICATION_FAILURE) {
$items[] = t('@status_icon The Varnish control terminal has not authenticated at @server on port @port.', [
'@status_icon' => $icon_markup,
'@server' => $server,
'@port' => $port,
]);
}
else {
$items[] = t('@status_icon The Varnish control terminal is not responding at @server on port @port.', [
'@status_icon' => $icon_markup,
'@server' => $server,
'@port' => $port,
]);
}
}
}
$list = [
'#theme' => 'item_list',
'#items' => $items,
];
return \Drupal::service('renderer')
->render($list);
}