Score:0

Block doesn't show up in the entity reference UI

jp flag

I have an Entity Reference field, whose "type of item to reference" is block.

I have a View that creates a block called staff list but when I edit content that uses that field, I can't get it to present staff list as an option?

Why is this block not selectable? Surely all 'blocks' should be reference-able this way?

Screenshot

Score:1
cn flag

Your field is referencing block config entities. Those exists only for blocks placed in the block layout. If Views creates a block then this is a derivative of a views block plugin and not yet a configured block. You could place the block in block layout, then it shows up in the entity reference select UI. But this is not a good idea. This will cause an error if you remove the configuration and still have references in content.

So better use a different field type. You can place block plugins directly in node fields. See Display custom module block in page content. Or the View directly in a node field, without using a block display. There are a few modules for this:

https://www.drupal.org/project/eva

https://www.drupal.org/project/viewfield

jp flag
Thanks. (I'm now recalling this might be why I abandoned D8 years ago!) So I have a paragraph type that wants to offer authors the opportunity to put something in their para. This might be a custom block, a block generated from any number of modules including a view. Blocks used to be a solid reusable concept. But I think you're suggesting I'd need to add one field for every type of block now? This seems to un-do the whole concept of Blocks?
jp flag
Ah. yes, it was. Just found my question from 5 years ago https://drupal.stackexchange.com/questions/198623/how-to-create-a-field-that-references-a-views-block-display-in-d8 The block_field project looks promising, though it's a lot more of a headache for authors. Maybe I'll go back to placing the block in a non-rendered region (though I remember there were some other problems with that..).
4uk4 avatar
cn flag
OK, if you want to create a paragraph type which allows the user to place a block generated from any number of modules including Views then your question is a duplicate of the linked question asked recently.
4uk4 avatar
cn flag
All three modules have their use cases and there are more modules out there. My favorite is the EVA module if you don't want to give the authors a headache.
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.