You are here

public function MgvPluginManager::createInstance in More Global Variables 8

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

1 call to MgvPluginManager::createInstance()
MgvPluginManager::getVariables in src/MgvPluginManager.php
Returns all the variables.

File

src/MgvPluginManager.php, line 92

Class

MgvPluginManager
Class MgvPluginManager.

Namespace

Drupal\mgv

Code

public function createInstance($plugin_id, array $configuration = []) {
  if (!empty($configuration['variableDependencies'])) {
    foreach ($configuration['variableDependencies'] as $key => $plugin) {
      $definition = $this
        ->getDefinition($plugin);

      /* @var \Drupal\mgv\Plugin\GlobalVariableInterface $instance */
      $instance = $this
        ->createInstance($definition['id'], $definition);
      $configuration['variableDependencies'][$plugin] = $instance
        ->getValue();
      unset($configuration['variableDependencies'][$key]);
    }
  }
  return parent::createInstance($plugin_id, $configuration);
}