3 namespace Drupal\{{ machine_name }};
5 use Drupal\Core\Cache\CacheBackendInterface;
6 use Drupal\Core\Extension\ModuleHandlerInterface;
7 use Drupal\Core\Plugin\DefaultPluginManager;
8 use Drupal\Core\Plugin\Discovery\YamlDiscovery;
9 use Drupal\Core\Plugin\Factory\ContainerFactory;
12 * Defines a plugin manager to deal with {{ plugin_type|plural }}.
14 * Modules can define {{ plugin_type|plural }} in a MODULE_NAME.{{ plugin_type|plural }}.yml file contained
15 * in the module's base directory. Each {{ plugin_type }} has the following structure:
23 * @see \Drupal\{{ machine_name }}\{{ class_prefix }}Default
24 * @see \Drupal\{{ machine_name }}\{{ class_prefix }}Interface
27 class {{ class_prefix }}PluginManager extends DefaultPluginManager {
32 protected $defaults = [
33 // The {{ plugin_type }} id. Set by the plugin system based on the top-level YAML key.
35 // The {{ plugin_type }} label.
37 // The {{ plugin_type }} description.
39 // Default plugin class.
40 'class' => 'Drupal\{{ machine_name }}\{{ class_prefix }}Default',
44 * Constructs {{ class_prefix }}PluginManager object.
46 * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
47 * The module handler to invoke the alter hook with.
48 * @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend
49 * Cache backend instance to use.
51 public function __construct(ModuleHandlerInterface $module_handler, CacheBackendInterface $cache_backend) {
52 $this->factory = new ContainerFactory($this);
53 $this->moduleHandler = $module_handler;
54 $this->alterInfo('{{ plugin_type }}_info');
55 $this->setCacheBackend($cache_backend, '{{ plugin_type }}_plugins');
61 protected function getDiscovery() {
62 if (!isset($this->discovery)) {
63 $this->discovery = new YamlDiscovery('{{ plugin_type|plural }}', $this->moduleHandler->getModuleDirectories());
64 $this->discovery->addTranslatableProperty('label', 'label_context');
65 $this->discovery->addTranslatableProperty('description', 'description_context');
67 return $this->discovery;