- Drupal 8 Module Development
- Daniel Sipos
- 225字
- 2021-07-02 12:22:40
Blocks
Blocks in Drupal 8 are plugins. However, the blocks you create in the UI are content entities and the placement of both in the block layout are configuration entities. So, the block system is a good example of how entities and plugins work hand in hand in Drupal 8. We will talk in more detail about plugin types and entities later in the book.
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? 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. But 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.
- Mastering Concurrency Programming with Java 8
- R語言數據分析從入門到精通
- Python量化投資指南:基礎、數據與實戰
- Learning C++ Functional Programming
- C語言從入門到精通(第4版)
- CKA/CKAD應試教程:從Docker到Kubernetes完全攻略
- 鋒利的SQL(第2版)
- Learning AngularJS for .NET Developers
- PHP+Ajax+jQuery網站開發項目式教程
- 計算機應用基礎案例教程
- UNIX Linux程序設計教程
- 零代碼實戰:企業級應用搭建與案例詳解
- Learning Grunt
- SEO教程:搜索引擎優化入門與進階(第3版)
- Python應用與實戰