Mercurial > hg > cmmr2012-drupal-site
comparison core/modules/migrate/src/Plugin/MigrateSourcePluginManager.php @ 0:c75dbcec494b
Initial commit from drush-created site
author | Chris Cannam |
---|---|
date | Thu, 05 Jul 2018 14:24:15 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:c75dbcec494b |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\migrate\Plugin; | |
4 | |
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; | |
10 | |
11 /** | |
12 * Plugin manager for migrate source plugins. | |
13 * | |
14 * @see \Drupal\migrate\Plugin\MigrateSourceInterface | |
15 * @see \Drupal\migrate\Plugin\migrate\source\SourcePluginBase | |
16 * @see \Drupal\migrate\Annotation\MigrateSource | |
17 * @see plugin_api | |
18 * | |
19 * @ingroup migration | |
20 */ | |
21 class MigrateSourcePluginManager extends MigratePluginManager { | |
22 | |
23 /** | |
24 * MigrateSourcePluginManager constructor. | |
25 * | |
26 * @param string $type | |
27 * The type of the plugin: row, source, process, destination, entity_field, | |
28 * id_map. | |
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. | |
36 */ | |
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'); | |
39 } | |
40 | |
41 /** | |
42 * {@inheritdoc} | |
43 */ | |
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); | |
48 } | |
49 return $this->discovery; | |
50 } | |
51 | |
52 /** | |
53 * Finds plugin definitions. | |
54 * | |
55 * @return array | |
56 * List of definitions to store in cache. | |
57 * | |
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. | |
61 */ | |
62 protected function findDefinitions() { | |
63 $definitions = $this->getDiscovery()->getDefinitions(); | |
64 foreach ($definitions as $plugin_id => &$definition) { | |
65 $this->processDefinition($definition, $plugin_id); | |
66 } | |
67 $this->alterDefinitions($definitions); | |
68 return ProviderFilterDecorator::filterDefinitions($definitions, function ($provider) { | |
69 return $this->providerExists($provider); | |
70 }); | |
71 } | |
72 | |
73 } |