public function Server::addIndex in Search API 8
Adds a new index to this server.
If the index was already added to the server, the object should treat this as if removeIndex() and then addIndex() were called.
Parameters
\Drupal\search_api\IndexInterface $index: The index to add.
Throws
\Drupal\search_api\SearchApiException Thrown if an error occurred while adding the index.
Overrides BackendSpecificInterface::addIndex
File
- src/Entity/ Server.php, line 261 
Class
- Server
- Defines the search server configuration entity.
Namespace
Drupal\search_api\EntityCode
public function addIndex(IndexInterface $index) {
  $server_task_manager = \Drupal::getContainer()
    ->get('search_api.server_task_manager');
  // When freshly adding an index to a server, it doesn't make any sense to
  // execute possible other tasks for that server/index combination.
  // (removeIndex() is implicit when adding an index which was already added.)
  $server_task_manager
    ->delete($this, $index);
  try {
    if ($server_task_manager
      ->execute($this)) {
      $this
        ->getBackend()
        ->addIndex($index);
      return;
    }
  } catch (SearchApiException $e) {
    $vars = [
      '%server' => $this
        ->label(),
      '%index' => $index
        ->label(),
    ];
    $this
      ->logException($e, '%type while adding index %index to server %server: @message in %function (line %line of %file).', $vars);
  }
  $task_manager = \Drupal::getContainer()
    ->get('search_api.task_manager');
  $task_manager
    ->addTask(__FUNCTION__, $this, $index);
}