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
- Use Drupal 11.3.18 with PHP 8.5.
- Enable Layout Builder and per-content layout overrides for a content type.
- Leave the overridden layout without a selected section.
- Create or edit content of that type.
- Save the content.
- Observe repeated deprecation warnings from Section::toRenderArray().
- Add a real section and save again.
- 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.
| Comment | File | Size | Author |
|---|---|---|---|
| Issue with no sections yet - example 2.png | 117.05 KB | seeduardo | |
| Issue with no sections yet - example.png | 143.8 KB | seeduardo |
Issue fork drupal-3629628
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
Comment #4
seeduardo commentedI added an initial fix that returns an empty render array for the internal
layout_builder_blankplaceholder before its regionless components are rendered.