PluginDiscoveryDecorator.php in Plugin 8.2
File
src/PluginDiscovery/PluginDiscoveryDecorator.php
View source
<?php
namespace Drupal\plugin\PluginDiscovery;
use Drupal\Component\Plugin\Discovery\CachedDiscoveryInterface;
use Drupal\Component\Plugin\Discovery\DiscoveryInterface;
use Drupal\Component\Plugin\Discovery\DiscoveryTrait;
use Drupal\Core\DependencyInjection\DependencySerializationTrait;
class PluginDiscoveryDecorator implements DiscoveryInterface, CachedDiscoveryInterface {
use DependencySerializationTrait;
use DiscoveryTrait;
protected $decoratedDiscovery;
protected $pluginDefinitions;
protected $useCaches = TRUE;
public function __construct(DiscoveryInterface $decorated_discovery) {
$this->decoratedDiscovery = $decorated_discovery;
}
public function getDefinitions() {
if (is_null($this->pluginDefinitions) || !$this->useCaches) {
$this->pluginDefinitions = $this
->processDecoratedDefinitions($this->decoratedDiscovery
->getDefinitions());
}
return $this->pluginDefinitions;
}
protected function processDecoratedDefinitions(array $decorated_definitions) {
return $decorated_definitions;
}
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();
}
public function clearCachedDefinitions() {
$this->pluginDefinitions = NULL;
$decorated_discovery = $this->decoratedDiscovery;
if ($decorated_discovery instanceof CachedDiscoveryInterface) {
$decorated_discovery
->clearCachedDefinitions();
}
}
}