You are here

protected function PluginHelper::createIndexPlugins in Search API 8

Creates multiple plugin objects 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[]|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 index's stored settings, if they are present there, or default to an empty array.

Return value

\Drupal\search_api\Plugin\IndexPluginInterface[] The created plugin objects.

Throws

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

3 calls to PluginHelper::createIndexPlugins()
PluginHelper::createDatasourcePlugins in src/Utility/PluginHelper.php
Creates multiple datasource plugin objects for this index.
PluginHelper::createProcessorPlugins in src/Utility/PluginHelper.php
Creates multiple processor plugin objects for this index.
PluginHelper::createTrackerPlugins in src/Utility/PluginHelper.php
Creates multiple tracker plugin objects for this index.

File

src/Utility/PluginHelper.php, line 106

Class

PluginHelper
Provides methods for creating search plugins.

Namespace

Drupal\search_api\Utility

Code

protected function createIndexPlugins(IndexInterface $index, $type, array $plugin_ids = NULL, array $configurations = []) {
  if (!isset($this->{$type . "PluginManager"})) {
    throw new SearchApiException("Unknown plugin type '{$type}'");
  }
  if ($plugin_ids === NULL) {
    $plugin_ids = array_keys($this->{$type . "PluginManager"}
      ->getDefinitions());
  }
  $plugins = [];
  $index_settings = $index
    ->get($type . '_settings');
  foreach ($plugin_ids as $plugin_id) {
    $configuration = $configurations[$plugin_id] ?? $index_settings[$plugin_id] ?? [];
    $plugins[$plugin_id] = $this
      ->createIndexPlugin($index, $type, $plugin_id, $configuration);
  }
  return $plugins;
}