I am just reposting https://www.drupal.org/project/drupal/issues/2940212#comment-12721220 as a separate issue as requested.
Essentially, due to certain configurations of Views blocks, there are instances where the block may not have a viable preview that Layout Builder can use in the UI. This can cause confusing and difficulty placing and arranging blocks in the Layout Builder.
For instance, if you have a View with a contextual filter that does not validate in Layout Builder ( i.e. using a Node ID ) and the View is configured to "Hide View" if the filter present, when the block is placed in Layout Builder, there is no way to tell there is a block:

I had a similar case where there are 3 views blocks with the same filter. When placing the block in Layout Builder, there are 3 blank places, making it impossible to know which block I am moving / configuring.
My suggestion is to add some sort of indicator that there is a block placed, even if the current display is hidden.
A couple of options that come to mind:
- An outline around each placed block
- A small label for the block name in a corner of the block ( maybe just when hovering or moving the block? )
- Alternatively, use the View / Block ID as the label.
Here is potentially what a hidden block might look like:

| Comment | File | Size | Author |
|---|---|---|---|
| #22 | 2992410-placeholder-22.patch | 12.38 KB | tim.plunkett |
| #22 | 2992410-placeholder-22-interdiff.txt | 4.45 KB | tim.plunkett |
| #20 | 2992410-placeholder-20.patch | 10.83 KB | tim.plunkett |
| #20 | 2992410-placeholder-20-interdiff.txt | 3.64 KB | tim.plunkett |
| #16 | 2992410-placeholder-16-PASS.patch | 10.07 KB | tim.plunkett |
Comments
Comment #2
tim.plunkettPerhaps we can solve this problem for all blocks at once.
Comment #3
tim.plunkettBecause BlockBase and BlockPluginInterface have a tight 1:1 coupling, this is not considered a BC break.
Comment #4
scottsawyerBrilliant, will test in about 5 hours.
Comment #5
tim.plunkettComment #6
scottsawyerHey Tim,
I am using Drupal core 8.5.6, so I was unable to install the patch. Unfortunately, it's going to be a little while until I can test on 8.7. Maybe a few days.
Scott
Comment #7
tim.plunkettHere's an 8.5.x compatible one for testing.
The 8.7.x patch will also work on 8.6.x
Comment #9
tim.plunkettNeed to switch the way it checks for emptiness... by using the one named isEmpty!
Comment #11
tim.plunkettFixed a test, and renamed the method to be more clear.
Comment #12
johnwebdev commentedHmm, I wish we had something to retrieve a single extra field instead, but its static cached anyhow so its fine.
I think this looks great, but still needs test coverage.
Comment #13
scottsawyerI applied the patch in #7, but I am not seeing any difference on the manage display screen.
Comment #14
brian-c commentedThis is working great for me with a Views block.
Comment #15
sugaroverflow commentedConfirming that this works great!
Here's what I did:
1 - Created a related articles view block
2 - Added a Content: Has taxonomy term filter
3 - Added a contextual filter: Content: ID with the following settings: When the filter is not available- provide default value: "Content ID from URL"
4 - Attempted to place this block on the article content type, nothing appeared.
5 - Applied the patch from #11, cleared cache
6 - Observed a placeholder for my view -- attaching a screenshot.
Also needs tests.
Comment #16
tim.plunkett@sugaroverflow and I paired on this test.
Comment #18
tim.plunkettComment #19
phenaproximaI think this patch is a really, really nice idea. From a UX perspective, it's super-valuable (IMHO) to be able to show people where something will go.
I wonder if this should be its own interface. It's entirely possible that this functionality might be useful for things that are not blocks, so maybe we could just have a stand-alone \Drupal\Core\Render\PlaceholderInterface and get BlockPluginInterface to extend it. What do you think?
Additionally, I wonder if this should not return a renderable array. That would open the door to using things like placeholder images or other neatness. On the other hand, I'm not sure if it would complicate things too much. Worth mentioning, though!
EDIT: It looks like the core render system already has some code in place for dealing with placeholders -- I believe it is there because of BigPipe. Could be worth looking into that existing code?
Comment #20
tim.plunkettI'm fine with a separate interface, that could indeed be useful. I also removed the API addition to BlockPluginInterface and added an instanceof check before calling the method. But I still put it on BlockBase.
If we switched from a string to a render array, we'd have to make this
$build['content']['placeholder'] = $block->getPlaceholder();to avoid conflicts with any existing #cache keys.And then all existing implementations will have
return ['#markup' => $whatever];instead ofreturn $whatever;Not ruling it out, just thinking it through...
It's probably the right thing to do to be future-thinking, but it certainly makes things unwieldy until we need more than a string.
Comment #21
phenaproximaWouldn't we want to use $this->label() here? It will default to admin_label if not set, and I feel like that might be clearer for the users, if they're setting the label in a meaningful way.
Why was this changed? Not objecting, just asking in case committers do...
Comment #22
tim.plunkett1) I thought about this and decided against it at first, but on second thought I agree
2) Previously FieldBlock had it's own built in placeholder system based on the existence of
$entity->in_preview. Now that we're removing it, these tests should be streamlined completely.Comment #23
phenaproximaOkay, I feel pretty good about it. Let's make it happen!
Comment #25
larowlanCommitted 53f1980 and pushed to 8.7.x.
Comment #27
wim leers@tim.plunkett mentioned #3007439: Layout builder renders Book navigation block on non-book pages was a
Blocks-Layoutsblocker. So I looked at it … and discovered a unknown-to-mePlaceholderInterface, which was introduced here. Quoting my comment at #3007439-10: Layout builder renders Book navigation block on non-book pages.1:So yeah … I really really hate to reopen this, but I think I have to, to avoid future confusion.
Pre-existing:
\Drupal\Core\Render\PlaceholderGenerator(Interface)\Drupal\Core\Render\PlaceholderingRenderCache\Drupal\Core\Render\Placeholder\PlaceholderStrategyInterface\Drupal\Core\Render\Placeholder\ChainedPlaceholderStrategy\Drupal\Core\Render\Placeholder\SingleFlushStrategy\Drupal\big_pipe\Render\Placeholder\BigPipeStrategyAdded in this issue:
\Drupal\Core\Render\PlaceholderInterfaceThe pre-existing code/classes/interfaces ones define "placeholder" as an something to be replaced with final content. Used to for example be able to cache the entire
/node/42response except for the comment form which is then cacheable by Dynamic Page Cache; the comment form is present only as a placeholder, and is replaced by\Drupal\Core\Render\Renderer::replacePlaceholders()just before sending a response to the end user. A placeholder looks like this:<drupal-render-placeholder callback="…" arguments="…" token="…" ></drupal-render-placeholder— the end user never gets to see this. That's theSingleFlushStrategy. When BigPipe is installed, the placeholders look different: they become BigPipe placeholders (currently just empty<div>s since they do end up in the end user's DOM, but #2632750: Interface previews/skeleton screens through optional "preview" or "placeholder" templates would change this so that a more meaningful placeholder can be shown: an interface preview, or alternatively, perhaps just a spinner).The interface added in this issue defines "placeholder" to be something rather different, for a different purpose. It's even explicitly for blocks that commonly render to something that's empty! If that weren't the case, then perhaps it could be used to help solve #2632750: Interface previews/skeleton screens through optional "preview" or "placeholder" templates. But because it's explicitly about "placeholder to make something that may not show up still be visually present, accessible and navigatable", it seems fundamentally different?
Hence my concern here: we now have two very different "placeholder" concepts in the
\Drupal\Core\Rendernamespace.This was only committed to Drupal 8.7. I think we can rename the interface introduced here without breaking BC.
Sorry Tim! :(
Comment #28
dsnopekAs far as terminology: maybe this could be a "block preview" rather than a "placeholder"?
Comment #29
wim leers#28: yep, exactly.
And the more I think about it, the more I think that this needs exactly the same infrastructure as #2632750: Interface previews/skeleton screens through optional "preview" or "placeholder" templates. I was thinking about that issue again today and had forgotten I'd already made this connection a week ago in #7…
It'd be wonderful if we could introduce one "preview interface" and use it for both Layout Builder and BigPipe!
Comment #30
tim.plunkettWe can do
s/getPlaceholderString/getPreviewFallbackStringAs that's what it is, a fallback when the preview fails
Comment #31
wim leersMakes sense 👍
I think it then also makes sense to rename
PlaceholderInterfacetoPreviewFallbackInterface. What do you think?Comment #33
webchickAlso backported to 8.6.x.
Comment #34
tim.plunkettWith two commits here, unless we plan to fully revert this then let's close and move to a follow-up.
The backport puts a deadline on that for the next 8.6 minor...
#3013187: Rename PlaceholderInterface to PreviewFallbackInterface