diff --git a/src/DataType/DataTypePluginManager.php b/src/DataType/DataTypePluginManager.php index 5f0a595..b416556 100644 --- a/src/DataType/DataTypePluginManager.php +++ b/src/DataType/DataTypePluginManager.php @@ -21,11 +21,21 @@ class DataTypePluginManager extends DefaultPluginManager { * * @var \Drupal\search_api\DataType\DataTypeInterface[] * + * @see \Drupal\search_api\DataType\DataTypePluginManager::createInstance() * @see \Drupal\search_api\DataType\DataTypePluginManager::getInstances() */ protected $dataTypes; /** + * Whether all plugin instances have already been created. + * + * @var bool + * + * @see \Drupal\search_api\DataType\DataTypePluginManager::getInstances() + */ + protected $allCreated = FALSE; + + /** * Constructs a DataTypePluginManager object. * * @param \Traversable $namespaces @@ -72,13 +82,15 @@ public function createInstance($plugin_id, array $configuration = array()) { * An array of data type plugins, keyed by type identifier. */ public function getInstances() { - if (!isset($this->dataTypes)) { - $this->dataTypes = array(); + if (!$this->allCreated) { + if (!isset($this->dataTypes)) { + $this->dataTypes = array(); + } - foreach ($this->getDefinitions() as $name => $data_type_definition) { - if (class_exists($data_type_definition['class']) && empty($this->dataTypes[$name])) { - $data_type = $this->createInstance($name); - $this->dataTypes[$name] = $data_type; + foreach ($this->getDefinitions() as $plugin_id => $definition) { + if (class_exists($definition['class']) && empty($this->dataTypes[$plugin_id])) { + $data_type = $this->createInstance($plugin_id); + $this->dataTypes[$plugin_id] = $data_type; } } } diff --git a/src/Utility.php b/src/Utility.php index 5267907..701feda 100644 --- a/src/Utility.php +++ b/src/Utility.php @@ -164,8 +164,10 @@ public static function getDataTypeFallbackMapping(IndexInterface $index) { // custom types. } static::$dataTypeFallbackMapping[$index_id] = array(); - /** @var \Drupal\search_api\DataType\DataTypeInterface $data_type */ - foreach (\Drupal::service('plugin.manager.search_api.data_type')->getInstances() as $type_id => $data_type) { + $data_types = \Drupal::getContainer() + ->get('plugin.manager.search_api.data_type') + ->getInstances(); + foreach ($data_types as $type_id => $data_type) { // We know for sure that we do not need to fall back for the default // data types as they are always present and are required to be // supported by all backends.