protected function ClusterForm::clusterFormInfo in Elasticsearch Connector 8.7
Same name and namespace in other branches
- 8 src/Form/ClusterForm.php \Drupal\elasticsearch_connector\Form\ClusterForm::clusterFormInfo()
- 8.2 src/Form/ClusterForm.php \Drupal\elasticsearch_connector\Form\ClusterForm::clusterFormInfo()
- 8.5 src/Form/ClusterForm.php \Drupal\elasticsearch_connector\Form\ClusterForm::clusterFormInfo()
- 8.6 src/Form/ClusterForm.php \Drupal\elasticsearch_connector\Form\ClusterForm::clusterFormInfo()
Builds the cluster info table for the edit page.
Return value
array Returns cluster info table.
1 call to ClusterForm::clusterFormInfo()
- ClusterForm::buildEntityForm in src/
Form/ ClusterForm.php - Builds entity form.
File
- src/
Form/ ClusterForm.php, line 322
Class
- ClusterForm
- Provides a form for the Cluster entity.
Namespace
Drupal\elasticsearch_connector\FormCode
protected function clusterFormInfo() {
$element = [];
if (isset($this->entity->url)) {
try {
$client_connector = $this->clientManager
->getClientForCluster($this->entity);
$cluster_info = $client_connector
->getClusterInfo();
if ($cluster_info) {
$headers = [
[
'data' => t('Cluster name'),
],
[
'data' => t('Status'),
],
[
'data' => t('Number of nodes'),
],
];
if (isset($cluster_info['state'])) {
$rows = [
[
$cluster_info['health']['cluster_name'],
$cluster_info['health']['status'],
$cluster_info['health']['number_of_nodes'],
],
];
$element = [
'#theme' => 'table',
'#header' => $headers,
'#rows' => $rows,
'#attributes' => [
'class' => [
'admin-elasticsearch',
],
'id' => 'cluster-info',
],
];
}
else {
$rows = [
[
t('Unknown'),
t('Unavailable'),
'',
],
];
$element = [
'#theme' => 'table',
'#header' => $headers,
'#rows' => $rows,
'#attributes' => [
'class' => [
'admin-elasticsearch',
],
'id' => 'cluster-info',
],
];
}
}
else {
$element['#type'] = 'markup';
$element['#markup'] = '<div id="cluster-info"> </div>';
}
} catch (\Exception $e) {
$this
->messenger()
->addError($e
->getMessage());
}
}
return $element;
}