3 namespace Drupal\migrate\Plugin;
5 use Drupal\Component\Plugin\Factory\DefaultFactory;
6 use Drupal\Core\Cache\CacheBackendInterface;
7 use Drupal\Core\Extension\ModuleHandlerInterface;
8 use Drupal\Core\Plugin\DefaultPluginManager;
11 * Manages migrate plugins.
13 * @see hook_migrate_info_alter()
14 * @see \Drupal\migrate\Annotation\MigrateSource
15 * @see \Drupal\migrate\Plugin\MigrateSourceInterface
16 * @see \Drupal\migrate\Plugin\migrate\source\SourcePluginBase
17 * @see \Drupal\migrate\Annotation\MigrateProcessPlugin
18 * @see \Drupal\migrate\Plugin\MigrateProcessInterface
19 * @see \Drupal\migrate\Plugin\migrate\process\ProcessPluginBase
24 class MigratePluginManager extends DefaultPluginManager implements MigratePluginManagerInterface {
27 * Constructs a MigratePluginManager object.
30 * The type of the plugin: row, source, process, destination, entity_field,
32 * @param \Traversable $namespaces
33 * An object that implements \Traversable which contains the root paths
34 * keyed by the corresponding namespace to look for plugin implementations.
35 * @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend
36 * Cache backend instance to use.
37 * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
38 * The module handler to invoke the alter hook with.
39 * @param string $annotation
40 * (optional) The annotation class name. Defaults to
41 * 'Drupal\Component\Annotation\PluginID'.
43 public function __construct($type, \Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler, $annotation = 'Drupal\Component\Annotation\PluginID') {
44 parent::__construct("Plugin/migrate/$type", $namespaces, $module_handler, NULL, $annotation);
45 $this->alterInfo('migrate_' . $type . '_info');
46 $this->setCacheBackend($cache_backend, 'migrate_plugins_' . $type);
52 public function createInstance($plugin_id, array $configuration = [], MigrationInterface $migration = NULL) {
53 $plugin_definition = $this->getDefinition($plugin_id);
54 $plugin_class = DefaultFactory::getPluginClass($plugin_id, $plugin_definition);
55 // If the plugin provides a factory method, pass the container to it.
56 if (is_subclass_of($plugin_class, 'Drupal\Core\Plugin\ContainerFactoryPluginInterface')) {
57 $plugin = $plugin_class::create(\Drupal::getContainer(), $configuration, $plugin_id, $plugin_definition, $migration);
60 $plugin = new $plugin_class($configuration, $plugin_id, $plugin_definition, $migration);