TwigExtensionsPluginManager.php in Twig Extender 8
File
src/Plugin/Twig/TwigExtensionsPluginManager.php
View source
<?php
namespace Drupal\twig_extender\Plugin\Twig;
use Drupal\Core\Plugin\DefaultPluginManager;
use Drupal\Core\Plugin\Discovery\YamlDiscoveryDecorator;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Extension\ThemeHandlerInterface;
class TwigExtensionsPluginManager extends DefaultPluginManager implements TwigPluginManagerInterface {
public function __construct(\Traversable $namespaces, CacheBackendInterface $cacheBackend, ModuleHandlerInterface $moduleHandler, ThemeHandlerInterface $themeHandler) {
$pluginInterface = 'Drupal\\twig_extender\\Plugin\\Twig\\TwigExtensionInterface';
$pluginAnnotation = 'Drupal\\twig_extender\\Annotation\\TwigPlugin';
parent::__construct("Plugin/TwigPlugin", $namespaces, $moduleHandler, $pluginInterface, $pluginAnnotation);
$discovery = $this
->getDiscovery();
$this->discovery = new YamlDiscoveryDecorator($discovery, 'twigplugins', $moduleHandler
->getModuleDirectories() + $themeHandler
->getThemeDirectories());
$this->themeHandler = $themeHandler;
$this->moduleHandler = $moduleHandler;
$this
->setCacheBackend($cacheBackend, 'twig_extender');
$this->defaults += array(
'class' => 'Drupal\\twig_extender\\Plugin\\Twig\\TwigPluginBase',
);
$this
->alterInfo('twig_extender');
}
protected function providerExists($provider) {
return $this->moduleHandler
->moduleExists($provider) || $this->themeHandler
->themeExists($provider);
}
public function processDefinition(&$definition, $pluginId) {
parent::processDefinition($definition, $pluginId);
if ($this->moduleHandler
->moduleExists($definition['provider'])) {
$definition['provider_type'] = 'module';
return;
}
elseif ($this->themeHandler
->themeExists($definition['provider'])) {
$definition['provider_type'] = 'theme';
return;
}
}
}