‪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  }
35 
39  public function ‪populateAvailableSystemLanguagesForBackend(array &$fieldInformation): void
40  {
41  $languageItems = $this->locales->getLanguages();
42  $availableLanguages = [];
43  $unavailableLanguages = [];
44  foreach ($languageItems as $languageKey => $name) {
45  if ($this->locales->isLanguageKeyAvailable($languageKey)) {
46  $availableLanguages[] = ['label' => $name, 'value' => $languageKey, 'group' => 'installed'];
47  } else {
48  $unavailableLanguages[] = ['label' => $name, 'value' => $languageKey, 'group' => 'unavailable'];
49  }
50  }
51 
52  // Ensure ordering of the items
53  $fieldInformation['items'] = array_merge($availableLanguages, $unavailableLanguages);
54  }
55 
63  public function ‪populateAvailableSiteLanguages(array &$fieldInformation): void
64  {
65  $allLanguages = [];
66  foreach ($this->‪getAllSites() as $site) {
67  foreach ($site->getAllLanguages() as $language) {
68  $languageId = $language->getLanguageId();
69  if (isset($allLanguages[$languageId])) {
70  // Language already provided by another site, just add the label separately
71  $allLanguages[$languageId]['label'] .= ', ' . $language->getTitle() . ' [Site: ' . $site->getIdentifier() . ']';
72  continue;
73  }
74  $allLanguages[$languageId] = [
75  'label' => $language->getTitle() . ' [Site: ' . $site->getIdentifier() . ']',
76  'value' => $languageId,
77  'icon' => $language->getFlagIdentifier(),
78  ];
79  }
80  }
81 
82  if ($allLanguages !== []) {
83  ksort($allLanguages);
84  foreach ($allLanguages as $item) {
85  $fieldInformation['items'][] = $item;
86  }
87  return;
88  }
89 
90  // Fallback if no site configuration exists
91  $recordPid = (int)($fieldInformation['row']['pid'] ?? 0);
92  ‪$languages = (new ‪NullSite())->getAvailableLanguages($this->‪getBackendUser(), false, $recordPid);
93 
94  foreach (‪$languages as $languageId => $language) {
95  $fieldInformation['items'][] = [
96  'label' => $language->getTitle(),
97  'value' => $languageId,
98  'icon' => $language->getFlagIdentifier(),
99  ];
100  }
101  }
102 
103  protected function ‪getAllSites(): array
104  {
105  return GeneralUtility::makeInstance(SiteFinder::class)->getAllSites();
106  }
107 
109  {
110  return ‪$GLOBALS['BE_USER'];
111  }
112 }
‪TYPO3\CMS\Core\Localization\TcaSystemLanguageCollector\populateAvailableSystemLanguagesForBackend
‪populateAvailableSystemLanguagesForBackend(array &$fieldInformation)
Definition: TcaSystemLanguageCollector.php:39
‪TYPO3\CMS\Core\Localization\TcaSystemLanguageCollector\populateAvailableSiteLanguages
‪populateAvailableSiteLanguages(array &$fieldInformation)
Definition: TcaSystemLanguageCollector.php:63
‪$languages
‪$languages
Definition: updateIsoDatabase.php:104
‪TYPO3\CMS\Core\Localization\TcaSystemLanguageCollector\getBackendUser
‪getBackendUser()
Definition: TcaSystemLanguageCollector.php:108
‪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:33
‪TYPO3\CMS\Core\Localization\TcaSystemLanguageCollector\getAllSites
‪getAllSites()
Definition: TcaSystemLanguageCollector.php:103
‪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:64
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:51