You are here

public function CommandHelper::serverListCommand in Search API 8

Returns a list of servers created on the page.

Return value

array An associative array, keyed by search server ID, each value an associative array with the following keys:

  • id: The ID of the search server.
  • name: The human readable name of the search server.
  • status: The enabled status of the server.

Throws

\Drupal\search_api\ConsoleException Thrown if no servers could be loaded.

File

src/Utility/CommandHelper.php, line 522

Class

CommandHelper
Provides functionality to be used by CLI tools.

Namespace

Drupal\search_api\Utility

Code

public function serverListCommand() {
  $servers = $this
    ->loadServers();
  if (count($servers) === 0) {
    throw new ConsoleException($this
      ->t('There are no servers present.'));
  }
  $rows = [];
  foreach ($servers as $server) {
    $rows[$server
      ->id()] = [
      'id' => $server
        ->id(),
      'name' => $server
        ->label(),
      'status' => $server
        ->status() ? $this
        ->t('enabled') : $this
        ->t('disabled'),
    ];
  }
  return $rows;
}