You are here

public function Task::getIndex in Search API 8

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

Return value

\Drupal\search_api\IndexInterface|null The search index, or NULL if there is none.

Throws

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

Overrides TaskInterface::getIndex

File

src/Entity/Task.php, line 123

Class

Task
Defines the Search API task entity class.

Namespace

Drupal\search_api\Entity

Code

public function getIndex() {
  $index_id = $this
    ->getIndexId();
  if ($index_id && !isset($this->indexInstance)) {
    $this->indexInstance = $this
      ->getEntityTypeManager()
      ->getStorage('search_api_index')
      ->load($index_id);
    if (!$this->indexInstance) {
      throw new SearchApiException("Could not load index with ID '{$index_id}'.");
    }
  }
  return $this->indexInstance;
}