View source
<?php
namespace Drupal\monitoring\Element;
use Drupal\Core\Render\Element\FormElement;
class VerboseTableResult extends FormElement {
public function getInfo() {
$class = get_class($this);
return [
'#title' => 'Result',
'#header' => [],
'#rows' => [],
'#empty' => 'There are no results for this sensor to display.',
'#query' => '',
'#query_args' => [],
'#pre_render' => [
[
$class,
'preRenderVerboseTableResult',
],
],
'#description' => '',
];
}
public static function preRenderVerboseTableResult(array $element) {
$id = $string = str_replace(" ", "_", strtolower($element['#title']));
$element[$id] = [
'#type' => 'fieldset',
'#title' => $element['#title'],
'#attributes' => [
'id' => $id,
],
'#description' => $element['#description'],
];
$element[$id]['table'] = [
'#type' => 'table',
'#header' => $element['#header'],
'#rows' => $element['#rows'],
'#empty' => t(':empty', [
':empty' => $element['#empty'],
]),
];
if (!empty($element['#query'])) {
$element[$id]['query'] = [
'#type' => 'details',
'#open' => FALSE,
'#title' => t('Query'),
'#attributes' => [
'class' => [
'monitoring-verbose-query',
],
],
];
$element[$id]['query']['query'] = [
'#type' => 'item',
'#markup' => '<pre>' . $element['#query'] . '</pre>',
];
if (!empty($element['#query_args'])) {
$element[$id]['query']['query_args'] = [
'#type' => 'item',
'#title' => t('Arguments'),
'#markup' => '<pre>' . var_export($element['#query_args'], TRUE) . '</pre>',
];
}
}
return $element;
}
}