- 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.
- HTML5+CSS3+JavaScript從入門到精通:上冊(cè)(微課精編版·第2版)
- Getting Started with Citrix XenApp? 7.6
- 流量的秘密:Google Analytics網(wǎng)站分析與優(yōu)化技巧(第2版)
- R語言數(shù)據(jù)分析從入門到精通
- 單片機(jī)C語言程序設(shè)計(jì)實(shí)訓(xùn)100例:基于STC8051+Proteus仿真與實(shí)戰(zhàn)
- C++ 從入門到項(xiàng)目實(shí)踐(超值版)
- 單片機(jī)C語言程序設(shè)計(jì)實(shí)訓(xùn)100例
- C指針原理揭秘:基于底層實(shí)現(xiàn)機(jī)制
- Application Development with Parse using iOS SDK
- Spring Data JPA從入門到精通
- SQL Server實(shí)例教程(2008版)
- Mastering Responsive Web Design
- 精通Oracle 12c 數(shù)據(jù)庫(kù)管理
- Java程序設(shè)計(jì)基礎(chǔ)教程
- ASP.NET 4權(quán)威指南