Commit 11398a37 authored by Benni Mack's avatar Benni Mack Committed by Anja Leichsenring
Browse files

[BUGFIX] Use all available languages from all sites for permissions

Since Pseudo-Sites have been removed,
sys_language is not the recommended way
anymore to detect available languages.

It is however possible to use all site
configurations to select a language to
limit the language to a backend user / group
with proper labels now.

Resolves: #88659
Releases: master
Change-Id: Ifbbaba28897eb06e5d574742a1094c90b03ba8f3
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/61199

Tested-by: default avatarTYPO3com <noreply@typo3.com>
Tested-by: Riccardo De Contardi's avatarRiccardo De Contardi <erredeco@gmail.com>
Tested-by: Georg Ringer's avatarGeorg Ringer <georg.ringer@gmail.com>
Tested-by: Andreas Fernandez's avatarAndreas Fernandez <a.fernandez@scripting-base.de>
Tested-by: Anja Leichsenring's avatarAnja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Georg Ringer's avatarGeorg Ringer <georg.ringer@gmail.com>
Reviewed-by: Andreas Fernandez's avatarAndreas Fernandez <a.fernandez@scripting-base.de>
Reviewed-by: Anja Leichsenring's avatarAnja Leichsenring <aleichsenring@ab-softlab.de>
parent 15932f95
......@@ -32,6 +32,7 @@ use TYPO3\CMS\Core\Messaging\FlashMessage;
use TYPO3\CMS\Core\Messaging\FlashMessageQueue;
use TYPO3\CMS\Core\Messaging\FlashMessageService;
use TYPO3\CMS\Core\Resource\FileRepository;
use TYPO3\CMS\Core\Site\SiteFinder;
use TYPO3\CMS\Core\Type\Bitmask\Permission;
use TYPO3\CMS\Core\Utility\ArrayUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
......@@ -274,15 +275,46 @@ abstract class AbstractItemProvider
}
break;
case $special === 'languages':
foreach ($result['systemLanguageRows'] as $language) {
if ($language['uid'] !== -1) {
$items[] = [
0 => $language['title'],
1 => $language['uid'],
2 => $language['flagIconIdentifier']
];
$allLanguages = [];
if (($result['effectivePid'] ?? 0) === 0) {
// This provides a list of all languages available for ALL sites
// Due to the nature of the "sys_language_uid" field having no meaning currently,
// We preserve the language ID and make a list of all languages
$sites = $this->getAllSites();
foreach ($sites as $site) {
foreach ($site->getAllLanguages() as $language) {
$languageId = $language->getLanguageId();
if (isset($allLanguages[$languageId])) {
// Language already provided by another site, just add the label separately
$allLanguages[$languageId][0] .= ', ' . $language->getTitle() . ' [Site: ' . $site->getIdentifier() . ']';
} else {
$allLanguages[$languageId] = [
0 => $language->getTitle() . ' [Site: ' . $site->getIdentifier() . ']',
1 => $languageId,
2 => $language->getFlagIdentifier()
];
}
}
}
ksort($allLanguages);
}
if (!empty($allLanguages)) {
foreach ($allLanguages as $item) {
$items[] = $item;
}
} else {
// Happens for non-pid=0 records (e.g. "tt_content"), or when no site was configured
foreach ($result['systemLanguageRows'] as $language) {
if ($language['uid'] !== -1) {
$items[] = [
0 => $language['title'],
1 => $language['uid'],
2 => $language['flagIconIdentifier']
];
}
}
}
break;
case $special === 'custom':
$customOptions = $GLOBALS['TYPO3_CONF_VARS']['BE']['customPermOptions'];
......@@ -1378,6 +1410,11 @@ abstract class AbstractItemProvider
return $staticValues;
}
protected function getAllSites(): array
{
return GeneralUtility::makeInstance(SiteFinder::class)->getAllSites();
}
/**
* @return LanguageService
*/
......
......@@ -36,6 +36,8 @@ use TYPO3\CMS\Core\Messaging\FlashMessage;
use TYPO3\CMS\Core\Messaging\FlashMessageQueue;
use TYPO3\CMS\Core\Messaging\FlashMessageService;
use TYPO3\CMS\Core\Resource\FileRepository;
use TYPO3\CMS\Core\Site\Entity\Site;
use TYPO3\CMS\Core\Site\SiteFinder;
use TYPO3\CMS\Core\Utility\ArrayUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
......@@ -1053,23 +1055,33 @@ class TcaSelectItemsTest extends UnitTestCase
],
],
],
'systemLanguageRows' => [
0 => [
'title' => 'aLangTitle',
'uid' => 42,
'flagIconIdentifier' => 'aFlag.gif',
],
],
];
$iconFactoryProphecy = $this->prophesize(IconRegistry::class);
GeneralUtility::setSingletonInstance(IconRegistry::class, $iconFactoryProphecy->reveal());
$siteFinder = $this->prophesize(SiteFinder::class);
$siteFinder->getAllSites()->willReturn([
new Site('test', 13, [
'base' => '/',
'languages' => [
[
'title' => 'French',
'languageId' => 13,
'base' => '/fr/',
'locale' => 'fr_FR',
'flag' => 'aFlag.gif'
]
]
])
]);
GeneralUtility::addInstance(SiteFinder::class, $siteFinder->reveal());
$expectedItems = [
0 => [
0 => 'aLangTitle',
1 => 42,
2 => 'aFlag.gif',
0 => 'French [Site: test]',
1 => 13,
2 => 'flags-aFlag.gif',
3 => null,
],
];
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment