You are here

class PluginDiscoveryDecorator in Plugin 8.2

Decorates plugin discovery.

Hierarchy

Expanded class hierarchy of PluginDiscoveryDecorator

2 files declare their use of PluginDiscoveryDecorator
PluginDiscoveryDecoratorTest.php in tests/src/Unit/PluginDiscovery/PluginDiscoveryDecoratorTest.php
PluginManagerDecorator.php in src/PluginManager/PluginManagerDecorator.php

File

src/PluginDiscovery/PluginDiscoveryDecorator.php, line 13

Namespace

Drupal\plugin\PluginDiscovery
View source
class PluginDiscoveryDecorator implements DiscoveryInterface, CachedDiscoveryInterface {
  use DependencySerializationTrait;
  use DiscoveryTrait;

  /**
   * The decorated discovery.
   *
   * @var \Drupal\Component\Plugin\Discovery\DiscoveryInterface
   */
  protected $decoratedDiscovery;

  /**
   * The processed plugin definitions.
   *
   * @var array[]|null
   *   An array with plugin definitions or NULL if the definitions have not been
   *   loaded yet.
   *
   * @see self::getDefinitions()
   */
  protected $pluginDefinitions;

  /**
   * Whether or not to use plugin caching.
   *
   * @var bool
   */
  protected $useCaches = TRUE;

  /**
   * Constructs a new instance.
   *
   * @param \Drupal\Component\Plugin\Discovery\DiscoveryInterface $decorated_discovery
   *   The decorated discovery.
   */
  public function __construct(DiscoveryInterface $decorated_discovery) {
    $this->decoratedDiscovery = $decorated_discovery;
  }

  /**
   * {@inheritdoc}
   */
  public function getDefinitions() {
    if (is_null($this->pluginDefinitions) || !$this->useCaches) {
      $this->pluginDefinitions = $this
        ->processDecoratedDefinitions($this->decoratedDiscovery
        ->getDefinitions());
    }
    return $this->pluginDefinitions;
  }

  /**
   * Processes the definitions from the decorated discovery.
   *
   * Any changes to the decorated definitions should be performed here.
   *
   * @param mixed[] $decorated_definitions
   *   The decorated plugin definitions, keyed by plugin ID.
   *
   * @return mixed[]
   *   The processed plugin definitions.
   */
  protected function processDecoratedDefinitions(array $decorated_definitions) {
    return $decorated_definitions;
  }

  /**
   * {@inheritdoc}
   */
  public function useCaches($use_caches = FALSE) {
    $this->useCaches = $use_caches;
    $decorated_discovery = $this->decoratedDiscovery;
    if ($decorated_discovery instanceof CachedDiscoveryInterface) {
      $decorated_discovery
        ->useCaches($use_caches);
    }
    $this
      ->clearCachedDefinitions();
  }

  /**
   * {@inheritdoc}
   */
  public function clearCachedDefinitions() {
    $this->pluginDefinitions = NULL;
    $decorated_discovery = $this->decoratedDiscovery;
    if ($decorated_discovery instanceof CachedDiscoveryInterface) {
      $decorated_discovery
        ->clearCachedDefinitions();
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
DiscoveryTrait::doGetDefinition protected function Gets a specific plugin definition.
DiscoveryTrait::getDefinition public function 3
DiscoveryTrait::hasDefinition public function
PluginDiscoveryDecorator::$decoratedDiscovery protected property The decorated discovery.
PluginDiscoveryDecorator::$pluginDefinitions protected property The processed plugin definitions.
PluginDiscoveryDecorator::$useCaches protected property Whether or not to use plugin caching.
PluginDiscoveryDecorator::clearCachedDefinitions public function Clears static and persistent plugin definition caches. Overrides CachedDiscoveryInterface::clearCachedDefinitions
PluginDiscoveryDecorator::getDefinitions public function Gets the definition of all plugins for this type. Overrides DiscoveryTrait::getDefinitions
PluginDiscoveryDecorator::processDecoratedDefinitions protected function Processes the definitions from the decorated discovery. 2
PluginDiscoveryDecorator::useCaches public function Disable the use of caches. Overrides CachedDiscoveryInterface::useCaches
PluginDiscoveryDecorator::__construct public function Constructs a new instance. 2