JsCallbackManager.php in JS Callback Handler 8.3
File
src/JsCallbackManager.php
View source
<?php
namespace Drupal\js;
use Drupal\Component\Plugin\FallbackPluginManagerInterface;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Extension\ThemeHandlerInterface;
use Drupal\Core\Plugin\DefaultPluginManager;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\Theme\ThemeManagerInterface;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
use Symfony\Component\DependencyInjection\ContainerInterface;
class JsCallbackManager extends DefaultPluginManager implements ContainerInjectionInterface, ContainerAwareInterface, FallbackPluginManagerInterface {
use ContainerAwareTrait;
use StringTranslationTrait;
protected $themeHandler;
protected $themeManager;
public function __construct(\ArrayObject $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler, ThemeHandlerInterface $theme_handler, ThemeManagerInterface $theme_manager) {
$this
->fixNamespaces($namespaces);
$this->themeHandler = $theme_handler;
$this->themeManager = $theme_manager;
parent::__construct('Plugin/Js', $namespaces, $module_handler, '\\Drupal\\js\\Plugin\\Js\\JsCallbackInterface', '\\Drupal\\js\\Annotation\\JsCallback');
$this
->alterInfo('js_callbacks');
$this
->setCacheBackend($cache_backend, 'js_callbacks');
}
public function fixNamespaces($namespaces) {
$class_loader = \Drupal::service('class_loader');
$ns = $namespaces
->getArrayCopy();
foreach ($class_loader
->getPrefixesPsr4() as $prefix => $paths) {
$prefix = trim($prefix, '\\');
$path = str_replace(\Drupal::root() . '/', '', reset($paths));
if (preg_match('/^(core|vendor)/', $path) === 0 && !isset($namespaces[$prefix])) {
$ns[$prefix] = $path;
}
}
$namespaces
->exchangeArray($ns);
}
public static function create(ContainerInterface $container) {
return new static($container
->get('container.namespaces'), $container
->get('cache.discovery'), $container
->get('module_handler'), $container
->get('theme_handler'), $container
->get('theme.manager'));
}
protected function alterDefinitions(&$definitions) {
if ($this->alterHook) {
$this->moduleHandler
->alter($this->alterHook, $definitions);
$this->themeManager
->alter($this->alterHook, $definitions);
}
}
public function getFallbackPluginId($plugin_id, array $configuration = []) {
return 'js.content';
}
protected function providerExists($provider) {
return $this->moduleHandler
->moduleExists($provider) || $this->themeHandler
->themeExists($provider);
}
}