Skip to content

Commit

Permalink
[WIP] copy to language
Browse files Browse the repository at this point in the history
  • Loading branch information
achimfritz committed Feb 3, 2025
1 parent b623455 commit 67ef247
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions Classes/Hooks/Datahandler/CommandMapPostProcessingHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 67ef247

Please sign in to comment.