diff --git a/Classes/Hooks/Datahandler/CommandMapPostProcessingHook.php b/Classes/Hooks/Datahandler/CommandMapPostProcessingHook.php index abbff152..32b2e7ef 100644 --- a/Classes/Hooks/Datahandler/CommandMapPostProcessingHook.php +++ b/Classes/Hooks/Datahandler/CommandMapPostProcessingHook.php @@ -45,36 +45,34 @@ public function processCmdmap_postProcess(string $command, string $table, $id, $ $this->copyOrMoveChildren($id, (int)$value, (int)$dataHandler->copyMappingArray['tt_content'][$id], 'copy', $dataHandler); } elseif ($table === 'tt_content' && $command === 'move') { $this->copyOrMoveChildren($id, (int)$value, $id, 'move', $dataHandler); - } elseif ($table === 'tt_content' && ($command === 'localize' || $command === 'copyToLanguage')) { - $this->localizeOrCopyToLanguage($id, (int)$value, $command, $dataHandler); + } elseif ($table === 'tt_content' && $command === 'localize') { + $this->localizeChildren($id, (int)$value, $command, $dataHandler); + } elseif ($table === 'tt_content' && $command === 'copyToLanguage') { + $this->copyToLanguageChildren($id, (int)$value, $command, $dataHandler); } } - protected function localizeOrCopyToLanguage(int $uid, int $language, string $command, DataHandler $dataHandler): void + protected function copyToLanguageChildren(int $uid, int $language, string $command, DataHandler $dataHandler): void { try { $container = $this->containerFactory->buildContainer($uid); $last = $dataHandler->copyMappingArray['tt_content'][$uid] ?? null; - if ($command === 'copyToLanguage') { - $containerId = $last; - $pos = $this->containerService->getAfterContainerElementTarget($container); - // move next record after last child - $cmd = ['tt_content' => [$last => [ - 'move' => [ - 'target' => $pos, - 'action' => 'paste', - 'update' => [], - ] - ]]]; - $localDataHandler = GeneralUtility::makeInstance(DataHandler::class); - $localDataHandler->enableLogging = $dataHandler->enableLogging; - $localDataHandler->start([], $cmd, $dataHandler->BE_USER); - $localDataHandler->process_cmdmap(); - } else { - $containerId = $container->getUid(); - } + $containerId = $last; + $pos = $this->containerService->getAfterContainerElementTarget($container); + // move next record after last child + $cmd = ['tt_content' => [$last => [ + 'move' => [ + 'target' => $pos, + 'action' => 'paste', + 'update' => [], + ] + ]]]; + $localDataHandler = GeneralUtility::makeInstance(DataHandler::class); + $localDataHandler->enableLogging = $dataHandler->enableLogging; + $localDataHandler->start([], $cmd, $dataHandler->BE_USER); + $localDataHandler->process_cmdmap(); $children = $container->getChildRecords(); - foreach ($children as $colPos => $record) { + foreach ($children as $record) { $cmd = ['tt_content' => [$record['uid'] => [$command => $language]]]; $localDataHandler = GeneralUtility::makeInstance(DataHandler::class); $localDataHandler->enableLogging = $dataHandler->enableLogging; @@ -104,6 +102,23 @@ protected function localizeOrCopyToLanguage(int $uid, int $language, string $com } } + protected function localizeChildren(int $uid, int $language, string $command, DataHandler $dataHandler): void + { + try { + $container = $this->containerFactory->buildContainer($uid); + $children = $container->getChildRecords(); + foreach ($children as $record) { + $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(); + } + } catch (Exception $e) { + // nothing todo + } + } + protected function copyOrMoveChildren(int $origUid, int $newId, int $containerId, string $command, DataHandler $dataHandler): void { try { diff --git a/Tests/Functional/Datahandler/Localization/Fixtures/Localize/LocalizeNestedContainerKeepsDefaultLanguageParent.csv b/Tests/Functional/Datahandler/Localization/Fixtures/Localize/LocalizeNestedContainerKeepsDefaultLanguageParent.csv new file mode 100644 index 00000000..49ea9758 --- /dev/null +++ b/Tests/Functional/Datahandler/Localization/Fixtures/Localize/LocalizeNestedContainerKeepsDefaultLanguageParent.csv @@ -0,0 +1,9 @@ +"pages" +,"uid","pid","title","slug","sys_language_uid","l10n_parent","l10n_source" +,1,0,"page-1","/",,, +,2,0,"page-1-language-1","/",1,1,1 +"tt_content" +,"uid","pid","CType","header","sorting","sys_language_uid","colPos","tx_container_parent" +,1,1,"b13-2cols-with-header-container","container",64,0,0,0 +,2,1,"b13-2cols-with-header-container","nested-container",128,0,201,1 +,3,1,"header","child",256,0,201,2 diff --git a/Tests/Functional/Datahandler/Localization/Fixtures/Localize/LocalizeNestedContainerKeepsDefaultLanguageParentResult.csv b/Tests/Functional/Datahandler/Localization/Fixtures/Localize/LocalizeNestedContainerKeepsDefaultLanguageParentResult.csv new file mode 100644 index 00000000..469e3b99 --- /dev/null +++ b/Tests/Functional/Datahandler/Localization/Fixtures/Localize/LocalizeNestedContainerKeepsDefaultLanguageParentResult.csv @@ -0,0 +1,8 @@ +"tt_content" +,"uid","pid","CType","header","sorting","sys_language_uid","colPos","tx_container_parent" +,1,1,"b13-2cols-with-header-container","container",64,0,0,0 +,2,1,"b13-2cols-with-header-container","nested-container",128,0,201,1 +,3,1,"header","child",256,0,201,2 +,4,1,"b13-2cols-with-header-container","[Translate to german:] container",96,1,0,0 +,5,1,"b13-2cols-with-header-container","[Translate to german:] nested-container",192,1,201,1 +,6,1,"header","[Translate to german:] child",224,1,201,2 diff --git a/Tests/Functional/Datahandler/Localization/LocalizeTest.php b/Tests/Functional/Datahandler/Localization/LocalizeTest.php index 877a6425..a81398bf 100644 --- a/Tests/Functional/Datahandler/Localization/LocalizeTest.php +++ b/Tests/Functional/Datahandler/Localization/LocalizeTest.php @@ -78,6 +78,24 @@ public function localizeContainerLocalizeChildren(): void self::assertCSVDataSet(__DIR__ . '/Fixtures/Localize/LocalizeContainerLocalizeChildrenResult.csv'); } + /** + * @test + */ + public function localizeNestedContainerKeepsDefaultLanguageParent(): void + { + $this->importCSVDataSet(__DIR__ . '/Fixtures/Localize/LocalizeNestedContainerKeepsDefaultLanguageParent.csv'); + $cmdmap = [ + 'tt_content' => [ + 1 => [ + 'localize' => 1, + ], + ], + ]; + $this->dataHandler->start([], $cmdmap, $this->backendUser); + $this->dataHandler->process_cmdmap(); + self::assertCSVDataSet(__DIR__ . '/Fixtures/Localize/LocalizeNestedContainerKeepsDefaultLanguageParentResult.csv'); + } + /** * @test */