Skip to content

[BUGFIX] keep child order on copy and move to other language - #761

Open
DenisMir wants to merge 1 commit into
b13:masterfrom
Communiacs:bugfix/keep-child-order-on-language-change
Open

[BUGFIX] keep child order on copy and move to other language#761
DenisMir wants to merge 1 commit into
b13:masterfrom
Communiacs:bugfix/keep-child-order-on-language-change

Conversation

@DenisMir

@DenisMir DenisMir commented Aug 4, 2026

Copy link
Copy Markdown

Fixes #760

copyOrMoveChildren() reverses the children per colPos. That is correct as long as every child is pasted on the same positive target, which rewriteCommandMapTargetForTopAtContainer() resolves to "top of the container column" — inserting a reversed list at the top repeatedly restores the original order.

As soon as the paste update carries a sys_language_uid that differs from the child's own language, the target switches to -$previousUid at the end of the first iteration. From the second child on the semantics change from insert at top to insert after the previous one, while the list is still reversed, so the children end up in reverse order. This applies to the copy and the move branch alike.

The fix keeps the reversal for the top-insert case and iterates in natural sorting order when the loop is going to chain.

Tests

Three cases in Tests/Functional/Datahandler/Localization/FreeMode/ContainerTest.php:

Test Purpose
copyContainerKeepsChildOrder guards the unchanged same-language path
copyContainerToOtherLanguageKeepsChildOrder the reported bug
moveContainerToOtherLanguageKeepsChildOrder same bug on move

The existing cross-language fixtures only have a single child per colPos, where array_reverse() is a no-op — that is why this went unnoticed. The new fixtures use three children in colPos 200 and two in colPos 201.

Without the fix both cross-language tests fail with the children swapped; the same-language test stays green. With the fix the full suite passes (524 functional, 23 unit), CGL and PHPStan v14 are clean.

Note

A few lines below the change, BackendUtility::getRecord('tt_content', abs($newId), 'pid') returns ?array but $previousRecord['pid'] is accessed unconditionally. Unrelated to this bug, so I left it out — happy to add a guard here or in a separate PR, whichever you prefer.

copyOrMoveChildren reverses the children per colPos, which is only
correct as long as every child is pasted on the same target, resolved
to the top of the container column. When the language changes, the
target switches to the previously handled child from the second child
on, so the reversed order is no longer compensated and the children
end up in reverse order.

Fixes: b13#760
@d-g-codappix

Copy link
Copy Markdown

PRAIS Thank you. I'll test your patch on monday next week.

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.

copyOrMoveChildren: child order reversed when copying to another language

2 participants