You are here

public function Server::getBackend in Search API 8

Retrieves the backend.

Return value

\Drupal\search_api\Backend\BackendInterface This server's backend plugin.

Throws

\Drupal\search_api\SearchApiException Thrown if the backend plugin could not be retrieved.

Overrides ServerInterface::getBackend

3 calls to Server::getBackend()
Server::calculateDependencies in src/Entity/Server.php
Calculates dependencies and stores them in the dependency property.
Server::onDependencyRemoval in src/Entity/Server.php
Informs the entity that entities it depends on will be deleted.
Server::preSave in src/Entity/Server.php
Acts on an entity before the presave hook is invoked.

File

src/Entity/Server.php, line 144

Class

Server
Defines the search server configuration entity.

Namespace

Drupal\search_api\Entity

Code

public function getBackend() {
  if (!$this->backendPlugin) {
    $backend_plugin_manager = \Drupal::service('plugin.manager.search_api.backend');
    $config = $this->backend_config;
    $config['#server'] = $this;
    if (!($this->backendPlugin = $backend_plugin_manager
      ->createInstance($this
      ->getBackendId(), $config))) {
      $backend_id = $this
        ->getBackendId();
      $label = $this
        ->label();
      throw new SearchApiException("The backend with ID '{$backend_id}' could not be retrieved for server '{$label}'.");
    }
  }
  return $this->backendPlugin;
}