function PluginDependencyTrait::getPluginDependencies

Same name in other branches
  1. 9 core/lib/Drupal/Core/Plugin/PluginDependencyTrait.php \Drupal\Core\Plugin\PluginDependencyTrait::getPluginDependencies()
  2. 10 core/lib/Drupal/Core/Plugin/PluginDependencyTrait.php \Drupal\Core\Plugin\PluginDependencyTrait::getPluginDependencies()
  3. 11.x core/lib/Drupal/Core/Plugin/PluginDependencyTrait.php \Drupal\Core\Plugin\PluginDependencyTrait::getPluginDependencies()

Calculates and returns dependencies of a specific plugin instance.

Dependencies are added for the module that provides the plugin, as well as any dependencies declared by the instance's calculateDependencies() method, if it implements \Drupal\Component\Plugin\DependentPluginInterface.

Parameters

\Drupal\Component\Plugin\PluginInspectionInterface $instance: The plugin instance.

Return value

array An array of dependencies keyed by the type of dependency.

2 calls to PluginDependencyTrait::getPluginDependencies()
LayoutBuilderEntityViewDisplay::onDependencyRemoval in core/modules/layout_builder/src/Entity/LayoutBuilderEntityViewDisplay.php
Informs the entity that entities it depends on will be deleted.
PluginDependencyTrait::calculatePluginDependencies in core/lib/Drupal/Core/Plugin/PluginDependencyTrait.php
Calculates and adds dependencies of a specific plugin instance.

File

core/lib/Drupal/Core/Plugin/PluginDependencyTrait.php, line 33

Class

PluginDependencyTrait
Provides a trait for calculating the dependencies of a plugin.

Namespace

Drupal\Core\Plugin

Code

protected function getPluginDependencies(PluginInspectionInterface $instance) {
    $dependencies = [];
    $definition = $instance->getPluginDefinition();
    $provider = NULL;
    $config_dependencies = [];
    if ($definition instanceof PluginDefinitionInterface) {
        $provider = $definition->getProvider();
        if ($definition instanceof DependentPluginDefinitionInterface) {
            $config_dependencies = $definition->getConfigDependencies();
        }
    }
    elseif (is_array($definition)) {
        $provider = $definition['provider'];
        if (isset($definition['config_dependencies'])) {
            $config_dependencies = $definition['config_dependencies'];
        }
    }
    // Add the provider as a dependency, taking into account if it's a module or
    // a theme.
    if ($provider) {
        if ($provider === 'core' || $this->moduleHandler()
            ->moduleExists($provider)) {
            $dependencies['module'][] = $provider;
        }
        elseif ($this->themeHandler()
            ->themeExists($provider)) {
            $dependencies['theme'][] = $provider;
        }
        else {
            @trigger_error('Declaring a dependency on an uninstalled module is deprecated in Drupal 8.7.0 and will not be supported in Drupal 9.0.0.', E_USER_DEPRECATED);
            $dependencies['module'][] = $provider;
        }
    }
    // Add the config dependencies.
    if ($config_dependencies) {
        $dependencies = NestedArray::mergeDeep($dependencies, $config_dependencies);
    }
    // If a plugin is dependent, calculate its dependencies.
    if ($instance instanceof DependentPluginInterface && ($plugin_dependencies = $instance->calculateDependencies())) {
        $dependencies = NestedArray::mergeDeep($dependencies, $plugin_dependencies);
    }
    return $dependencies;
}

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