‪TYPO3CMS  ‪main
TcaSystemLanguageCollector.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
24 
30 {
31  public function ‪__construct(
32  private readonly ‪Locales $locales
33  ) {}
34 
38  public function ‪populateAvailableSystemLanguagesForBackend(array &$fieldInformation): void
39  {
40  $languageItems = $this->locales->getLanguages();
41  $availableLanguages = [];
42  $unavailableLanguages = [];
43  foreach ($languageItems as $languageKey => $name) {
44  if ($this->locales->isLanguageKeyAvailable($languageKey)) {
45  $availableLanguages[] = ['label' => $name, 'value' => $languageKey, 'group' => 'installed'];
46  } else {
47  $unavailableLanguages[] = ['label' => $name, 'value' => $languageKey, 'group' => 'unavailable'];
48  }
49  }
50 
51  // Ensure ordering of the items
52  $fieldInformation['items'] = array_merge($availableLanguages, $unavailableLanguages);
53  }
54 
62  public function ‪populateAvailableSiteLanguages(array &$fieldInformation): void
63  {
64  $allLanguages = [];
65  foreach ($this->‪getAllSites() as $site) {
66  foreach ($site->getAllLanguages() as $language) {
67  $languageId = $language->getLanguageId();
68  if (isset($allLanguages[$languageId])) {
69  // Language already provided by another site, just add the label separately
70  $allLanguages[$languageId]['label'] .= ', ' . $language->getTitle() . ' [Site: ' . $site->getIdentifier() . ']';
71  continue;
72  }
73  $allLanguages[$languageId] = [
74  'label' => $language->getTitle() . ' [Site: ' . $site->getIdentifier() . ']',
75  'value' => $languageId,
76  'icon' => $language->getFlagIdentifier(),
77  ];
78  }
79  }
80 
81  if ($allLanguages !== []) {
82  ksort($allLanguages);
83  foreach ($allLanguages as $item) {
84  $fieldInformation['items'][] = $item;
85  }
86  return;
87  }
88 
89  // Fallback if no site configuration exists
90  $recordPid = (int)($fieldInformation['row']['pid'] ?? 0);
91  ‪$languages = (new ‪NullSite())->getAvailableLanguages($this->‪getBackendUser(), false, $recordPid);
92 
93  foreach (‪$languages as $languageId => $language) {
94  $fieldInformation['items'][] = [
95  'label' => $language->getTitle(),
96  'value' => $languageId,
97  'icon' => $language->getFlagIdentifier(),
98  ];
99  }
100  }
101 
102  protected function ‪getAllSites(): array
103  {
104  return GeneralUtility::makeInstance(SiteFinder::class)->getAllSites();
105  }
106 
108  {
109  return ‪$GLOBALS['BE_USER'];
110  }
111 }
‪TYPO3\CMS\Core\Localization\TcaSystemLanguageCollector\populateAvailableSystemLanguagesForBackend
‪populateAvailableSystemLanguagesForBackend(array &$fieldInformation)
Definition: TcaSystemLanguageCollector.php:38
‪TYPO3\CMS\Core\Localization\TcaSystemLanguageCollector\populateAvailableSiteLanguages
‪populateAvailableSiteLanguages(array &$fieldInformation)
Definition: TcaSystemLanguageCollector.php:62
‪$languages
‪$languages
Definition: updateIsoDatabase.php:104
‪TYPO3\CMS\Core\Localization\TcaSystemLanguageCollector\getBackendUser
‪getBackendUser()
Definition: TcaSystemLanguageCollector.php:107
‪TYPO3\CMS\Core\Site\Entity\NullSite
Definition: NullSite.php:32
‪TYPO3\CMS\Core\Site\SiteFinder
Definition: SiteFinder.php:31
‪TYPO3\CMS\Core\Localization\Locales
Definition: Locales.php:36
‪TYPO3\CMS\Core\Localization\TcaSystemLanguageCollector\getAllSites
‪getAllSites()
Definition: TcaSystemLanguageCollector.php:102
‪TYPO3\CMS\Core\Localization
Definition: CacheWarmer.php:18
‪TYPO3\CMS\Core\Localization\TcaSystemLanguageCollector
Definition: TcaSystemLanguageCollector.php:30
‪TYPO3\CMS\Core\Localization\TcaSystemLanguageCollector\__construct
‪__construct(private readonly Locales $locales)
Definition: TcaSystemLanguageCollector.php:31
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52