Skip to content

copyOrMoveChildren: child order reversed when copying to another language #760

Description

@DenisMir

Description

When a container content element is copied (or moved) into a different language column in the page module, its child elements end up in exactly reverse order. Copying within the same language works correctly, and the localization wizard ("Translate" / "Copy") is not affected either.

Env

14LTS
Container 4.0.2

Steps to reproduce

  1. Create a container (e.g. 1-col-container) in the default language with three children in a known order — A, B, C.
  2. In the page module, copy or drag the container into another language column (free mode).
  3. Look at the copied container.

Expected: children in order A, B, C.
Actual: children in order C, B, A.

Nested containers are affected at every level; a container whose only child is another container looks fine at the top level while the inner children are reversed.

Cause

Classes/Hooks/Datahandler/CommandMapPostProcessingHook::copyOrMoveChildren() builds the child list reversed per colPos:

$childrenByColPos = $container->getChildrenByColPos($colPos);
$childrenByColPos = array_reverse($childrenByColPos);

That is correct as long as every child is pasted onto the same positive $target, which CommandMapBeforeStartHook::rewriteCommandMapTargetForTopAtContainer() resolves to "top of the container column" — repeatedly inserting a reversed list at the top restores the original order.

However, at the end of the loop the target switches whenever the paste update carries a sys_language_uid that differs from the child's own language:

$target = -$record['uid'];
$newId = $localDataHandler->copyMappingArray['tt_content'][$record['uid']] ?? null;
if ($newId !== null) {
    $target = -$newId;
}

From the second child onwards the semantics change from insert at top to insert after the previous one, while the list is still reversed — so the reversal is no longer compensated. This applies to both the copy and the move branch.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions