Blocks do not have placeholders in Layout Builder

Created on 29 September 2021, about 3 years ago
Updated 24 October 2024, about 2 months ago

Problem/Motivation

Element::isEmpty() is used by BlockComponentRenderArray to determine if a block is empty.
However Inline Blocks (and perhaps some complex Views blocks) do not return an empty array when they are empty.
Because it's a rendered entity, it has several keys like #block_content, #view_mode, and an empty child array for each field.

Original report:
Custom blocks added through Layout Builder do no have placeholders, while standard blocks do. These placeholders were added a few years ago in issues like Provide placeholders for empty blocks (for example, an empty Views listing) β†’ , but this did not make placeholders universal. If you create a custom block type and then add it to a layout, but choose not to display the title, the block is completely invisible to editors. My understanding was that the previous issue was also supposed to add placeholders for views blocks, but my testing shows that views blocks are also lacking these placeholders.

Steps to reproduce

Steps:
Install Layout Builder
Enable Layout Builder for Basic Page (any content type will do, and "Allow each content item to have its layout customized." is not required).
Add an inline block with a title, no body field, and hide the title (uncheck "Display title")
Expectation:
Placeholder for the "Block title" block shown on page
Actual:
Nothing shown on page. Block still takes up vertical space and contextual links are available.

Proposed resolution

Either improve how "empty" entities are rendered, or improve the checking in BlockComponentRenderArray.

Remaining tasks

Figure out how to fix

User interface changes

The expected text will display

API changes

TBD

Data model changes

N/A

Release notes snippet

TBD

πŸ› Bug report
Status

Needs work

Version

11.0 πŸ”₯

Component

layout_builder.module

Created by

πŸ‡ΊπŸ‡ΈUnited States chrisgross

Live updates comments and jobs are added and updated live.
  • Blocks-Layouts

    Blocks and Layouts Initiative. See the #2811175 Add layouts to Drupal issue.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024