annotate core/modules/migrate/src/Plugin/MigrateSourcePluginManager.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\Core\Cache\CacheBackendInterface;
Chris@0 6 use Drupal\Core\Extension\ModuleHandlerInterface;
Chris@0 7 use Drupal\migrate\Plugin\Discovery\AnnotatedClassDiscoveryAutomatedProviders;
Chris@0 8 use Drupal\Core\Plugin\Discovery\ContainerDerivativeDiscoveryDecorator;
Chris@0 9 use Drupal\migrate\Plugin\Discovery\ProviderFilterDecorator;
Chris@0 10
Chris@0 11 /**
Chris@0 12 * Plugin manager for migrate source plugins.
Chris@0 13 *
Chris@0 14 * @see \Drupal\migrate\Plugin\MigrateSourceInterface
Chris@0 15 * @see \Drupal\migrate\Plugin\migrate\source\SourcePluginBase
Chris@0 16 * @see \Drupal\migrate\Annotation\MigrateSource
Chris@0 17 * @see plugin_api
Chris@0 18 *
Chris@0 19 * @ingroup migration
Chris@0 20 */
Chris@0 21 class MigrateSourcePluginManager extends MigratePluginManager {
Chris@0 22
Chris@0 23 /**
Chris@0 24 * MigrateSourcePluginManager constructor.
Chris@0 25 *
Chris@0 26 * @param string $type
Chris@0 27 * The type of the plugin: row, source, process, destination, entity_field,
Chris@0 28 * id_map.
Chris@0 29 * @param \Traversable $namespaces
Chris@0 30 * An object that implements \Traversable which contains the root paths
Chris@0 31 * keyed by the corresponding namespace to look for plugin implementations.
Chris@0 32 * @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend
Chris@0 33 * Cache backend instance to use.
Chris@0 34 * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
Chris@0 35 * The module handler to invoke the alter hook with.
Chris@0 36 */
Chris@0 37 public function __construct($type, \Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
Chris@0 38 parent::__construct($type, $namespaces, $cache_backend, $module_handler, 'Drupal\migrate\Annotation\MigrateSource');
Chris@0 39 }
Chris@0 40
Chris@0 41 /**
Chris@0 42 * {@inheritdoc}
Chris@0 43 */
Chris@0 44 protected function getDiscovery() {
Chris@0 45 if (!$this->discovery) {
Chris@0 46 $discovery = new AnnotatedClassDiscoveryAutomatedProviders($this->subdir, $this->namespaces, $this->pluginDefinitionAnnotationName, $this->additionalAnnotationNamespaces);
Chris@0 47 $this->discovery = new ContainerDerivativeDiscoveryDecorator($discovery);
Chris@0 48 }
Chris@0 49 return $this->discovery;
Chris@0 50 }
Chris@0 51
Chris@0 52 /**
Chris@0 53 * Finds plugin definitions.
Chris@0 54 *
Chris@0 55 * @return array
Chris@0 56 * List of definitions to store in cache.
Chris@0 57 *
Chris@0 58 * @todo This is a temporary solution to the fact that migration source
Chris@0 59 * plugins have more than one provider. This functionality will be moved to
Chris@0 60 * core in https://www.drupal.org/node/2786355.
Chris@0 61 */
Chris@0 62 protected function findDefinitions() {
Chris@0 63 $definitions = $this->getDiscovery()->getDefinitions();
Chris@0 64 foreach ($definitions as $plugin_id => &$definition) {
Chris@0 65 $this->processDefinition($definition, $plugin_id);
Chris@0 66 }
Chris@0 67 $this->alterDefinitions($definitions);
Chris@0 68 return ProviderFilterDecorator::filterDefinitions($definitions, function ($provider) {
Chris@0 69 return $this->providerExists($provider);
Chris@0 70 });
Chris@0 71 }
Chris@0 72
Chris@0 73 }