diff --git a/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php b/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php index e286aef..e6b3d41 100644 --- a/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php +++ b/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php @@ -278,7 +278,7 @@ protected function findDefinitions() { $this->processDefinition($definition, $plugin_id); } $this->alterDefinitions($definitions); - return (new ProviderFilterDecorator($definitions, $this->moduleHandler->getModuleList()))->getDefinitions(); + return ProviderFilterDecorator::filterDefinitions($definitions, $this->moduleHandler); } /** diff --git a/core/lib/Drupal/Core/Plugin/Discovery/ProviderFilterDecorator.php b/core/lib/Drupal/Core/Plugin/Discovery/ProviderFilterDecorator.php index f5c98e0..0656263 100644 --- a/core/lib/Drupal/Core/Plugin/Discovery/ProviderFilterDecorator.php +++ b/core/lib/Drupal/Core/Plugin/Discovery/ProviderFilterDecorator.php @@ -4,6 +4,7 @@ use Drupal\Component\Plugin\Discovery\DiscoveryInterface; use Drupal\Component\Plugin\Discovery\DiscoveryTrait; +use Drupal\Core\Extension\ModuleHandlerInterface; /** * Remove plugin definitions with non-existing providers. @@ -20,38 +21,37 @@ class ProviderFilterDecorator implements DiscoveryInterface { protected $decorated; /** - * A list of providers. - * - * @var array + * @var \Drupal\Core\Extension\ModuleHandlerInterface */ - protected $providers; + protected $moduleHandler; /** * Constructs a InheritProviderDecorator object. * * @param \Drupal\Component\Plugin\Discovery\DiscoveryInterface $decorated * The object implementing DiscoveryInterface that is being decorated. - * @param \Drupal\Core\Extension\Extension[] $module_list - * An associative array whose keys are the names of the modules and whose - * values are Extension objects. + * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler + * The module handler. */ - public function __construct(DiscoveryInterface $decorated, $module_list) { + public function __construct(DiscoveryInterface $decorated, ModuleHandlerInterface $module_handler) { $this->decorated = $decorated; - $this->providers = $module_list + ['core' => TRUE, 'component' => TRUE]; + $this->moduleHandler = $module_handler; } /** * Remove plugin definitions with non-existing providers. * - * @param array $definitions - * An array of plugin definitions. + * @param mixed[] $definitions + * An array of plugin definitions (empty array if no definitions were + * found). Keys are plugin IDs. + * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler + * The module handler. * - * @return array - * An array of plugin definitions. If a definition is an array and it has - * a provider key that provider or providers are guaranteed to exist. + * @return $definitions + * An array of plugin definitions. If a definition is an array and has a + * provider key that provider is guaranteed to exist. */ - public function getDefinitions() { - $definitions = $this->decorated->getDefinitions(); + public static function filterDefinitions(array $definitions, ModuleHandlerInterface $module_handler) { foreach ($definitions as $plugin_id => $plugin_definition) { // If the plugin definition is an object, attempt to convert it to an // array, if that is not possible, skip further processing. @@ -59,7 +59,7 @@ public function getDefinitions() { continue; } foreach ((array) $plugin_definition['provider'] as $provider) { - if (!isset($this->providers[$provider])) { + if (!in_array($provider, ['core', 'component']) && !$module_handler->moduleExists($provider)) { unset($definitions[$plugin_id]); } } @@ -68,6 +68,13 @@ public function getDefinitions() { } /** + * {@inheritdoc} + */ + public function getDefinitions() { + return static::filterDefinitions($this->decorated->getDefinitions(), $this->moduleHandler); + } + + /** * Passes through all unknown calls onto the decorated object. */ public function __call($method, $args) { diff --git a/core/modules/migrate/src/Plugin/MigrationPluginManager.php b/core/modules/migrate/src/Plugin/MigrationPluginManager.php index ba2ea0b..a9552d4 100644 --- a/core/modules/migrate/src/Plugin/MigrationPluginManager.php +++ b/core/modules/migrate/src/Plugin/MigrationPluginManager.php @@ -71,7 +71,7 @@ protected function getDiscovery() { $yaml_discovery = new YamlDirectoryDiscovery($directories, 'migrate'); $inherited_discovery = new InheritProviderDecorator($yaml_discovery); - $filtered_discovery = new ProviderFilterDecorator($inherited_discovery, $this->moduleHandler->getModuleList()); + $filtered_discovery = new ProviderFilterDecorator($inherited_discovery, $this->moduleHandler); $this->discovery = new ContainerDerivativeDiscoveryDecorator($filtered_discovery); } return $this->discovery;