You are here

trait PluginDependencyTrait in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Plugin/PluginDependencyTrait.php \Drupal\Core\Plugin\PluginDependencyTrait

Provides a trait for calculating the dependencies of a plugin.

Hierarchy

3 files declare their use of PluginDependencyTrait
ConfigEntityBase.php in core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php
Contains \Drupal\Core\Config\Entity\ConfigEntityBase.
DisplayPluginBase.php in core/modules/views/src/Plugin/views/display/DisplayPluginBase.php
Contains \Drupal\views\Plugin\views\display\DisplayPluginBase.
VariantBase.php in core/lib/Drupal/Core/Display/VariantBase.php
Contains \Drupal\Core\Display\VariantBase.

File

core/lib/Drupal/Core/Plugin/PluginDependencyTrait.php, line 17
Contains \Drupal\Core\Plugin\PluginDependencyTrait.

Namespace

Drupal\Core\Plugin
View source
trait PluginDependencyTrait {
  use DependencyTrait;

  /**
   * Calculates and adds 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.
   *
   * @param \Drupal\Component\Plugin\PluginInspectionInterface $instance
   *   The plugin instance.
   */
  protected function calculatePluginDependencies(PluginInspectionInterface $instance) {
    $definition = $instance
      ->getPluginDefinition();
    $this
      ->addDependency('module', $definition['provider']);

    // Plugins can declare additional dependencies in their definition.
    if (isset($definition['config_dependencies'])) {
      $this
        ->addDependencies($definition['config_dependencies']);
    }

    // If a plugin is dependent, calculate its dependencies.
    if ($instance instanceof DependentPluginInterface && ($plugin_dependencies = $instance
      ->calculateDependencies())) {
      $this
        ->addDependencies($plugin_dependencies);
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DependencyTrait::$dependencies protected property The object's dependencies. 1
DependencyTrait::addDependencies protected function Adds multiple dependencies.
DependencyTrait::addDependency protected function Adds a dependency.
PluginDependencyTrait::calculatePluginDependencies protected function Calculates and adds dependencies of a specific plugin instance. 1