protected function PluginHelper::createPlugins in Search API Autocomplete 8
Creates multiple plugin objects 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[]|null $plugin_ids: (optional) The IDs of the plugins to create, or NULL to create instances for all known plugins of this type.
array $configurations: (optional) The configurations to set for the plugins, keyed by plugin ID. Missing configurations are either taken from the search's stored settings, if they are present there, or default to an empty array.
Return value
\Drupal\search_api_autocomplete\Plugin\PluginInterface[] The created plugin objects.
Throws
\Drupal\search_api_autocomplete\SearchApiAutocompleteException Thrown if an unknown $type is given.
1 call to PluginHelper::createPlugins()
- PluginHelper::createSuggesterPlugins in src/
Utility/ PluginHelper.php - Creates multiple suggester plugin objects for the given search.
File
- src/
Utility/ PluginHelper.php, line 96
Class
- PluginHelper
- Provides methods for creating autocomplete search plugins.
Namespace
Drupal\search_api_autocomplete\UtilityCode
protected function createPlugins(SearchInterface $search, $type, array $plugin_ids = NULL, array $configurations = []) {
if (!isset($this->{$type . "PluginManager"})) {
throw new SearchApiAutocompleteException("Unknown plugin type '{$type}'");
}
if ($plugin_ids === NULL) {
$plugin_ids = array_keys($this->{$type . "PluginManager"}
->getDefinitions());
}
$plugins = [];
$search_settings = $search
->get($type . '_settings');
foreach ($plugin_ids as $plugin_id) {
$configuration = [];
if (isset($configurations[$plugin_id])) {
$configuration = $configurations[$plugin_id];
}
elseif (isset($search_settings[$plugin_id])) {
$configuration = $search_settings[$plugin_id];
}
try {
$plugins[$plugin_id] = $this
->createPlugin($search, $type, $plugin_id, $configuration);
} catch (SearchApiAutocompleteException $e) {
// Ignore unknown plugins.
}
}
return $plugins;
}