You are here

public function FileMetadataPluginManager::createInstance in File metadata manager 8

Same name and namespace in other branches
  1. 8.2 src/Plugin/FileMetadataPluginManager.php \Drupal\file_mdm\Plugin\FileMetadataPluginManager::createInstance()

Creates a pre-configured instance of a plugin.

Parameters

string $plugin_id: The ID of the plugin being instantiated.

array $configuration: An array of configuration relevant to the plugin instance.

Return value

object A fully configured plugin instance.

Throws

\Drupal\Component\Plugin\Exception\PluginException If the instance cannot be created, such as if the ID is invalid.

Overrides PluginManagerBase::createInstance

File

src/Plugin/FileMetadataPluginManager.php, line 36

Class

FileMetadataPluginManager
Plugin manager for FileMetadata plugins.

Namespace

Drupal\file_mdm\Plugin

Code

public function createInstance($plugin_id, array $configuration = []) {
  $plugin_definition = $this
    ->getDefinition($plugin_id);
  $default_config = call_user_func($plugin_definition['class'] . '::defaultConfiguration');
  $configuration = $this->configFactory
    ->get($plugin_definition['provider'] . '.file_metadata_plugin.' . $plugin_id)
    ->get('configuration') ?: [];
  return parent::createInstance($plugin_id, NestedArray::mergeDeep($default_config, $configuration));
}