Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 37 additions & 22 deletions Classes/Hooks/Datahandler/CommandMapPostProcessingHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
18 changes: 18 additions & 0 deletions Tests/Functional/Datahandler/Localization/LocalizeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
Loading