Fix undefined array key in document editables sort index for nested blocks#1112
Open
blankse wants to merge 2 commits into
Open
Fix undefined array key in document editables sort index for nested blocks#1112blankse wants to merge 2 commits into
blankse wants to merge 2 commits into
Conversation
…locks getElementSortIndex() walks the parent block names of a nested editable (e.g. "content:3.contentblock:1.content") and looks each up in the document's editables array. For deeply nested area-/blocks an intermediate block key (e.g. "content:3.contentblock") may be absent from the editables map, so the unguarded access `$elements[$blockName]` raised "Warning: Undefined array key" on PHP 8, which DataHub escalates to an "Internal server error" for the whole `editables` field. Guard the lookup with `?? null`; the existing `instanceof BlockInterface` check already handles a missing block gracefully (that segment simply contributes no sort index, as when the key is not found). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Bug
Querying the
editablesfield of adocument_pagewhose content contains a deeply nested area-/block structure fails with:Document meta resolves fine — only the
editablesfield crashes, and only for documents with the nested structure (e.g.contentareablock →contentblock→content→ brick).Root cause
getElementSortIndex()walks the parent block names of a nested editable (e.g.content:3.contentblock:1.content) and looks each intermediate block name up in the document's editables map:For a deeply nested editable an intermediate block key (e.g.
content:3.contentblock) can be absent from the editables map, so this unguarded access raises a PHP 8Undefined array keywarning, which DataHub escalates to anInternal server errorfor the entireeditablesfield.Fix
Guard the lookup with
?? null. The existingif ($block instanceof BlockInterface)already handles a missing block gracefully — that path segment simply contributes no sort index, exactly as when the block key is present but the index is not found.One-line, behaviour-preserving for the existing (resolvable) case.
🤖 Generated with Claude Code