diff --git a/core/modules/migrate/src/Annotation/MigrateSource.php b/core/modules/migrate/src/Annotation/MigrateSource.php index 85f3ad9..349bcf8 100644 --- a/core/modules/migrate/src/Annotation/MigrateSource.php +++ b/core/modules/migrate/src/Annotation/MigrateSource.php @@ -24,7 +24,7 @@ * * @Annotation */ -class MigrateSource extends Plugin { +class MigrateSource extends Plugin implements MultipleProviderAnnotationInterface { /** * A unique identifier for the process plugin. @@ -67,13 +67,7 @@ class MigrateSource extends Plugin { public $minimum_version; /** - * Gets the name of the provider of the annotated class. - * - * @return string - * - * @todo This is a temporary solution to the fact that migration source - * plugins have more than one provider. This functionality will be moved to - * core in https://www.drupal.org/node/2786355. + * {@inheritdoc} */ public function getProvider() { if (isset($this->definition['provider'])) { @@ -82,4 +76,21 @@ public function getProvider() { return FALSE; } + /** + * {@inheritdoc} + */ + public function getProviders() { + if (isset($this->definition['provider'])) { + return is_array($this->definition['provider']) ? $this->definition['provider'] : [$this->definition['provider']]; + } + return []; + } + + /** + * {@inheritdoc} + */ + public function setProviders(array $providers) { + $this->definition['provider'] = $providers; + } + } diff --git a/core/modules/migrate/src/Annotation/MultipleProviderAnnotationInterface.php b/core/modules/migrate/src/Annotation/MultipleProviderAnnotationInterface.php new file mode 100644 index 0000000..11544ee --- /dev/null +++ b/core/modules/migrate/src/Annotation/MultipleProviderAnnotationInterface.php @@ -0,0 +1,41 @@ +finder = $class_loader; } @@ -58,15 +59,21 @@ public function __construct($subdir, \Traversable $root_namespaces, $plugin_defi * {@inheritdoc} */ protected function prepareAnnotationDefinition(AnnotationInterface $annotation, $class, BaseStaticReflectionParser $parser = NULL) { + if (!($annotation instanceof MultipleProviderAnnotationInterface)) { + throw new \LogicException('AnnotatedClassDiscoveryAutomatedProviders annotations must implement \Drupal\migrate\Annotation\MultipleProviderAnnotationInterface'); + } $annotation->setClass($class); - $providers = (array) $annotation->getProvider(); + $providers = $annotation->getProviders(); // Loop through all the parent classes and add their providers (which we // infer by parsing their use statements) to the $providers array. do { $new_providers = array_map([$this, 'getProviderFromNamespace'], $parser->getUseStatements()); $providers = array_merge($providers, $new_providers); } while ($parser = StaticReflectionParser::getParentParser($parser, $this->finder)); - $annotation->setProvider(array_unique(array_filter($providers))); + $providers = array_unique(array_filter($providers, function ($provider) { + return $provider && $provider !== 'component'; + })); + $annotation->setProviders(array_unique(array_filter($providers))); } /**