How do I create a block in a module that can be referenced via an entity reference field?
-
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?
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.
- install and enable the module
- Create a new field of type Block(plugin) in your paragraph type
- 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
- now you can reference your block in the paragraph.
Licenciado bajo: CC-BY-SA con atribución
No afiliado a drupal.stackexchange