Skip to content

Commit

Permalink
[BUGFIX] Keep existing baseVariants for site languages
Browse files Browse the repository at this point in the history
The backend UI does not support handling of baseVariants
for languages, however it is possible to define them
in the config.yaml of a site configuration.

However, when editing and saving a site, the baseVariants
manually defined were removed. This has now been changed,
as the baseVariants are kept when persisting
the site configuratino via the UI.

Resolves: #93719
Releases: main, 11.5
Change-Id: I8a0b3be72ddfab46da59b3f8a69ad16121c7246b
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/76460
Tested-by: core-ci <typo3@b13.com>
Tested-by: Stefan Bürk <stefan@buerk.tech>
Tested-by: Oliver Bartsch <bo@cedev.de>
Tested-by: Benni Mack <benni@typo3.org>
Reviewed-by: Stefan Bürk <stefan@buerk.tech>
Reviewed-by: Oliver Bartsch <bo@cedev.de>
Reviewed-by: Benni Mack <benni@typo3.org>
  • Loading branch information
bmack committed Nov 9, 2022
1 parent adc8b44 commit 29f3d83
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 6 deletions.
Expand Up @@ -390,12 +390,9 @@ protected function saveAction(ServerRequestInterface $request): ResponseInterfac
}
}

// keep root config objects not given via GUI
// this way extension authors are able to use their own objects on root level
// that are not configurable via GUI
// however: we overwrite the full subset of any GUI object to make sure we have a clean state
$newSysSiteData = array_merge($currentSiteConfiguration, $newSysSiteData);
$newSiteConfiguration = $this->validateFullStructure($newSysSiteData);
$newSiteConfiguration = $this->validateFullStructure(
$this->getMergeSiteData($currentSiteConfiguration, $newSysSiteData)
);

// Persist the configuration
$siteConfigurationManager = GeneralUtility::makeInstance(SiteConfiguration::class);
Expand Down Expand Up @@ -808,6 +805,35 @@ protected function validateValueForRequired(array $tcaFieldConfig, mixed $value)
return !empty($value) || $value === '0';
}

/**
* Method keeps root config objects, which are not given via GUI. This way,
* extension authors are able to use their own objects on root level that are
* not configurable via GUI. However: We overwrite the full subset of any GUI
* object to make sure we have a clean state.
*
* Additionally, we also keep the baseVariants of languages, since they
* can't be modified via the GUI, but are part of the public API.
*/
protected function getMergeSiteData(array $currentSiteConfiguration, array $newSysSiteData): array
{
$newSysSiteData = array_merge($currentSiteConfiguration, $newSysSiteData);

// @todo: this should go away, once base variants for languages are managable via the GUI.
$existingLanguageConfigurationsWithBaseVariants = [];
foreach ($currentSiteConfiguration['languages'] ?? [] as $languageConfiguration) {
if (isset($languageConfiguration['baseVariants'])) {
$existingLanguageConfigurationsWithBaseVariants[$languageConfiguration['languageId']] = $languageConfiguration['baseVariants'];
}
}
foreach ($newSysSiteData['languages'] ?? [] as $key => $languageConfiguration) {
if (isset($existingLanguageConfigurationsWithBaseVariants[$languageConfiguration['languageId']])) {
$newSysSiteData['languages'][$key]['baseVariants'] = $existingLanguageConfigurationsWithBaseVariants[$languageConfiguration['languageId']];
}
}

return $newSysSiteData;
}

protected function getLanguageService(): LanguageService
{
return $GLOBALS['LANG'];
Expand Down
Expand Up @@ -126,4 +126,57 @@ public function duplicateEntryPointsAreRecognized(): void

self::assertEquals($expected, $mockedSiteConfigurationController->_call('getDuplicatedEntryPoints', $sites, $rootPages));
}

/**
* @test
*/
public function languageBaseVariantsAreKept(): void
{
$mockedSiteConfigurationController = $this->getAccessibleMock(SiteConfigurationController::class, ['dummy'], [], '', false);

$currentSiteConfig = [
'base' => '//domain1.tld/',
'websiteTitle' => 'domain1',
'languages' => [
0 => [
'languageId' => 0,
'title' => 'English',
'base' => '/',
'baseVariants' => [
[
'base' => '/en',
],
],
],
],
];

$newSiteConfig = $currentSiteConfig;
$newSiteConfig['rootPageId'] = 123;
$newSiteConfig['websiteTitle'] = 'domain1 renamed';
unset($newSiteConfig['languages'][0]['baseVariants']);

$expected = [
'base' => '//domain1.tld/',
'rootPageId' => 123,
'websiteTitle' => 'domain1 renamed',
'languages' => [
0 => [
'languageId' => 0,
'title' => 'English',
'base' => '/',
'baseVariants' => [
[
'base' => '/en',
],
],
],
],
];

self::assertEquals(
$expected,
$mockedSiteConfigurationController->_call('getMergeSiteData', $currentSiteConfig, $newSiteConfig)
);
}
}

0 comments on commit 29f3d83

Please sign in to comment.