You are here

protected function ClusterForm::clusterFormInfo in Elasticsearch Connector 8

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

Build the cluster info table for the edit page.

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

File

src/Form/ClusterForm.php, line 213
Contains Drupal\elasticsearch_connector\Form.

Class

ClusterForm
Provides a form for the Cluster entity.

Namespace

Drupal\elasticsearch_connector\Form

Code

protected function clusterFormInfo(Cluster $cluster = NULL) {
  $element = array();
  if (isset($cluster->url)) {
    try {
      $cluster_info = $cluster
        ->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) {
      drupal_set_message($e
        ->getMessage(), 'error');
    }
  }
  return $element;
}