
Your custom plugin definition class must also have annotation metadata, that is defined by the module that implement the plugin type, in our example : \Drupal\views\Annotation\ViewsArea In most cases, the modules that implement a Plugin type will provide a base class for the plugins definitions, in our example views area provide a base class : \Drupal\views\Plugin\views\area\AreaPluginBaseĭrupal provide also a base class, if you implement a custom Plugin type, for the Plugin definition : \Drupal\Component\Plugin\PluginBase
DRUPAL WIKI PLUGIN CODE
To know where to implement a plugin definition for a plugin type, you can in most case look at module docs, or directly in the source code of the module (looking at an example of a definition will be enough) So if I implement a custom views area Plugin in my module the class will be located under the location module_name/src/Plugin/views/area/MyAreaHandler.php You have to understand simply that a Plugin in most case is a Class implementation, namespaced within the namespace of the plugin type, in our example this is : \Drupal\module_name\Plugin\views\area The existing documentation on the plugin definitions are a little abstract for now to understand how it really works ( ).
DRUPAL WIKI PLUGIN HOW TO
In our case Views is responsible of that implementations so we are not going further on that, let see now how to implement a plugin definition. The Factory is responsible for instantiating the specific plugin(s) chosen for a given use case. Plugin Discovery is the process of finding plugins within the available code base that qualify for use within this particular plugin type's use case. cache backends, image actions, blocks, etc.

The type will describe the central purpose of all plugins of that type e.g. The plugin type is the central controlling class that defines how the plugins of this type will be discovered and instantiated. The plugin system has three base elements : Plugin Types For those that already been using Ctools plugins system, you already now about the plugin system purposes.įor those who doesn't know about it, the plugin system is a way to let other module implements her own use case for an existing features, think of Field formatter : provide your own render array for a particular field display, or Widget : provide your own form element for a particular field type, etc. The Plugin systemįor the first post on the plugins I will introduce briefly on the concept. For the example we are going to implement an area that will present some links and text in a custom way, not sure if it's really usefull, but that not the point of this article.
