6

In Drupal 7 there is Block Reference field module that can reference pretty much all available blocks, including views' blocks, system blocks, menu blocks etc.

I'm just starting with Drupal 8 and since the Block Reference module doesn't have a version for it, and the built-in Entity Reference doesn't seem to pick up views' blocks, system blocks, I want to create a new custom block type. In this new block type, I want to have a reference field that can reference all available block content.

Is there a way to do it?

2 Answers 2

6

Like I said, I'm new to Drupal 8 so not familiar with new rule and features. After a bit digging here is what I found out.

Entity Reference field allows to reference block instances (config) or custom blocks (content).

Before I was set my field to Content > Custom block, now I switch it to Configuration > Block then you have to Place the block that you want to reference to, even if it is in disabled. After that, you can have your Entity Reference field pick that up otherwise it won't show.

You can have a look at here for more detail.

3
  • Wow. Both a good question and a pretty good answer. So this works even if block is disabled? All logic for block visibility can be done in code? Commented Jan 11, 2016 at 6:00
  • 1
    Forgive my tardiness, I just find out that you can reference a block instance but it can't be in disabled state : ( it won't show with "Restrict access" message. If I create a custom block type that display some block instances, those instances have to be enabled. Then what is the point?! May be I misunderstand the concept. Anyway to workaround I create another block region but won't show in page and put all the instance that I want to reference to into this block region.
    – wzh
    Commented Jan 25, 2016 at 3:06
  • Did you ever find another solution? Seems odd to have to enable another unused block region, I wonder if that is the expected use? There may be some better way to be going about this? I will post back if I find anything. Commented May 25, 2016 at 7:02
3

To fix the restricted access: make a region in yourtheme.info. Don't render the region in your page.html.twig. Place the config block in that region.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.