How do I create a block in a module that can be referenced via an entity reference field?

drupal.stackexchange https://drupal.stackexchange.com/questions/300214

  •  02-03-2021
  •  | 
  •  

Pregunta

I'd like to be able to reference my programmed block as a field in a paragraphs.

I've

  • Generated a module with drupal console - drupal generate:module
  • Used the template for a block from the example module. Only has Plugin/Block/MyBlock.php

I create a new field in my paragraph

  • Field type Reference
  • choose other

How do I get the block to be able to be embedded in this way?

¿Fue útil?

Solución

To achieve this you may use the Block field:
From module description:

Use Cases
Add blocks to a node's sidebar.
Add blocks to paragraph.
Create a carousel of content and configurable blocks.

  1. install and enable the module
  2. Create a new field of type Block(plugin) in your paragraph type
  3. In case you want only your custom block to be referenced in the field settings uncheck all other blocks in the AVAILABLE BLOCKS config like this for my Hello block for exemple enter image description here
  4. now you can reference your block in the paragraph.
Licenciado bajo: CC-BY-SA con atribución
No afiliado a drupal.stackexchange
scroll top