You are here

public function ClusterListBuilder::buildRow in Elasticsearch Connector 8.2

Same name and namespace in other branches
  1. 8.7 src/Controller/ClusterListBuilder.php \Drupal\elasticsearch_connector\Controller\ClusterListBuilder::buildRow()
  2. 8 src/Controller/ClusterListBuilder.php \Drupal\elasticsearch_connector\Controller\ClusterListBuilder::buildRow()
  3. 8.5 src/Controller/ClusterListBuilder.php \Drupal\elasticsearch_connector\Controller\ClusterListBuilder::buildRow()
  4. 8.6 src/Controller/ClusterListBuilder.php \Drupal\elasticsearch_connector\Controller\ClusterListBuilder::buildRow()

Builds a row for an entity in the entity listing.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity for this row of the list.

Return value

array A render array structure of fields for this entity.

Overrides EntityListBuilder::buildRow

See also

\Drupal\Core\Entity\EntityListBuilder::render()

1 call to ClusterListBuilder::buildRow()
ClusterListBuilder::render in src/Controller/ClusterListBuilder.php
Builds the entity listing as renderable array for table.html.twig.

File

src/Controller/ClusterListBuilder.php, line 116
Contains \Drupal\elasticsearch_connector\Controller\ClusterListBuilder.

Class

ClusterListBuilder
Provides a listing of Clusters along with their indices.

Namespace

Drupal\elasticsearch_connector\Controller

Code

public function buildRow(EntityInterface $entity) {
  if ($entity instanceof Cluster) {
    $client_connector = $this->clientManager
      ->getClientForCluster($entity);
  }
  elseif ($entity instanceof Index) {
    $cluster = Cluster::load($entity->server);
    $client_connector = $this->clientManager
      ->getClientForCluster($cluster);
  }
  else {
    throw new NotFoundHttpException();
  }
  $row = parent::buildRow($entity);
  $result = array();
  $status = NULL;
  if (isset($entity->cluster_id)) {
    $cluster = Cluster::load($entity->cluster_id);
    if ($client_connector
      ->isClusterOk()) {
      $cluster_health = $client_connector
        ->cluster()
        ->health();
      $version_number = $client_connector
        ->getServerVersion();
      $status = $cluster_health['status'];
    }
    else {
      $status = $this
        ->t('Not available');
      $version_number = $this
        ->t('Unknown version');
    }
    $result = array(
      'data' => array(
        'type' => array(
          'data' => $this
            ->t('Cluster'),
        ),
        'title' => array(
          'data' => array(
            '#type' => 'link',
            '#title' => $entity
              ->label() . ' (' . $version_number . ')',
            '#url' => new Url('entity.elasticsearch_cluster.edit_form', array(
              'elasticsearch_cluster' => $entity
                ->id(),
            )),
          ),
        ),
        'machine_name' => array(
          'data' => $entity
            ->id(),
        ),
        'status' => array(
          'data' => $cluster->status ? 'Active' : 'Inactive',
        ),
        'clusterStatus' => array(
          'data' => $status,
        ),
        'operations' => $row['operations'],
      ),
      'title' => $this
        ->t('Machine name: @name', array(
        '@name' => $entity
          ->id(),
      )),
    );
  }
  elseif (isset($entity->index_id)) {
    $result = array(
      'data' => array(
        'type' => array(
          'data' => $this
            ->t('Index'),
          'class' => array(
            'es-list-index',
          ),
        ),
        'title' => array(
          'data' => $entity
            ->label(),
        ),
        'machine_name' => array(
          'data' => $entity
            ->id(),
        ),
        'status' => array(
          'data' => '',
        ),
        'clusterStatus' => array(
          'data' => '-',
        ),
        'operations' => $row['operations'],
      ),
      'title' => $this
        ->t('Machine name: @name', array(
        '@name' => $entity
          ->id(),
      )),
    );
  }
  return $result;
}