Problem/Motivation

It's not possible to add ESI for blocks in layout builder.

Steps to reproduce

Enable layout builder on node bundle and add a block to this layout. No ESI options can be selected.

Proposed resolution

Add ESI support for layout builder blocks.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

GoZ created an issue.

shumer’s picture

That's a whole new feature here :)
Thanks working on that and raising a PR!

The overall approach is solid. The architecture makes sense: event subscriber on section_component.build.render_array, form alter for LB block forms, settings stored in SectionComponent, shared form definition service, and a dedicated controller with composite block ID. These are the right integration points.

However, there are several issues that need to be addressed before this can be merged.

Performance concern:
- ESILayoutBuilderBlockController::content() renders the entire entity view (getViewBuilder()->view($entity, $viewMode)) and then manually calls pre_render and iterates all sections/regions just to find one component by UUID. This is very heavy for an ESI subrequest that should be fast.

Fragile code:
- $view['#pre_render'][0][0]->{$view['#pre_render'][0][1]}($view)is hardcoded array indices into #pre_render. This will break if any module adds or reorders pre_render callbacks.
- $this->requestStack->pop() / push() : manipulating the request stack is risky and can cause issues with other subscribers.

Missing:
- No tests (unit or functional).
- Missing docblocks on several classes.

Edge cases not handled:
- Layout Builder per-entity overrides (entity-level layouts store sections differently from default display).
- LB preview mode, in this case blocks should NOT be replaced with ESI tags during preview.