public function IndexListBuilder::loadGroups in Search API 8
Loads search servers and indexes, grouped by servers.
Return value
\Drupal\Core\Config\Entity\ConfigEntityInterface[][] An associative array with two keys:
- servers: All available search servers, each followed by all search indexes attached to it.
- lone_indexes: All search indexes that aren't attached to any server.
1 call to IndexListBuilder::loadGroups()
- IndexListBuilder::render in src/
IndexListBuilder.php - Builds the entity listing as renderable array for table.html.twig.
File
- src/
IndexListBuilder.php, line 283
Class
- IndexListBuilder
- Builds a listing of search index entities.
Namespace
Drupal\search_apiCode
public function loadGroups() {
$indexes = $this->storage
->loadMultiple();
/** @var \Drupal\search_api\ServerInterface[] $servers */
$servers = $this->serverStorage
->loadMultiple();
$this
->sortByStatusThenAlphabetically($indexes);
$this
->sortByStatusThenAlphabetically($servers);
$server_groups = [];
foreach ($servers as $server) {
$server_group = [
'server.' . $server
->id() => $server,
];
foreach ($server
->getIndexes() as $index) {
$server_group['index.' . $index
->id()] = $index;
// Remove this index from $index so it will finally only contain those
// indexes not belonging to any server.
unset($indexes[$index
->id()]);
}
$server_groups['server.' . $server
->id()] = $server_group;
}
return [
'servers' => $server_groups,
'lone_indexes' => $indexes,
];
}