Skip to content

Commit

Permalink
[BUGFIX] Fix integrity sorting in page with nested containers
Browse files Browse the repository at this point in the history
Relates: #458
  • Loading branch information
d-g-codappix authored and achimfritz committed Aug 6, 2024
1 parent 038a1bd commit 1132599
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 6 deletions.
18 changes: 13 additions & 5 deletions Classes/Domain/Service/ContainerService.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,26 @@ public function getNewContentElementAtTopTargetInColumn(Container $container, in
return $target;
}

public function getAfterContainerElementTarget(Container $container): int
public function getAfterContainerRecord(Container $container): array
{
$target = -$container->getUid();
$childRecords = $container->getChildRecords();
if (empty($childRecords)) {
return $target;
return $container->getContainerRecord();
}

$lastChild = array_pop($childRecords);
if (!$this->tcaRegistry->isContainerElement($lastChild['CType'])) {
return -(int)$lastChild['uid'];
return $lastChild;
}

$container = $this->containerFactory->buildContainer((int)$lastChild['uid']);
return $this->getAfterContainerElementTarget($container);
return $this->getAfterContainerRecord($container);
}

public function getAfterContainerElementTarget(Container $container): int
{
$target = $this->getAfterContainerRecord($container);

return -$target['uid'];
}
}
2 changes: 1 addition & 1 deletion Classes/Integrity/SortingInPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function run(bool $dryRun = true, bool $enableLogging = false, ?int $pid
if (empty($children)) {
$sorting = $record['sorting'];
} else {
$lastChild = array_pop($children);
$lastChild = $this->containerService->getAfterContainerRecord($container);
$sorting = $lastChild['sorting'];

if ($prevChild === null || $prevContainer === null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"pages"
,"uid","pid"
,1,0
"tt_content"
,"uid","pid","colPos","CType","sorting","tx_container_parent"
,1,1,0,b13-2cols-with-header-container,1,
,2,1,0,b13-2cols-with-header-container,2,1
,3,1,202,,5,2
,4,1,0,"b13-2cols-with-header-container",3,
,5,1,202,,4,3
13 changes: 13 additions & 0 deletions Tests/Functional/Integrity/SortingInPageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,19 @@ public function containerIsSortedAfterChildOfPreviousContainerWithChangedChildre
self::assertTrue($rows[2]['sorting'] > $rows[3]['sorting'], 'container should be sorted after child of previous container');
}

/**
* @test
*/
public function containerIsSortedAfterChildOfPreviousContainerWithNestedChangedChildrenSorting(): void
{
$this->importCSVDataSet(__DIR__ . '/Fixtures/SortingInPage/container_is_sorted_before_child_of_previous_container_with_nested_changed_children_sorting.csv');
$errors = $this->sorting->run(false);
self::assertTrue(count($errors) === 1, 'should get one error');
$rows = $this->getContentsByUid();
self::assertTrue($rows[2]['sorting'] > $rows[5]['sorting'], 'container should be sorted after last nested child of previous container');
self::assertTrue($rows[3]['sorting'] > $rows[2]['sorting'], 'child should be sorted after its own parent container after resorting');
}

/**
* @test
*/
Expand Down

0 comments on commit 1132599

Please sign in to comment.