Skip to content

Commit 8377274

Browse files
committed
[TASK] prevent changing language fields for container children
Fixes: #499
1 parent 8d1036b commit 8377274

File tree

3 files changed

+110
-0
lines changed

3 files changed

+110
-0
lines changed

Classes/Hooks/Datahandler/DatamapBeforeStartHook.php

+44
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use B13\Container\Domain\Service\ContainerService;
1818
use B13\Container\Tca\Registry;
1919
use TYPO3\CMS\Core\DataHandling\DataHandler;
20+
use TYPO3\CMS\Core\Utility\MathUtility;
2021

2122
class DatamapBeforeStartHook
2223
{
@@ -56,6 +57,49 @@ public function processDatamap_beforeStart(DataHandler $dataHandler): void
5657
{
5758
$dataHandler->datamap = $this->datamapForChildLocalizations($dataHandler->datamap);
5859
$dataHandler->datamap = $this->datamapForChildrenChangeContainerLanguage($dataHandler->datamap);
60+
$dataHandler->datamap = $this->denyChangingOfLanguageFieldsForContainerChildren($dataHandler->datamap, $dataHandler);
61+
}
62+
63+
protected function denyChangingOfLanguageFieldsForContainerChildren(array $datamap, DataHandler $dataHandler):array
64+
{
65+
foreach ($datamap['tt_content'] ?? [] as $uid => &$datas) {
66+
if (!MathUtility::canBeInterpretedAsInteger($uid)) {
67+
continue;
68+
}
69+
if (!isset($datas['sys_language_uid']) && !isset($datas['l18n_parent'])) {
70+
continue;
71+
}
72+
$record = $this->database->fetchOneRecord((int)$uid);
73+
if ($record === null || (int)($record['tx_container_parent'] ?? 0) === 0) {
74+
continue;
75+
}
76+
if (isset($datas['sys_language_uid'])) {
77+
$dataHandler->log(
78+
'tt_content',
79+
$uid,
80+
2,
81+
0,
82+
1,
83+
'cannot change language of container child record',
84+
28
85+
);
86+
unset($datas['sys_language_uid']);
87+
}
88+
if (isset($datas['l18n_parent'])) {
89+
unset($datas['l18n_parent']);
90+
$dataHandler->log(
91+
'tt_content',
92+
$uid,
93+
2,
94+
0,
95+
1,
96+
'cannot change parent of container child record',
97+
28
98+
);
99+
}
100+
$datamap['tt_content'][$uid] = $datas;
101+
}
102+
return $datamap;
59103
}
60104

61105
protected function datamapForChildLocalizations(array $datamap): array
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace B13\Container\Tests\Functional\Datahandler\Localization\ConnectedMode;
6+
7+
/*
8+
* This file is part of TYPO3 CMS-based extension "container" by b13.
9+
*
10+
* It is free software; you can redistribute it and/or modify it under
11+
* the terms of the GNU General Public License, either version 2
12+
* of the License, or any later version.
13+
*/
14+
15+
use B13\Container\Tests\Functional\Datahandler\AbstractDatahandler;
16+
17+
class ContainerChildrenTest extends AbstractDatahandler
18+
{
19+
/**
20+
* @test
21+
*/
22+
public function cannotChangeLanguageOfTranslatedChild(): void
23+
{
24+
$this->importCSVDataSet(__DIR__ . '/Fixtures/ContainerChildren/translated_container_with_children.csv');
25+
$datamap = [
26+
'tt_content' => [
27+
22 => [
28+
'sys_language_uid' => 0,
29+
],
30+
],
31+
];
32+
$this->dataHandler->start($datamap, [], $this->backendUser);
33+
$this->dataHandler->process_datamap();
34+
self::assertCSVDataSet(__DIR__ . '/Fixtures/ContainerChildren/translated_container_with_children.csv');
35+
self::assertNotEmpty($this->dataHandler->errorLog, 'dataHander error log is empty');
36+
}
37+
38+
/**
39+
* @test
40+
*/
41+
public function cannotChangeL18nParentOfTranslatedChild(): void
42+
{
43+
$this->importCSVDataSet(__DIR__ . '/Fixtures/ContainerChildren/translated_container_with_children.csv');
44+
$datamap = [
45+
'tt_content' => [
46+
22 => [
47+
'l18n_parent' => 1,
48+
],
49+
],
50+
];
51+
$this->dataHandler->start($datamap, [], $this->backendUser);
52+
$this->dataHandler->process_datamap();
53+
self::assertCSVDataSet(__DIR__ . '/Fixtures/ContainerChildren/translated_container_with_children.csv');
54+
self::assertNotEmpty($this->dataHandler->errorLog, 'dataHander error log is empty');
55+
}
56+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
"pages"
2+
,"uid","pid","title","slug","sys_language_uid","l10n_parent","l10n_source"
3+
,1,0,"page-1","/",0,0,0
4+
,2,0,"page-1-language-1","/",1,1,1
5+
"tt_content"
6+
,"uid","pid","CType","header","sorting","sys_language_uid","colPos","tx_container_parent","l18n_parent"
7+
,1,1,"b13-2cols-with-header-container","container-default",256,0,0,0,0
8+
,2,1,"header","header-default",128,0,200,1,0
9+
,21,1,"b13-2cols-with-header-container","container-language-1",256,1,0,0,1
10+
,22,1,"header","header-language-1",128,1,200,1,2

0 commit comments

Comments
 (0)