Skip to content

Commit 6359224

Browse files
committed
[BUGFIX] sortings
1 parent 222456c commit 6359224

2 files changed

Lines changed: 32 additions & 9 deletions

File tree

Classes/Hooks/Datahandler/CommandMapPostProcessingHook.php

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,12 @@ class CommandMapPostProcessingHook
2727
*/
2828
protected $containerFactory;
2929

30-
public function __construct(ContainerFactory $containerFactory)
30+
protected ContainerService $containerService;
31+
32+
public function __construct(ContainerFactory $containerFactory, ContainerService $containerService)
3133
{
3234
$this->containerFactory = $containerFactory;
35+
$this->containerService = $containerService;
3336
}
3437

3538
public function processCmdmap_postProcess(string $command, string $table, $id, $value, DataHandler $dataHandler, $pasteUpdate, $pasteDatamap): void
@@ -54,6 +57,19 @@ protected function localizeOrCopyToLanguage(int $uid, int $language, string $com
5457
$last = $dataHandler->copyMappingArray['tt_content'][$uid] ?? null;
5558
if ($command === 'copyToLanguage') {
5659
$containerId = $last;
60+
$pos = $this->containerService->getAfterContainerElementTarget($container);
61+
// move next record after last child
62+
$cmd = ['tt_content' => [$last => [
63+
'move' => [
64+
'target' => $pos,
65+
'action' => 'paste',
66+
'update' => [],
67+
]
68+
]]];
69+
$localDataHandler = GeneralUtility::makeInstance(DataHandler::class);
70+
$localDataHandler->enableLogging = $dataHandler->enableLogging;
71+
$localDataHandler->start([], $cmd, $dataHandler->BE_USER);
72+
$localDataHandler->process_cmdmap();
5773
} else {
5874
$containerId = $container->getUid();
5975
}
@@ -132,6 +148,18 @@ protected function copyOrMoveChildren(int $origUid, int $newId, int $containerId
132148
$localDataHandler->enableLogging = $dataHandler->enableLogging;
133149
$localDataHandler->start([], $cmd, $dataHandler->BE_USER);
134150
$localDataHandler->process_cmdmap();
151+
if (!isset($origCmdMap['tt_content'][$origUid][$command]['update']['sys_language_uid'])) {
152+
continue;
153+
}
154+
if ($origCmdMap['tt_content'][$origUid][$command]['update']['sys_language_uid'] === $record['sys_language_uid']) {
155+
continue;
156+
}
157+
$target = -$record['uid'];
158+
// copy case
159+
$newId = $localDataHandler->copyMappingArray['tt_content'][$record['uid']] ?? null;
160+
if ($newId !== null) {
161+
$target = -$newId;
162+
}
135163
}
136164
(GeneralUtility::makeInstance(DatahandlerProcess::class))->endContainerProcess($origUid);
137165
} catch (Exception $e) {

Classes/Hooks/Datahandler/DatamapPreProcessFieldArrayHook.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,14 @@ public function __construct(
5656

5757
protected function newElementAfterContainer(array $incomingFieldArray): array
5858
{
59+
if (isset($incomingFieldArray['sorting'])) {
60+
return $incomingFieldArray;
61+
}
5962
$record = $this->database->fetchOneRecord(-(int)$incomingFieldArray['pid']);
6063
if ($record === null) {
6164
// new elements in container have already correct target
6265
return $incomingFieldArray;
6366
}
64-
if ((int)$record['uid'] === (int)($incomingFieldArray['tx_container_parent'] ?? 0)) {
65-
return $incomingFieldArray;
66-
}
67-
if ((int)($incomingFieldArray['tx_container_parent'] ?? 0) > 0 &&
68-
(GeneralUtility::makeInstance(DatahandlerProcess::class))->isContainerInProcess((int)$incomingFieldArray['tx_container_parent'])
69-
) {
70-
return $incomingFieldArray;
71-
}
7267
if (!$this->tcaRegistry->isContainerElement($record['CType'])) {
7368
return $incomingFieldArray;
7469
}

0 commit comments

Comments
 (0)