You are here

public function Task::getServer in Search API 8

Retrieves the search server associated with this task, if any.

Return value

\Drupal\search_api\ServerInterface|null The search server, or NULL if there is none.

Throws

\Drupal\search_api\SearchApiException Thrown if a server was set, but it could not be loaded.

Overrides TaskInterface::getServer

File

src/Entity/Task.php, line 98

Class

Task
Defines the Search API task entity class.

Namespace

Drupal\search_api\Entity

Code

public function getServer() {
  $server_id = $this
    ->getServerId();
  if ($server_id && !isset($this->serverInstance)) {
    $this->serverInstance = $this
      ->getEntityTypeManager()
      ->getStorage('search_api_server')
      ->load($server_id);
    if (!$this->serverInstance) {
      throw new SearchApiException("Could not load server with ID '{$server_id}'.");
    }
  }
  return $this->serverInstance;
}