function ProviderFilterDecorator::filterDefinitions

Same name in other branches
  1. 8.9.x core/modules/migrate/src/Plugin/Discovery/ProviderFilterDecorator.php \Drupal\migrate\Plugin\Discovery\ProviderFilterDecorator::filterDefinitions()
  2. 10 core/modules/migrate/src/Plugin/Discovery/ProviderFilterDecorator.php \Drupal\migrate\Plugin\Discovery\ProviderFilterDecorator::filterDefinitions()
  3. 11.x core/modules/migrate/src/Plugin/Discovery/ProviderFilterDecorator.php \Drupal\migrate\Plugin\Discovery\ProviderFilterDecorator::filterDefinitions()

Removes plugin definitions with non-existing providers.

Parameters

mixed[] $definitions: An array of plugin definitions (empty array if no definitions were found). Keys are plugin IDs.

callable $provider_exists: A callable, gets passed a provider name, should return TRUE if the provider exists and FALSE if not.

Return value

array|\mixed[] An array of plugin definitions. If a definition is an array and has a provider key that provider is guaranteed to exist.

3 calls to ProviderFilterDecorator::filterDefinitions()
MigrateSourcePluginManager::findDefinitions in core/modules/migrate/src/Plugin/MigrateSourcePluginManager.php
Finds plugin definitions.
MigrationPluginManager::findDefinitions in core/modules/migrate/src/Plugin/MigrationPluginManager.php
Finds plugin definitions.
ProviderFilterDecorator::getDefinitions in core/modules/migrate/src/Plugin/Discovery/ProviderFilterDecorator.php
Gets the definition of all plugins for this type.

File

core/modules/migrate/src/Plugin/Discovery/ProviderFilterDecorator.php, line 62

Class

ProviderFilterDecorator
Remove plugin definitions with non-existing providers.

Namespace

Drupal\migrate\Plugin\Discovery

Code

public static function filterDefinitions(array $definitions, callable $provider_exists) {
    // Besides what the caller accepts, we also accept core or component.
    $provider_exists = function ($provider) use ($provider_exists) {
        return in_array($provider, [
            'core',
            'component',
        ]) || $provider_exists($provider);
    };
    return array_filter($definitions, function ($definition) use ($provider_exists) {
        // Plugin definitions can be objects (for example, Typed Data) those will
        // become empty array here and cause no problems.
        $definition = (array) $definition + [
            'provider' => [],
        ];
        // There can be one or many providers, handle them as multiple always.
        $providers = (array) $definition['provider'];
        return count($providers) == count(array_filter($providers, $provider_exists));
    });
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.