Blocks are boxes of content in Drupal, It is like a component and we can place them on a web page by placing them in any region of the theme. Drupal provides many inbuilt blocks and you can use view to create new blocks. I believe creating a block using a view is the best method. We can create a block with dynamic content using it. However, the Drupal core system provides an annotation to create a custom block.
In this article, we will see how to create and define custom blocks with a single configurable field.
Your first step will be, to create a custom module. I am skipping info.yml as we all know how to do that and let's assume ourblock is our module name.
Annotation
Here id is our block unique id or you can say it’s a machine name and admin_label is a translatable label that will show in the admin.
As we are going to define one configurable field with our block so we also need to define its schema under ourblock/config/schema so our system can know which type of value our field will hold.
Here is the schema for our block. (ourblock.schema.yml)
Now we have to define our block class in the directory ourblock/src/Plugin/Block and our namespace will be Drupal\ourblock\Plugin\Block.
Now enable your module from the backend and your block is ready to be placed on regions of the theme, You can place it from Block Layout.