Yaffs site version 1.1
[yaffs-website] / vendor / drupal / console / templates / module / src / yaml-plugin-manager.php.twig
1 {% extends "base/class.php.twig" %}
2
3 {% block file_path %}
4 \Drupal\{{ module }}\{{ plugin_class }}Manager.
5 {% endblock %}
6
7 {% block namespace_class %}
8 namespace Drupal\{{ module }};
9 {% endblock %}
10
11 {% block use_class %}
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;
18 {% endblock %}
19
20 {% block class_declaration %}
21 /**
22  * Provides the default {{ plugin_name }} manager.
23  */
24 class {{ plugin_class }}Manager extends DefaultPluginManager implements {{ plugin_class }}ManagerInterface {% endblock %}
25 {% block class_methods %}
26   /**
27    * Provides default values for all {{ plugin_name }} plugins.
28    *
29    * @var array
30    */
31   protected $defaults = [
32     // Add required and optional plugin properties.
33     'id' => '',
34     'label' => '',
35   ];
36
37   /**
38    * Constructs a new {{ plugin_class }}Manager object.
39    *
40    * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
41    *   The module handler.
42    * @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend
43    *   Cache backend instance to use.
44    */
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 }}', ['{{ plugin_name }}']);
49   }
50
51   /**
52    * {@inheritdoc}
53    */
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);
59     }
60     return $this->discovery;
61   }
62
63   /**
64    * {@inheritdoc}
65    */
66   public function processDefinition(&$definition, $plugin_id) {
67     parent::processDefinition($definition, $plugin_id);
68
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));
72     }
73   }
74
75   // Add other methods here as defined in the {{ plugin_class }}ManagerInterface.
76 {% endblock %}