‪TYPO3CMS  11.5
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 
25 
31 {
33 
35  {
36  $this->locales = ‪$locales;
37  }
38 
42  public function ‪populateAvailableSystemLanguagesForBackend(array &$fieldInformation): void
43  {
44  $languageItems = $this->locales->getLanguages();
45  unset($languageItems['default']);
46  asort($languageItems);
47  $installedLanguages = ‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['lang']['availableLanguages'] ?? [];
48  $availableLanguages = [];
49  $unavailableLanguages = [];
50  foreach ($languageItems as $typo3Language => $name) {
51  $available = in_array($typo3Language, $installedLanguages, true) || is_dir(‪Environment::getLabelsPath() . '/' . $typo3Language);
52  if ($available) {
53  $availableLanguages[] = [$name, $typo3Language, '', 'installed'];
54  } else {
55  $unavailableLanguages[] = [$name, $typo3Language, '', 'unavailable'];
56  }
57  }
58 
59  // Ensure ordering of the items
60  $fieldInformation['items'] = array_merge($fieldInformation['items'], $availableLanguages);
61  $fieldInformation['items'] = array_merge($fieldInformation['items'], $unavailableLanguages);
62  }
63 
71  public function ‪populateAvailableSiteLanguages(array &$fieldInformation): void
72  {
73  $allLanguages = [];
74  foreach ($this->‪getAllSites() as $site) {
75  foreach ($site->getAllLanguages() as $language) {
76  $languageId = $language->getLanguageId();
77  if (isset($allLanguages[$languageId])) {
78  // Language already provided by another site, just add the label separately
79  $allLanguages[$languageId][0] .= ', ' . $language->getTitle() . ' [Site: ' . $site->getIdentifier() . ']';
80  continue;
81  }
82  $allLanguages[$languageId] = [
83  0 => $language->getTitle() . ' [Site: ' . $site->getIdentifier() . ']',
84  1 => $languageId,
85  2 => $language->getFlagIdentifier(),
86  ];
87  }
88  }
89 
90  if ($allLanguages !== []) {
91  ksort($allLanguages);
92  foreach ($allLanguages as $item) {
93  $fieldInformation['items'][] = $item;
94  }
95  return;
96  }
97 
98  // Fallback if no site configuration exists
99  $recordPid = (int)($fieldInformation['row']['pid'] ?? 0);
100  $languages = (new ‪NullSite())->getAvailableLanguages($this->‪getBackendUser(), false, $recordPid);
101 
102  foreach ($languages as $languageId => $language) {
103  $fieldInformation['items'][] = [
104  0 => $language->getTitle(),
105  1 => $languageId,
106  2 => $language->getFlagIdentifier(),
107  ];
108  }
109  }
110 
111  protected function ‪getAllSites(): array
112  {
113  return GeneralUtility::makeInstance(SiteFinder::class)->getAllSites();
114  }
115 
117  {
118  return ‪$GLOBALS['BE_USER'];
119  }
120 }
‪TYPO3\CMS\Core\Core\Environment\getLabelsPath
‪static string getLabelsPath()
Definition: Environment.php:262
‪TYPO3\CMS\Core\Localization\TcaSystemLanguageCollector\populateAvailableSystemLanguagesForBackend
‪populateAvailableSystemLanguagesForBackend(array &$fieldInformation)
Definition: TcaSystemLanguageCollector.php:42
‪TYPO3\CMS\Core\Localization\TcaSystemLanguageCollector\populateAvailableSiteLanguages
‪populateAvailableSiteLanguages(array &$fieldInformation)
Definition: TcaSystemLanguageCollector.php:71
‪TYPO3\CMS\Core\Localization\TcaSystemLanguageCollector\getBackendUser
‪getBackendUser()
Definition: TcaSystemLanguageCollector.php:116
‪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:30
‪TYPO3\CMS\Core\Localization\TcaSystemLanguageCollector\getAllSites
‪getAllSites()
Definition: TcaSystemLanguageCollector.php:111
‪TYPO3\CMS\Core\Localization
Definition: CacheWarmer.php:18
‪TYPO3\CMS\Core\Localization\TcaSystemLanguageCollector
Definition: TcaSystemLanguageCollector.php:31
‪TYPO3\CMS\Core\Localization\TcaSystemLanguageCollector\$locales
‪Locales $locales
Definition: TcaSystemLanguageCollector.php:32
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Core\Localization\TcaSystemLanguageCollector\__construct
‪__construct(Locales $locales)
Definition: TcaSystemLanguageCollector.php:34
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:43
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50