You are here

public function MigratePluginManager::createInstance in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/migrate/src/Plugin/MigratePluginManager.php \Drupal\migrate\Plugin\MigratePluginManager::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

1 call to MigratePluginManager::createInstance()
MigrateDestinationPluginManager::createInstance in core/modules/migrate/src/Plugin/MigrateDestinationPluginManager.php
A specific createInstance method is necessary to pass the migration on.
1 method overrides MigratePluginManager::createInstance()
MigrateDestinationPluginManager::createInstance in core/modules/migrate/src/Plugin/MigrateDestinationPluginManager.php
A specific createInstance method is necessary to pass the migration on.

File

core/modules/migrate/src/Plugin/MigratePluginManager.php, line 52

Class

MigratePluginManager
Manages migrate plugins.

Namespace

Drupal\migrate\Plugin

Code

public function createInstance($plugin_id, array $configuration = [], MigrationInterface $migration = NULL) {
  $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, $migration);
  }
  else {
    $plugin = new $plugin_class($configuration, $plugin_id, $plugin_definition, $migration);
  }
  return $plugin;
}