Same filename and directory in other branches
- 8.9.x core/lib/Drupal/Core/Plugin/PluginDependencyTrait.php
- 9 core/lib/Drupal/Core/Plugin/PluginDependencyTrait.php
Namespace
Drupal\Core\Plugin
File
core/lib/Drupal/Core/Plugin/PluginDependencyTrait.php
View source
<?php
namespace Drupal\Core\Plugin;
use Drupal\Component\Plugin\Definition\PluginDefinitionInterface;
use Drupal\Component\Plugin\DependentPluginInterface;
use Drupal\Component\Plugin\PluginInspectionInterface;
use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Entity\DependencyTrait;
use Drupal\Core\Plugin\Definition\DependentPluginDefinitionInterface;
trait PluginDependencyTrait {
use DependencyTrait;
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'];
}
}
if ($provider) {
if ($provider === 'core' || $this
->moduleHandler()
->moduleExists($provider)) {
$dependencies['module'][] = $provider;
}
elseif ($this
->themeHandler()
->themeExists($provider)) {
$dependencies['theme'][] = $provider;
}
}
if ($config_dependencies) {
$dependencies = NestedArray::mergeDeep($dependencies, $config_dependencies);
}
if ($instance instanceof DependentPluginInterface && ($plugin_dependencies = $instance
->calculateDependencies())) {
$dependencies = NestedArray::mergeDeep($dependencies, $plugin_dependencies);
}
return $dependencies;
}
protected function calculatePluginDependencies(PluginInspectionInterface $instance) {
$this
->addDependencies($this
->getPluginDependencies($instance));
}
protected function moduleHandler() {
return \Drupal::moduleHandler();
}
protected function themeHandler() {
return \Drupal::service('theme_handler');
}
}
Traits