Out of Bounds error when adding new section

Created on 1 October 2021, over 3 years ago
Updated 13 February 2023, almost 2 years ago

It looks like Drupal 9 has changed something in the order of operations when creating a new section in Layout Builder as I'm getting an OutOfBoundsException when I attempt to add a new one. The exact error is as follows:

OutOfBoundsException: Invalid delta "1" in Drupal\layout_builder\Field\LayoutSectionItemList->getSection() (line 41 of /var/www/html/web/core/modules/layout_builder/src/SectionStorage/SectionStorageTrait.php).

I've traced the cause back to the getSectionFromFormState method on the FormEntityHelperTrait class. Looks like if you call the getSection method on the section storage object and the section doesn't exist, this error is thrown. Simply checking the delta exists before accessing (or catching the error) and then returning NULL fixes the issue and retains the expected behaviour of this module.

I have a patch incoming doing the former, but it probably needs some review to see if my fix effects anything else (seems to work fine from my testing). Also might be worth looking into exactly what has actually changed in Layout Builder that's necessitating this change.

πŸ› Bug report
Status

Fixed

Version

2.0

Component

Code

Created by

πŸ‡¨πŸ‡¦Canada johnjw59@gmail.com

Live updates comments and jobs are added and updated live.
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