You are here

protected function PluginHelper::createIndexPlugin in Search API 8

Creates a plugin object for the given index.

Parameters

\Drupal\search_api\IndexInterface $index: The index for which to create the plugins.

string $type: The type of plugin to create: "datasource", "processor" or "tracker".

string $plugin_id: The plugin's ID.

array $configuration: (optional) The configuration to set for the plugin.

Return value

\Drupal\search_api\Plugin\IndexPluginInterface The new plugin object.

Throws

\Drupal\search_api\SearchApiException Thrown if an unknown $type or $plugin_id is given.

4 calls to PluginHelper::createIndexPlugin()
PluginHelper::createDatasourcePlugin in src/Utility/PluginHelper.php
Creates a datasource plugin object for this index.
PluginHelper::createIndexPlugins in src/Utility/PluginHelper.php
Creates multiple plugin objects for the given index.
PluginHelper::createProcessorPlugin in src/Utility/PluginHelper.php
Creates a processor plugin object for this index.
PluginHelper::createTrackerPlugin in src/Utility/PluginHelper.php
Creates a processor plugin object for this index.

File

src/Utility/PluginHelper.php, line 72

Class

PluginHelper
Provides methods for creating search plugins.

Namespace

Drupal\search_api\Utility

Code

protected function createIndexPlugin(IndexInterface $index, $type, $plugin_id, array $configuration = []) {
  if (!isset($this->{$type . "PluginManager"})) {
    throw new SearchApiException("Unknown plugin type '{$type}'");
  }
  try {
    $configuration['#index'] = $index;
    return $this->{$type . "PluginManager"}
      ->createInstance($plugin_id, $configuration);
  } catch (PluginException $e) {
    throw new SearchApiException("Unknown {$type} plugin with ID '{$plugin_id}'");
  }
}