You are here

public function ClusterListBuilder::load in Elasticsearch Connector 8

Loads entities of this type from storage for listing.

This allows the implementation to manipulate the listing, like filtering or sorting the loaded entities.

Return value

\Drupal\Core\Entity\EntityInterface[] An array of entities implementing \Drupal\Core\Entity\EntityInterface indexed by their IDs. Returns an empty array if no matching entities are found.

Overrides ConfigEntityListBuilder::load

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

File

src/Controller/ClusterListBuilder.php, line 50
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 load() {
  $clusters = $this->storage
    ->loadMultiple();
  $indices = $this->indexStorage
    ->loadMultiple();
  $cluster_groups = array();
  $lone_indices = array();
  foreach ($clusters as $cluster) {
    $cluster_group = array(
      'cluster.' . $cluster->cluster_id => $cluster,
    );
    foreach ($indices as $index) {
      if ($index->server == $cluster->cluster_id) {
        $cluster_group['index.' . $index->index_id] = $index;
      }
      elseif ($index->server == NULL) {
        $lone_indices['index.' . $index->index_id] = $index;
      }
    }
    $cluster_groups['cluster.' . $cluster->cluster_id] = $cluster_group;
  }
  $cluster_groups['cluster.lone'] = $lone_indices;
  return $cluster_groups;
}