- Drupal 8 Module Development
- Daniel Sipos
- 253字
- 2021-07-02 15:45:17
Blocks
Custom blocks in Drupal 8 are plugins. Finally, we encounter our first plugin type. For the sake of full disclosure, the content blocks that you create through the UI to place in a region and the custom blocks that are placed in a region are content entities. So, the block system is a good example of how entities and plugins work hand in hand in Drupal 8, and not to make matters too complex for you, configuration entities (about which we will learn in a later chapter) also play a big role here.
The block system in Drupal 8 is a great shift from its predecessor. Before, you had to implement two obligatory hooks plus two optional hooks if you wanted the block to have a configuration, and the latter was always saved somewhere that had nothing to do with the block itself. In Drupal 8, we work with a simple plugin class that can be made container-aware (that is, we can inject dependencies into it) and we can store configuration in a logical fashion.
So, how do we create a custom block plugin easily? All we need is one class, placed in the right namespace--Drupal\module_name\Plugin\Block. In this case (with plugins), the folder naming is important. The plugin discoverability is dependent on the plugin type itself, and this one has the Plugin\Block namespace bit in it. Enough talk, let's create a simple block that just renders the same as our Controller did previously, and I will explain things along the way.
- JavaScript 從入門到項目實踐(超值版)
- Mastering SVG
- C語言程序設計基礎與實驗指導
- Python貝葉斯分析(第2版)
- jQuery開發基礎教程
- Hands-On Full Stack Development with Go
- 大數據分析與應用實戰:統計機器學習之數據導向編程
- MySQL從入門到精通(軟件開發視頻大講堂)
- Babylon.js Essentials
- MySQL入門很輕松(微課超值版)
- Unity 2017 Game AI Programming(Third Edition)
- 基于MATLAB的控制系統仿真及應用
- SQL Server 2008實用教程(第3版)
- Effective C++:改善程序與設計的55個具體做法(第三版)中文版(雙色)
- ASP.NET本質論