官术网_书友最值得收藏!

Plugins

Plugins are new to Drupal 8 and are an elegant solution to an important problem— encapsulating functionality. Right off the bat, you should not confuse them with things such as the WordPress plugins, which are more akin to Drupal modules. Instead, you should think of plugins as components of reusable code that can be used and managed by a central system. Typically, they are used when a system handles a task in a certain way (plugin A) but allows other modules to provide different ways to handle that task (plugin B or C).

You can also look at plugins as being opposite to entities: not used for data storage, but for functionality. Instead of creating a type of data that gets stored, you create a type of functionality that is used. The two usually work hand in hand, especially when it comes to manipulating the data in different ways.

An important aspect of how they work is their discoverability. Most plugin types (but definitely not all) are discovered via something called Annotations. Annotations are a form of DocBlock comments, borrowed from the Doctrine library (http://docs.doctrine-project.org/projects/doctrine-common/en/latest/reference/annotations.html), by which we can describe classes, methods, and even properties with certain metadata. This metadata is then read to determine what that item is without the need for instantiating the class. In Drupal 8, we use annotations only at a class level to denote that it is a plugin implementation with certain characteristics. That is how most plugins are discovered in Drupal 8.

The second most common discoverability method for plugins is via a YAML file, and a popular example of those are menu links (as we will see later in the book). However, for now, you should know that plugins are very widely used, and we will create quite a few plugins in this book.

Plugins are a great new extension point for developers to add their own functionality and are a critical subsystem in Drupal 8. Every Drupal 8 developer needs to be comfortable with the plugin system.

主站蜘蛛池模板: 什邡市| 沾益县| 百色市| 绥化市| 丽江市| 大新县| 宁波市| 新宾| 英德市| 光泽县| 恭城| 安塞县| 手游| 微山县| 威信县| 伊春市| 巴彦淖尔市| 封开县| 兴义市| 如东县| 射阳县| 达孜县| 威信县| 卓尼县| 镇康县| 柘城县| 汤阴县| 衢州市| 于都县| 阳东县| 淮北市| 兰州市| 台湾省| 德钦县| 景德镇市| 舞阳县| 河曲县| 楚雄市| 长阳| 耿马| 河东区|