Skip to content

Fix undefined array key in document editables sort index for nested blocks#1112

Open
blankse wants to merge 2 commits into
pimcore:2026.1from
blankse:fix/pagesnippet-editables-undefined-array-key
Open

Fix undefined array key in document editables sort index for nested blocks#1112
blankse wants to merge 2 commits into
pimcore:2026.1from
blankse:fix/pagesnippet-editables-undefined-array-key

Conversation

@blankse

@blankse blankse commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

Bug

Querying the editables field of a document_page whose content contains a deeply nested area-/block structure fails with:

"message": "Internal server error",
"path": ["getDocument", "editables"],
"debugMessage": "Warning: Undefined array key \"content:3.contentblock\""
src/GraphQL/DocumentResolver/PageSnippet.php:97

Document meta resolves fine — only the editables field crashes, and only for documents with the nested structure (e.g. content areablock → contentblockcontent → 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:

$block = $elements[$blockName];

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 8 Undefined array key warning, which DataHub escalates to an Internal server error for the entire editables field.

Fix

Guard the lookup with ?? null. The existing if ($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.

$block = $elements[$blockName] ?? null;

One-line, behaviour-preserving for the existing (resolvable) case.

🤖 Generated with Claude Code

blankse and others added 2 commits June 27, 2026 20:20
…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>
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants