Score:2

Display custom module block in page content

br flag

I have created a custom module providing a block.

The block is available in the block library under "Block Layout" (/admin/structure/block).

On the other hand, I have a custom content type with an "Entity reference revisions" field that allows me to add any kind of content to a page. I can select "Add Drupal Block" in this field but my custom block either:

  1. Shows up in the list if it's placed in the block layout (but then it appears twice on the page)
  2. Doesn't show at all in the list if it's not placed in the block layout

Am I misunderstanding something or doing something wrong ? Thanks!

cn flag
I'm not sure if you can use Entity Reference Revisions to place blocks (hopefully someone else can chime in about that). What you can do using the core modules is to enable Layout Builder and place the block using Layout Builder. Layout Builder will let you build a specific layout for your custom content type, or even a specific node of that content type.
Score:2
cn flag

You've created a custom block plugin in a custom module and now you need to configure it? Then the question is where to store the configuration when you don't want to use the block layout.

This could be the Layout Builder as commented or a smaller, more targeted module like https://www.drupal.org/project/block_field.

The "Entity reference revisions" field is usually used together with Paragraphs. Then "Add Drupal Block" adds a paragraph type, in which you could use the mentioned field module. This module can be used as a stand-alone node field as well if the only purpose of this field is to place the block.

br flag
Thank you very much, that works like a charm!
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.