You are here

public function SearchApiElasticsearchBackend::viewSettings in Elasticsearch Connector 8.5

Same name and namespace in other branches
  1. 8.7 src/Plugin/search_api/backend/SearchApiElasticsearchBackend.php \Drupal\elasticsearch_connector\Plugin\search_api\backend\SearchApiElasticsearchBackend::viewSettings()
  2. 8 src/Plugin/search_api/backend/SearchApiElasticsearchBackend.php \Drupal\elasticsearch_connector\Plugin\search_api\backend\SearchApiElasticsearchBackend::viewSettings()
  3. 8.2 src/Plugin/search_api/backend/SearchApiElasticsearchBackend.php \Drupal\elasticsearch_connector\Plugin\search_api\backend\SearchApiElasticsearchBackend::viewSettings()
  4. 8.6 src/Plugin/search_api/backend/SearchApiElasticsearchBackend.php \Drupal\elasticsearch_connector\Plugin\search_api\backend\SearchApiElasticsearchBackend::viewSettings()

Returns additional, backend-specific information about this server.

This information will be then added to the server's "View" tab in some way. In the default theme implementation the data is output in a table with two columns along with other, generic information about the server.

Return value

array An array of additional server information, with each piece of information being an associative array with the following keys:

  • label: The human-readable label for this data.
  • info: The information, as HTML.
  • status: (optional) The status associated with this information. One of "info", "ok", "warning" or "error". Defaults to "info".

Overrides BackendPluginBase::viewSettings

File

src/Plugin/search_api/backend/SearchApiElasticsearchBackend.php, line 332

Class

SearchApiElasticsearchBackend
Elasticsearch Search API Backend definition.

Namespace

Drupal\elasticsearch_connector\Plugin\search_api\backend

Code

public function viewSettings() {
  $info = [];
  $server_link = $this->cluster
    ->getSafeUrl();
  $info[] = [
    'label' => $this
      ->t('Elasticsearch server URI'),
    'info' => Link::fromTextAndUrl($server_link, Url::fromUri($server_link)),
  ];
  if ($this->server
    ->status()) {

    // If the server is enabled, check whether Elasticsearch can be reached.
    $ping = $this->client
      ->isClusterOk();
    if ($ping) {
      $msg = $this
        ->t('The Elasticsearch server could be reached');
    }
    else {
      $msg = $this
        ->t('The Elasticsearch server could not be reached. Further data is therefore unavailable.');
    }
    $info[] = [
      'label' => $this
        ->t('Connection'),
      'info' => $msg,
      'status' => $ping ? 'ok' : 'error',
    ];
  }
  return $info;
}