You are here

public function ClusterListBuilder::buildRow in Elasticsearch Connector 8.5

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.2 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 131

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 = $this->clusterStorage
      ->load($entity->server);
    $client_connector = $this->clientManager
      ->getClientForCluster($cluster);
  }
  else {
    throw new NotFoundHttpException();
  }
  $row = parent::buildRow($entity);
  $result = [];
  $status = NULL;
  if (isset($entity->cluster_id)) {
    $cluster = $this->clusterStorage
      ->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 = [
      'data' => [
        'type' => [
          'data' => $this
            ->t('Cluster'),
        ],
        'title' => [
          'data' => [
            '#type' => 'link',
            '#title' => $entity
              ->label() . ' (' . $version_number . ')',
            '#url' => new Url('entity.elasticsearch_cluster.edit_form', [
              'elasticsearch_cluster' => $entity
                ->id(),
            ]),
          ],
        ],
        'machine_name' => [
          'data' => $entity
            ->id(),
        ],
        'status' => [
          'data' => $cluster->status ? 'Active' : 'Inactive',
        ],
        'clusterStatus' => [
          'data' => $status,
        ],
        'operations' => $row['operations'],
      ],
      'title' => $this
        ->t('Machine name: @name', [
        '@name' => $entity
          ->id(),
      ]),
    ];
  }
  elseif (isset($entity->index_id)) {
    $result = [
      'data' => [
        'type' => [
          'data' => $this
            ->t('Index'),
          'class' => [
            'es-list-index',
          ],
        ],
        'title' => [
          'data' => $entity
            ->label(),
        ],
        'machine_name' => [
          'data' => $entity
            ->id(),
        ],
        'status' => [
          'data' => '',
        ],
        'clusterStatus' => [
          'data' => '-',
        ],
        'operations' => $row['operations'],
      ],
      'title' => $this
        ->t('Machine name: @name', [
        '@name' => $entity
          ->id(),
      ]),
    ];
  }
  return $result;
}