Skip to content

Commit

Permalink
[BUGFIX] Use all available languages from all sites for permissions
Browse files Browse the repository at this point in the history
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: TYPO3com <noreply@typo3.com>
Tested-by: Riccardo De Contardi <erredeco@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
  • Loading branch information
bmack authored and maddy2101 committed Jul 5, 2019
1 parent 15932f9 commit 11398a3
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 17 deletions.
Expand Up @@ -32,6 +32,7 @@
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;
Expand Down Expand Up @@ -274,15 +275,46 @@ protected function addItemsFromSpecial(array $result, $fieldName, array $items)
}
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'];
Expand Down Expand Up @@ -1378,6 +1410,11 @@ protected function getStaticValues($itemArray, $dynamicItemArray)
return $staticValues;
}

protected function getAllSites(): array
{
return GeneralUtility::makeInstance(SiteFinder::class)->getAllSites();
}

/**
* @return LanguageService
*/
Expand Down
Expand Up @@ -36,6 +36,8 @@
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;
Expand Down Expand Up @@ -1053,23 +1055,33 @@ public function addDataAddsLanguagesWithSpecialLanguages()
],
],
],
'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,
],
];
Expand Down

0 comments on commit 11398a3

Please sign in to comment.