You are here

protected function ClusterForm::clusterFormInfo in Elasticsearch Connector 8.6

Same name and namespace in other branches
  1. 8.7 src/Form/ClusterForm.php \Drupal\elasticsearch_connector\Form\ClusterForm::clusterFormInfo()
  2. 8 src/Form/ClusterForm.php \Drupal\elasticsearch_connector\Form\ClusterForm::clusterFormInfo()
  3. 8.2 src/Form/ClusterForm.php \Drupal\elasticsearch_connector\Form\ClusterForm::clusterFormInfo()
  4. 8.5 src/Form/ClusterForm.php \Drupal\elasticsearch_connector\Form\ClusterForm::clusterFormInfo()

Build the cluster info table for the edit page.

Return value

array

1 call to ClusterForm::clusterFormInfo()
ClusterForm::buildEntityForm in src/Form/ClusterForm.php

File

src/Form/ClusterForm.php, line 314

Class

ClusterForm
Provides a form for the Cluster entity.

Namespace

Drupal\elasticsearch_connector\Form

Code

protected function clusterFormInfo() {
  $element = array();
  if (isset($this->entity->url)) {
    try {
      $client_connector = $this->clientManager
        ->getClientForCluster($this->entity);
      $cluster_info = $client_connector
        ->getClusterInfo();
      if ($cluster_info) {
        $headers = array(
          array(
            'data' => t('Cluster name'),
          ),
          array(
            'data' => t('Status'),
          ),
          array(
            'data' => t('Number of nodes'),
          ),
        );
        if (isset($cluster_info['state'])) {
          $rows = array(
            array(
              $cluster_info['health']['cluster_name'],
              $cluster_info['health']['status'],
              $cluster_info['health']['number_of_nodes'],
            ),
          );
          $element = array(
            '#theme' => 'table',
            '#header' => $headers,
            '#rows' => $rows,
            '#attributes' => array(
              'class' => array(
                'admin-elasticsearch',
              ),
              'id' => 'cluster-info',
            ),
          );
        }
        else {
          $rows = array(
            array(
              t('Unknown'),
              t('Unavailable'),
              '',
            ),
          );
          $element = array(
            '#theme' => 'table',
            '#header' => $headers,
            '#rows' => $rows,
            '#attributes' => array(
              'class' => array(
                'admin-elasticsearch',
              ),
              'id' => 'cluster-info',
            ),
          );
        }
      }
      else {
        $element['#type'] = 'markup';
        $element['#markup'] = '<div id="cluster-info">&nbsp;</div>';
      }
    } catch (\Exception $e) {
      $this
        ->messenger()
        ->addError($e
        ->getMessage());
    }
  }
  return $element;
}