Creating blocks using plugins
In Drupal, a block is a piece of content that can be placed in a region provided by a theme. Blocks are used to present specific kinds of content, such as a user login form, a snippet of text, and many more.
Blocks are configuration entities, and the block module uses the Drupal plugin system as a way to define blocks for modules. Custom blocks are defined in the PHP code in the module's Plugin
class namespace. Each class in the Plugin/Block
namespace will be discovered by the block module's plugin manager.
In this recipe, we will define a block that will display a copyright snippet and the current year, and place it in the footer region.
Getting ready
Create a new module like the one shown in this recipe. We will refer ...
Get Drupal 8: Enterprise Web Development now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.