Skip to content

Commit 67ef247

Browse files
committed
[WIP] copy to language
1 parent b623455 commit 67ef247

File tree

1 file changed

+26
-7
lines changed

1 file changed

+26
-7
lines changed

Classes/Hooks/Datahandler/CommandMapPostProcessingHook.php

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
use B13\Container\Domain\Factory\ContainerFactory;
1616
use B13\Container\Domain\Factory\Exception;
17+
use B13\Container\Domain\Service\ContainerService;
1718
use TYPO3\CMS\Backend\Utility\BackendUtility;
1819
use TYPO3\CMS\Core\DataHandling\DataHandler;
1920
use TYPO3\CMS\Core\Utility\GeneralUtility;
@@ -50,20 +51,38 @@ protected function localizeOrCopyToLanguage(int $uid, int $language, string $com
5051
{
5152
try {
5253
$container = $this->containerFactory->buildContainer($uid);
53-
(GeneralUtility::makeInstance(DatahandlerProcess::class))->startContainerProcess($uid);
54+
$last = $dataHandler->copyMappingArray['tt_content'][$uid] ?? null;
55+
if ($command === 'copyToLanguage') {
56+
$containerId = $last;
57+
} else {
58+
$containerId = $uid;
59+
}
5460
$children = $container->getChildRecords();
55-
$children = array_reverse($children);
56-
$cmd = ['tt_content' => []];
5761
foreach ($children as $colPos => $record) {
58-
$cmd['tt_content'][$record['uid']] = [$command => $language];
59-
}
60-
if (count($cmd['tt_content']) > 0) {
62+
$cmd = ['tt_content' => [$record['uid'] => [$command => $language]]];
63+
$localDataHandler = GeneralUtility::makeInstance(DataHandler::class);
64+
$localDataHandler->enableLogging = $dataHandler->enableLogging;
65+
$localDataHandler->start([], $cmd, $dataHandler->BE_USER);
66+
$localDataHandler->process_cmdmap();
67+
$newId = $localDataHandler->copyMappingArray['tt_content'][$record['uid']] ?? null;
68+
if ($newId === null) {
69+
continue;
70+
}
71+
$cmd = ['tt_content' => [$newId=> [
72+
'move' => [
73+
'target' => -$last,
74+
'action' => 'paste',
75+
'update' => [
76+
'tx_container_parent' => $containerId,
77+
]
78+
]
79+
]]];
6180
$localDataHandler = GeneralUtility::makeInstance(DataHandler::class);
6281
$localDataHandler->enableLogging = $dataHandler->enableLogging;
6382
$localDataHandler->start([], $cmd, $dataHandler->BE_USER);
6483
$localDataHandler->process_cmdmap();
84+
$last = $newId;
6585
}
66-
(GeneralUtility::makeInstance(DatahandlerProcess::class))->endContainerProcess($uid);
6786
} catch (Exception $e) {
6887
// nothing todo
6988
}

0 commit comments

Comments
 (0)