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 11.3.18 with PHP 8.5.
  2. Enable Layout Builder and per-content layout overrides for a content type.
  3. Leave the overridden layout without a selected section.
  4. Create or edit content of that type.
  5. Save the content.
  6. Observe repeated deprecation warnings from Section::toRenderArray().
  7. Add a real section and save again.
  8. Observe that the warnings stop.

Proposed resolution

Do not render components belonging to the internal layout_builder_blank placeholder. Return an empty render array before iterating over its components.

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.