You are here

protected static function Server::getBackend in Search API Autocomplete 8

Retrieves the backend for the given index, if it supports autocomplete.

Parameters

\Drupal\search_api\IndexInterface $index: The search index.

Return value

\Drupal\search_api_autocomplete\AutocompleteBackendInterface|null The backend plugin of the index's server, if it exists and supports autocomplete; NULL otherwise.

2 calls to Server::getBackend()
Server::getAutocompleteSuggestions in src/Plugin/search_api_autocomplete/suggester/Server.php
Retrieves autocompletion suggestions for some user input.
Server::supportsSearch in src/Plugin/search_api_autocomplete/suggester/Server.php
Determines whether this plugin supports the given search.

File

src/Plugin/search_api_autocomplete/suggester/Server.php, line 191

Class

Server
Provides a suggester plugin that retrieves suggestions from the server.

Namespace

Drupal\search_api_autocomplete\Plugin\search_api_autocomplete\suggester

Code

protected static function getBackend(IndexInterface $index) {
  if (!$index
    ->hasValidServer()) {
    return NULL;
  }
  try {
    $server = $index
      ->getServerInstance();
    $backend = $server
      ->getBackend();
  } catch (SearchApiException $e) {
    return NULL;
  }
  if ($server
    ->supportsFeature('search_api_autocomplete') || $backend instanceof AutocompleteBackendInterface) {
    return $backend;
  }
  return NULL;
}