3 namespace Drupal\migrate\Plugin;
5 use Drupal\Core\Cache\CacheBackendInterface;
6 use Drupal\Core\Extension\ModuleHandlerInterface;
7 use Drupal\migrate\Plugin\Discovery\AnnotatedClassDiscoveryAutomatedProviders;
8 use Drupal\Core\Plugin\Discovery\ContainerDerivativeDiscoveryDecorator;
9 use Drupal\migrate\Plugin\Discovery\ProviderFilterDecorator;
12 * Plugin manager for migrate source plugins.
14 * @see \Drupal\migrate\Plugin\MigrateSourceInterface
15 * @see \Drupal\migrate\Plugin\source\SourcePluginBase
16 * @see \Drupal\migrate\Annotation\MigrateSource
21 class MigrateSourcePluginManager extends MigratePluginManager {
24 * MigrateSourcePluginManager constructor.
27 * The type of the plugin: row, source, process, destination, entity_field,
29 * @param \Traversable $namespaces
30 * An object that implements \Traversable which contains the root paths
31 * keyed by the corresponding namespace to look for plugin implementations.
32 * @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend
33 * Cache backend instance to use.
34 * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
35 * The module handler to invoke the alter hook with.
37 public function __construct($type, \Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
38 parent::__construct($type, $namespaces, $cache_backend, $module_handler, 'Drupal\migrate\Annotation\MigrateSource');
44 protected function getDiscovery() {
45 if (!$this->discovery) {
46 $discovery = new AnnotatedClassDiscoveryAutomatedProviders($this->subdir, $this->namespaces, $this->pluginDefinitionAnnotationName, $this->additionalAnnotationNamespaces);
47 $this->discovery = new ContainerDerivativeDiscoveryDecorator($discovery);
49 return $this->discovery;
53 * Finds plugin definitions.
56 * List of definitions to store in cache.
58 * @todo This is a temporary solution to the fact that migration source
59 * plugins have more than one provider. This functionality will be moved to
60 * core in https://www.drupal.org/node/2786355.
62 protected function findDefinitions() {
63 $definitions = $this->getDiscovery()->getDefinitions();
64 foreach ($definitions as $plugin_id => &$definition) {
65 $this->processDefinition($definition, $plugin_id);
67 $this->alterDefinitions($definitions);
68 return ProviderFilterDecorator::filterDefinitions($definitions, function ($provider) {
69 return $this->providerExists($provider);