Fix: Propagate block index in recursive processing#1363
Open
ggutenberg wants to merge 1 commit intodevelopfrom
Open
Fix: Propagate block index in recursive processing#1363ggutenberg wants to merge 1 commit intodevelopfrom
ggutenberg wants to merge 1 commit intodevelopfrom
Conversation
…orrectly track block instance order across inner blocks
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.
Description of the Change
When distributing posts that contain registered data (e.g., media IDs registered via
distributor_register_data) inside inner blocks — such ascore/imageblocks nested insidecore/columns— all sibling inner block instances incorrectly receiveextra_datafrom index0instead of their own sequential index. In practice this means every image in a columns layout is replaced with the media item from the first column, overwriting the correct media for subsequent columns.Root cause: In
RegisteredDataHandler::process_blocks_data_recursive(), the$indexcounter is passed by value into each recursive call for inner blocks, but the updated value returned by that call is never read back. Once the recursive call returns,$indexstill holds its pre-call value, so the next parallel branch of inner blocks starts counting from the wrong position.Fix: Three minimal changes to
process_blocks_data_recursive():@returntag — document that the returned array always includes an'index'key.'index' => $indexto the early-return array so every code path returns a consistent shape.$index = $inner_result['index'], ensuring sibling branches receive the correct offset.How to test the Change
distributor_register_datatargetingcore/imageblocks (the built-indt_post_distribute_media_cbcallback works).core/columnsblock with at least two columns, placing a different image block in each column.composer run-tests) and confirm all tests pass.Changelog Entry
Credits
Props @ggutenberg
Checklist: