Problem/Motivation
In Drupal 11, when a content field (e.g., a "Body" field managed by CKEditor 5) contains an embedded block (e.g., a Views block displaying recent articles), and this content is exposed via a Views REST Export display, the JSON output returns <drupal-render-placeholder> tags instead of the rendered HTML for the embedded block.
For example, if a basic page's body field embeds a "Recent Articles" Views block, accessing a REST endpoint for that basic page will show a placeholder like this:
<div data-entity-type="block" ... class="embedded-entity"><drupal-render-placeholder callback="Drupal\\block\\BlockViewBuilder::lazyBuilder" arguments="..." token="..."></drupal-render-placeholder></div>This issue prevents decoupled frontends or other API clients from consuming the actual content of embedded blocks, as they receive unrendered placeholder tags. The same content, when viewed in the Drupal UI (e.g., in the Views preview or on the basic page itself), correctly renders the embedded block's HTML.
This behavior is observed in Drupal 11 (specifically D11.2.4) but was not present in Drupal 10.4.8, indicating a change in render placeholder handling within REST contexts.
Steps to reproduce
- Install and enable the
entity_embedmodule. - Configure an embed button for blocks at `/admin/config/content/embed`.
- Set "Embed type" to "Entity".
- Set "Entity Type" to "Block".
- Ensure "Allowed Entity Embed Display plugins" includes "Rendered Entity".
- Add this embed button to the "Full HTML" CKEditor 5 text format at `/admin/config/content/formats/manage/full_html`.
- Enable the "Display embedded entities" filter for the "Full HTML" text format.
- Create a new Views block display (e.g., a block showing "Recent Articles" from a content type like "Article").
- Place this new Views block in a region via the Block layout (e.g., `admin/structure/block`). *This step is crucial for the block to be discoverable and renderable.*
- Create a new Basic Page content. In the CKEditor 5 "Body" field, use the Entity Embed button to embed the Views block created in step 5. Save the content.
- Create a new View with a REST Export display (e.g., path: `/api/content_endpoint`).
- Configure it to show "Content" of type "Basic page".
- Add the "Body" field to the REST export, ensuring it uses a "Processed text" or "Default" formatter.
- Access the REST endpoint in a browser or tool like Postman.
- Observe the JSON output: the "Body" field will contain a
<drupal-render-placeholder>tag for the embedded Views block instead of the list of articles. - In contrast, navigating to the Views preview within Drupal, or viewing the basic page directly, correctly displays the rendered HTML of the embedded block.
Proposed resolution
The issue appears to stem from a specific line of code introduced or significantly altered in Drupal 11 within core/modules/block/src/BlockViewBuilder.php.
Specifically, the following code snippet forces the creation of a render placeholder:
if ($plugin->createPlaceholder()) { $build[$entity_id] += [ '#create_placeholder' => TRUE, ]; }
When this conditional block is removed or commented out, the REST endpoint correctly returns the rendered HTML of the embedded block, resolving the issue for API consumers.
The attached patch implements this by commenting out the problematic lines in BlockViewBuilder.php.
API changes
- Blocks will no longer be marked with
#create_placeholder => TRUEby default in their render array during the `BlockViewBuilder::lazyBuilder` process. Modules or custom code explicitly checking for this render array property to trigger specific asynchronous rendering behaviors might be affected.
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | 3547968-d11-Removed_Default_createPlaceholder_on_BlockViewBuilder.patch | 1.06 KB | someshver |
Issue fork drupal-3547968
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:
- 3547968-d11-embedded-blocks
changes, plain diff MR !13294
Comments
Comment #2
someshver commentedComment #4
cilefen commentedThe code changed in #3437499: Use placeholdering for more blocks.
Please rebase your changes onto the 11.x branch for tests to run. Remove code instead of commenting it out.
Comment #6
someshver commentedI am finding the conflicts too confusing to resolve, so I’m going to create a patch for this instead.
Comment #7
acSpecifically this commit is the culprit: https://git.drupalcode.org/project/drupal/-/commit/bc383a3
The issue also affects things like local tasks and breadcrumbs. Breaks a lot of themes. This issue is a duplicate of https://www.drupal.org/project/drupal/issues/3533588
Comment #8
acDuplicate of https://www.drupal.org/project/drupal/issues/3533588