You are here

public function UiPatternsSettingsManager::createInstance in UI Patterns Settings 8

Same name and namespace in other branches
  1. 8.2 src/UiPatternsSettingsManager.php \Drupal\ui_patterns_settings\UiPatternsSettingsManager::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/UiPatternsSettingsManager.php, line 32

Class

UiPatternsSettingsManager
Provides the UI Patterns Settings plugin manager.

Namespace

Drupal\ui_patterns_settings

Code

public function createInstance($plugin_id, array $configuration = []) {
  $plugin_definition = $this
    ->getDefinition($plugin_id);
  $plugin_class = DefaultFactory::getPluginClass($plugin_id, $plugin_definition);

  // If the plugin provides a factory method, pass the container to it.
  if (is_subclass_of($plugin_class, 'Drupal\\Core\\Plugin\\ContainerFactoryPluginInterface')) {
    $plugin = $plugin_class::create(\Drupal::getContainer(), $configuration, $plugin_id, $plugin_definition);
  }
  else {
    $plugin = new $plugin_class($configuration, $plugin_id, $plugin_definition);
  }
  return $plugin;
}