1 {% extends "base/class.php.twig" %}
4 \Drupal\{{ module }}\{{ plugin_class }}Manager.
7 {% block namespace_class %}
8 namespace Drupal\{{ module }};
12 use Drupal\Component\Plugin\Exception\PluginException;
13 use Drupal\Core\Cache\CacheBackendInterface;
14 use Drupal\Core\Extension\ModuleHandlerInterface;
15 use Drupal\Core\Plugin\DefaultPluginManager;
16 use Drupal\Core\Plugin\Discovery\ContainerDerivativeDiscoveryDecorator;
17 use Drupal\Core\Plugin\Discovery\YamlDiscovery;
20 {% block class_declaration %}
22 * Provides the default {{ plugin_name }} manager.
24 class {{ plugin_class }}Manager extends DefaultPluginManager implements {{ plugin_class }}ManagerInterface {% endblock %}
25 {% block class_methods %}
27 * Provides default values for all {{ plugin_name }} plugins.
31 protected $defaults = array(
32 // Add required and optional plugin properties.
38 * Constructs a {{ plugin_class }}Manager object.
40 * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
42 * @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend
43 * Cache backend instance to use.
45 public function __construct(ModuleHandlerInterface $module_handler, CacheBackendInterface $cache_backend) {
46 // Add more services as required.
47 $this->moduleHandler = $module_handler;
48 $this->setCacheBackend($cache_backend, '{{ plugin_name }}', array('{{ plugin_name }}'));
54 protected function getDiscovery() {
55 if (!isset($this->discovery)) {
56 $this->discovery = new YamlDiscovery('{{ plugin_file_name }}', $this->moduleHandler->getModuleDirectories());
57 $this->discovery->addTranslatableProperty('label', 'label_context');
58 $this->discovery = new ContainerDerivativeDiscoveryDecorator($this->discovery);
60 return $this->discovery;
66 public function processDefinition(&$definition, $plugin_id) {
67 parent::processDefinition($definition, $plugin_id);
69 // You can add validation of the plugin definition here.
70 if (empty($definition['id'])) {
71 throw new PluginException(sprintf('Example plugin property (%s) definition "is" is required.', $plugin_id));
75 // Add other methods here as defined in the {{ plugin_class }}ManagerInterface.