Problem/Motivation
The TextFirstPara field formatter causes an InvalidArgumentException: "0" is an invalid render array key error when a text field contains content without a tag. This occurs because the formatter returns a scalar string value ('') instead of a proper render array when no paragraph element is found.
The error manifests during rendering: InvalidArgumentException: "0" is an invalid render array key. Value should be an array but got a string. in Drupal\Core\Render\Element::children()
This prevents pages from rendering when nodes with empty or non-paragraph-wrapped text fields are displayed using the "First Paragraph" formatter.
Steps to reproduce
Create a content type with a text field (text_long or text_with_summary)
Configure the field display to use the "First Paragraph" formatter
Create a node where the text field either: Is empty, or Contains text without tags (e.g., plain text or other HTML elements)
Attempt to render the node in the configured view mode
Observe the InvalidArgumentException error
Proposed resolution
Change line 93 in TextFirstPara.php from: $elements[$delta] = '';
To: $elements[$delta] = [ '#markup' => '', ];
This ensures that even when no paragraph is found, a valid render array structure is returned instead of a scalar string value.
Remaining tasks
Review and commit the patch
Add test coverage for edge cases (empty fields, non-paragraph content)
Create a new release with the fix
| Comment | File | Size | Author |
|---|---|---|---|
| first_paragraph-invalid-render-array-key.patch | 423 bytes | jv24 |
Issue fork first_paragraph-3569970
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 #2
jv24Comment #3
nicholasthompsonThanks - this should be fixed in dev and the upcoming 2.1.0 release.
Comment #4
nicholasthompsonThe commit ahead of this (found during D12 upgrades) made it an empty array. Your fix is more explicit, so adopting that instead + adapting some new test coverage:
https://git.drupalcode.org/project/first_paragraph/-/merge_requests/3