You are here

protected function PluginHelper::createPlugin in Search API Autocomplete 8

Creates a plugin object for the given search.

Parameters

\Drupal\search_api_autocomplete\SearchInterface $search: The search for which to create the plugins.

string $type: The type of plugin to create: "suggester" or "search".

string $plugin_id: The plugin's ID.

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

Return value

\Drupal\search_api_autocomplete\Plugin\PluginInterface The new plugin object.

Throws

\Drupal\search_api_autocomplete\SearchApiAutocompleteException Thrown if an unknown $type or $plugin_id is given.

3 calls to PluginHelper::createPlugin()
PluginHelper::createPlugins in src/Utility/PluginHelper.php
Creates multiple plugin objects for the given search.
PluginHelper::createSearchPlugin in src/Utility/PluginHelper.php
Creates a search plugin object for the given search.
PluginHelper::createSuggesterPlugin in src/Utility/PluginHelper.php
Creates a suggester plugin object for the given search.

File

src/Utility/PluginHelper.php, line 61

Class

PluginHelper
Provides methods for creating autocomplete search plugins.

Namespace

Drupal\search_api_autocomplete\Utility

Code

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