RjsfEditorFormatter::viewElements() may return null instead of array

Created on 29 July 2025, 10 days ago

Problem/Motivation

\Drupal\rjsf\Plugin\Field\FieldFormatter\RjsfEditorFormatter::viewElements() is defined by \Drupal\Core\Field\FormatterInterface as returning an array, but the return variable $elements is only defined within a foreach loop, so if $items contains no items, the variable will be undefined and the method will return null instead of an array, causing an error.

Steps to reproduce

Honestly this lack of $items probably only happens if an entity is created programmatically and not through the UI, but it's still a bug in the code.

Proposed resolution

Define $elements = []; before the foreach loop.

Remaining tasks

Make a MR.

πŸ› Bug report
Status

Active

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States BenStallings

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024