EntityBrowserEnhancedPluginManager.php in Entity Browser Enhance(d|r) 8
File
src/EntityBrowserEnhancedPluginManager.php
View source
<?php
namespace Drupal\entity_browser_enhanced;
use Drupal\Component\Plugin\Exception\PluginException;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Plugin\DefaultPluginManager;
use Drupal\Core\Plugin\Discovery\ContainerDerivativeDiscoveryDecorator;
use Drupal\Core\Plugin\Discovery\YamlDiscovery;
class EntityBrowserEnhancedPluginManager extends DefaultPluginManager {
protected $defaults = [
'id' => '',
'label' => '',
'form_extra_class' => '',
'libraray' => '',
];
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
$this->moduleHandler = $module_handler;
$this
->setCacheBackend($cache_backend, 'entity_browser_enhanced_plugin', [
'entity_browser_enhanced_plugin',
]);
}
protected function getDiscovery() {
if (!isset($this->discovery)) {
$this->discovery = new YamlDiscovery('enhancers', $this->moduleHandler
->getModuleDirectories());
$this->discovery
->addTranslatableProperty('label', 'label_context');
$this->discovery = new ContainerDerivativeDiscoveryDecorator($this->discovery);
}
return $this->discovery;
}
public function processDefinition(&$definition, $plugin_id) {
parent::processDefinition($definition, $plugin_id);
if (empty($definition['id'])) {
throw new PluginException(sprintf('Enhancer ID property (%s) definition "is" is required.', $plugin_id));
}
if (empty($definition['label'])) {
throw new PluginException(sprintf('Enhancer Lable property (%s) definition "is" is required.', $plugin_id));
}
if (empty($definition['form_extra_class'])) {
throw new PluginException(sprintf('Enhancer form extra CSS class selector property (%s) definition "is" is required.', $plugin_id));
}
if (empty($definition['libraray'])) {
throw new PluginException(sprintf('Enhancer libraray (in a module or theme) property (%s) definition "is" is required.', $plugin_id));
}
}
public function getId() {
return $this->pluginDefinition['id'];
}
public function getLabel() {
return $this->pluginDefinition['label'];
}
public function getFormExtraClass() {
return $this->pluginDefinition['form_extra_class'];
}
public function getLibraray() {
return $this->pluginDefinition['libraray'];
}
}