annotate core/modules/migrate/src/Plugin/MigratePluginManager.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 4c8ae668cc8c
children
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 namespace Drupal\migrate\Plugin;
Chris@0 4
Chris@0 5 use Drupal\Component\Plugin\Factory\DefaultFactory;
Chris@0 6 use Drupal\Core\Cache\CacheBackendInterface;
Chris@0 7 use Drupal\Core\Extension\ModuleHandlerInterface;
Chris@0 8 use Drupal\Core\Plugin\DefaultPluginManager;
Chris@0 9
Chris@0 10 /**
Chris@0 11 * Manages migrate plugins.
Chris@0 12 *
Chris@0 13 * @see hook_migrate_info_alter()
Chris@0 14 * @see \Drupal\migrate\Annotation\MigrateSource
Chris@0 15 * @see \Drupal\migrate\Plugin\MigrateSourceInterface
Chris@0 16 * @see \Drupal\migrate\Plugin\migrate\source\SourcePluginBase
Chris@0 17 * @see \Drupal\migrate\Annotation\MigrateProcessPlugin
Chris@0 18 * @see \Drupal\migrate\Plugin\MigrateProcessInterface
Chris@0 19 * @see \Drupal\migrate\Plugin\migrate\process\ProcessPluginBase
Chris@0 20 * @see plugin_api
Chris@0 21 *
Chris@0 22 * @ingroup migration
Chris@0 23 */
Chris@0 24 class MigratePluginManager extends DefaultPluginManager implements MigratePluginManagerInterface {
Chris@0 25
Chris@0 26 /**
Chris@0 27 * Constructs a MigratePluginManager object.
Chris@0 28 *
Chris@0 29 * @param string $type
Chris@0 30 * The type of the plugin: row, source, process, destination, entity_field,
Chris@0 31 * id_map.
Chris@0 32 * @param \Traversable $namespaces
Chris@0 33 * An object that implements \Traversable which contains the root paths
Chris@0 34 * keyed by the corresponding namespace to look for plugin implementations.
Chris@0 35 * @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend
Chris@0 36 * Cache backend instance to use.
Chris@0 37 * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
Chris@0 38 * The module handler to invoke the alter hook with.
Chris@0 39 * @param string $annotation
Chris@0 40 * (optional) The annotation class name. Defaults to
Chris@0 41 * 'Drupal\Component\Annotation\PluginID'.
Chris@0 42 */
Chris@0 43 public function __construct($type, \Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler, $annotation = 'Drupal\Component\Annotation\PluginID') {
Chris@0 44 parent::__construct("Plugin/migrate/$type", $namespaces, $module_handler, NULL, $annotation);
Chris@0 45 $this->alterInfo('migrate_' . $type . '_info');
Chris@0 46 $this->setCacheBackend($cache_backend, 'migrate_plugins_' . $type);
Chris@0 47 }
Chris@0 48
Chris@0 49 /**
Chris@0 50 * {@inheritdoc}
Chris@0 51 */
Chris@0 52 public function createInstance($plugin_id, array $configuration = [], MigrationInterface $migration = NULL) {
Chris@0 53 $plugin_definition = $this->getDefinition($plugin_id);
Chris@0 54 $plugin_class = DefaultFactory::getPluginClass($plugin_id, $plugin_definition);
Chris@0 55 // If the plugin provides a factory method, pass the container to it.
Chris@0 56 if (is_subclass_of($plugin_class, 'Drupal\Core\Plugin\ContainerFactoryPluginInterface')) {
Chris@0 57 $plugin = $plugin_class::create(\Drupal::getContainer(), $configuration, $plugin_id, $plugin_definition, $migration);
Chris@0 58 }
Chris@0 59 else {
Chris@0 60 $plugin = new $plugin_class($configuration, $plugin_id, $plugin_definition, $migration);
Chris@0 61 }
Chris@0 62 return $plugin;
Chris@0 63 }
Chris@0 64
Chris@0 65 }