Problem/Motivation

On Drupal 11.3.18 with PHP 8.5, saving and viewing content with Layout Builder enabled but no section selected produces repeated deprecation warnings:

Deprecated function: Using null as an array offset is deprecated, use an empty string instead in Drupal\layout_builder\Section->toRenderArray()

The empty Layout Builder state uses the internal layout_builder_blank layout. Its retained components have no region because no real section and therefore no region has yet been selected.

Section::toRenderArray() nevertheless renders those components and uses the null region as an array key:

$regions[$component->getRegion()][$component->getUuid()] = $output;

Adding a real section gives the components valid regions and stops the warnings. Configuring a default section is not a general workaround because doing so preselects a layout before the content creator chooses the required layout.

Diagnostic logging produced entries such as:

Layout Builder component 6876ecee-c2cc-46b6-99c4-321974d8852d in layout layout_builder_blank has no region.

While the problem has not been reproduced beyond Drupal 11.3.18, 11.4.x still uses the same Section::toRenderArray() logic, and no 11.4.x release note or committed issue fixing this Layout Builder path was found. Drupal 11.4.6 included other PHP 8.5 deprecation fixes, but not this one.

Steps to reproduce

  1. Use Drupal latest stable or main with PHP 8.5.
  2. Install standard profile
  3. Login and add a content type
  4. Go to manage display for the content type, enable Layout builder on the Default display, click Manage layout and delete the default section, this will make the display fall back to a layout_builder_blank section
  5. Add a field to the content type - this will cause the new field to be added to the blank section (this will change in #3115759: Prevent auto-adding new fields to LB layouts)
  6. Create a node of that type.
  7. Save the content.
  8. Observe repeated deprecation warnings from Section::toRenderArray().
  9. Add a real section and save again.
  10. Observe that the warnings stop.

Proposed resolution

Guard against NULL regions.

Issue fork drupal-3629628

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

seeduardo created an issue. See original summary.

seeduardo’s picture

Status: Active » Needs review

I added an initial fix that returns an empty render array for the internal layout_builder_blank placeholder before its regionless components are rendered.

acbramley’s picture

I just hit this as well, I wonder if it'd be better to just continue inside the loop if $component->getRegion() is NULL?

smustgrave’s picture

Version: 11.x-dev » main

Not sure I follow "Leave the overridden layout without a selected section." could the steps be cleaned up some?

acbramley’s picture

Issue summary: View changes
acbramley’s picture

Issue summary: View changes

I've pushed a slightly different solution which I think is more robust and added a test.

smustgrave’s picture

Sweet I’ll test it out tomorrow. I wasn’t sure we needed a test or not

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new1.23 KB

The Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

acbramley’s picture

Status: Needs work » Needs review