You are here

public function ClusterListBuilder::render in Elasticsearch Connector 8.6

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

Builds the entity listing as renderable array for table.html.twig.

@todo Add a link to add a new item to the #empty text.

Overrides EntityListBuilder::render

File

src/Controller/ClusterListBuilder.php, line 255

Class

ClusterListBuilder
Provides a listing of Clusters along with their indices.

Namespace

Drupal\elasticsearch_connector\Controller

Code

public function render() {
  $entity_groups = $this
    ->group();
  $rows = [];
  foreach ($entity_groups['clusters'] as $cluster_group) {

    /** @var \Drupal\elasticsearch_connector\Entity\Cluster|\Drupal\elasticsearch_connector\Entity\Index $entity */
    foreach ($cluster_group as $entity) {
      $rows[$entity
        ->id()] = $this
        ->buildRow($entity);
    }
  }
  $list['#type'] = 'container';
  $list['#attached']['library'][] = 'elasticsearch_connector/drupal.elasticsearch_connector.ec_index';
  $list['clusters'] = [
    '#type' => 'table',
    '#header' => $this
      ->buildHeader(),
    '#rows' => $rows,
    '#empty' => $this
      ->t('No clusters available. <a href="@link">Add new cluster</a>.', [
      '@link' => \Drupal::urlGenerator()
        ->generate('entity.elasticsearch_cluster.add_form'),
    ]),
  ];
  return $list;
}