I've been testing the Facets module with Layout Builder in D8.6 and 8.7-dev. There is an issue handling empty facet blocks. Core has implemented a PreviewFallbackInterface to handle empty blocks. When a block is empty, a fallback text string is rendered within Layout Builder to allow the content editor to still have a block object they can interact with (move around, configure, etc).
Core will use this preview fallback whenever it detects an empty block. However, an empty facet block is not actually empty. In DefaultFacetManager::build there is logic to detect an empty facet, and either add text or return the empty facet based on the facet config. But when returning the empty facet, the content is not empty and instead has a container with the "facet-empty" class that is used by Javascript.
This causes a problem when placing facet blocks via Layout Builder since the core preview fallback text will not be used.
There needs to be some way to trigger the core functionality so content editors can place empty facet blocks in Layout Builder.
I'm also going to point the core Layout Builder devs to this issue since as far as I can tell there isn't an easy way for the block build() function to know if it's being previewed or not to allow for custom fallback functionality.
To test this issue, simply use Layout Builder to place a facet block and sure "display title" is unchecked. You'll see that there isn't any block available in the Layout Builder UI to move, delete, or configure at that point.
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | 3027593-facets-4.patch | 1.8 KB | mpotter |
| #2 | 3027593-facets-2.patch | 1.75 KB | tim.plunkett |
Comments
Comment #2
tim.plunkettThis is blocked on #3027653: Allow block and layout plugins to determine if they are being previewed.
But if that patch is applied (or committed), this should do the trick.
Comment #3
mpotter commentedApplied both this and 3027653 and got:
within the FacetBlock build() function.
I think the core patch is setting the context for the SectionComponentBuildRenderArrayEvent but here it's checking the context of the block object itself.
Edited: Hmm, maybe I need to create new facet block instances for this to take affect. Let me try that.
Comment #4
mpotter commentedAhh, Tim pointed out the "context" was a changed to "context_definitions" between 8.6 and 8.7. So #2 is for core 8.7, here is a patch for core 8.6
Comment #5
borisson_Ok, so that means we should probably wait for 8.7 to come out, then commit tim's patch?
Comment #6
fdefeyter@gmail.com commentedFollowing :-)
Comment #7
mkalkbrennerComment #9
mkalkbrennerWe ran into this problem today. Patch #2 solved the issue.