From 67ef2477b28da9d2d54763f726b90bda20d9b7c7 Mon Sep 17 00:00:00 2001 From: Achim Fritz Date: Mon, 3 Feb 2025 09:12:07 +0100 Subject: [PATCH] [WIP] copy to language --- .../CommandMapPostProcessingHook.php | 33 +++++++++++++++---- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/Classes/Hooks/Datahandler/CommandMapPostProcessingHook.php b/Classes/Hooks/Datahandler/CommandMapPostProcessingHook.php index f14b32c2..b9e50405 100644 --- a/Classes/Hooks/Datahandler/CommandMapPostProcessingHook.php +++ b/Classes/Hooks/Datahandler/CommandMapPostProcessingHook.php @@ -14,6 +14,7 @@ use B13\Container\Domain\Factory\ContainerFactory; use B13\Container\Domain\Factory\Exception; +use B13\Container\Domain\Service\ContainerService; use TYPO3\CMS\Backend\Utility\BackendUtility; use TYPO3\CMS\Core\DataHandling\DataHandler; use TYPO3\CMS\Core\Utility\GeneralUtility; @@ -50,20 +51,38 @@ protected function localizeOrCopyToLanguage(int $uid, int $language, string $com { try { $container = $this->containerFactory->buildContainer($uid); - (GeneralUtility::makeInstance(DatahandlerProcess::class))->startContainerProcess($uid); + $last = $dataHandler->copyMappingArray['tt_content'][$uid] ?? null; + if ($command === 'copyToLanguage') { + $containerId = $last; + } else { + $containerId = $uid; + } $children = $container->getChildRecords(); - $children = array_reverse($children); - $cmd = ['tt_content' => []]; foreach ($children as $colPos => $record) { - $cmd['tt_content'][$record['uid']] = [$command => $language]; - } - if (count($cmd['tt_content']) > 0) { + $cmd = ['tt_content' => [$record['uid'] => [$command => $language]]]; + $localDataHandler = GeneralUtility::makeInstance(DataHandler::class); + $localDataHandler->enableLogging = $dataHandler->enableLogging; + $localDataHandler->start([], $cmd, $dataHandler->BE_USER); + $localDataHandler->process_cmdmap(); + $newId = $localDataHandler->copyMappingArray['tt_content'][$record['uid']] ?? null; + if ($newId === null) { + continue; + } + $cmd = ['tt_content' => [$newId=> [ + 'move' => [ + 'target' => -$last, + 'action' => 'paste', + 'update' => [ + 'tx_container_parent' => $containerId, + ] + ] + ]]]; $localDataHandler = GeneralUtility::makeInstance(DataHandler::class); $localDataHandler->enableLogging = $dataHandler->enableLogging; $localDataHandler->start([], $cmd, $dataHandler->BE_USER); $localDataHandler->process_cmdmap(); + $last = $newId; } - (GeneralUtility::makeInstance(DatahandlerProcess::class))->endContainerProcess($uid); } catch (Exception $e) { // nothing todo }