‪TYPO3CMS  9.5
NullSite.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
3 
5 
6 /*
7  * This file is part of the TYPO3 CMS project.
8  *
9  * It is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License, either version 2
11  * of the License, or any later version.
12  *
13  * For the full copyright and license information, please read the
14  * LICENSE.txt file that was distributed with this source code.
15  *
16  * The TYPO3 project - inspiring people to share!
17  */
18 
19 use Psr\Http\Message\UriInterface;
26 
30 class ‪NullSite implements ‪SiteInterface
31 {
35  protected ‪$rootPageId = 0;
36 
40  protected ‪$languages;
41 
48  public function ‪__construct(array ‪$languages = null, ‪Uri $baseEntryPoint = null)
49  {
50  foreach (‪$languages ?? [] as $languageConfiguration) {
51  $languageUid = (int)$languageConfiguration['languageId'];
52  // Language configuration does not have a base defined
53  // So the main site base is used (usually done for default languages)
54  $this->languages[$languageUid] = new ‪SiteLanguage(
55  $languageUid,
56  $languageConfiguration['locale'] ?? '',
57  $baseEntryPoint ?: new ‪Uri('/'),
58  $languageConfiguration
59  );
60  }
61  }
62 
68  public function ‪getIdentifier(): string
69  {
70  return '#NULL';
71  }
72 
76  public function ‪getBase(): UriInterface
77  {
78  return new ‪Uri('/');
79  }
80 
86  public function ‪getRootPageId(): int
87  {
88  return 0;
89  }
90 
96  public function ‪getLanguages(): array
97  {
98  return ‪$this->languages;
99  }
100 
108  public function ‪getLanguageById(int $languageId): ‪SiteLanguage
109  {
110  if (isset($this->languages[$languageId])) {
111  return $this->languages[$languageId];
112  }
113  throw new \InvalidArgumentException(
114  'Language ' . $languageId . ' does not exist on site ' . $this->‪getIdentifier() . '.',
115  1522965188
116  );
117  }
118 
122  public function ‪getDefaultLanguage(): ‪SiteLanguage
123  {
124  return reset($this->languages);
125  }
126 
133  public function ‪getAvailableLanguages(‪BackendUserAuthentication $user, bool $includeAllLanguagesFlag = false, int $pageId = null): array
134  {
135  $availableLanguages = [];
136 
137  // Check if we need to add language "-1"
138  if ($includeAllLanguagesFlag && $user->‪checkLanguageAccess(-1)) {
139  $availableLanguages[-1] = new ‪SiteLanguage(-1, '', $this->‪getBase(), [
140  'title' => $this->‪getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_mod_web_list.xlf:multipleLanguages'),
141  'flag' => 'flags-multiple'
142  ]);
143  }
144  $pageTs = ‪BackendUtility::getPagesTSconfig($pageId);
145  $pageTs = $pageTs['mod.']['SHARED.'] ?? [];
146 
147  $disabledLanguages = GeneralUtility::intExplode(',', $pageTs['disableLanguages'] ?? '', true);
148  // Do not add the ones that are not allowed by the user
149  foreach ($this->languages as $language) {
150  if ($user->‪checkLanguageAccess($language->getLanguageId()) && !in_array($language->getLanguageId(), $disabledLanguages, true)) {
151  if ($language->getLanguageId() === 0) {
152  // 0: "Default" language
153  $defaultLanguageLabel = 'LLL:EXT:core/Resources/Private/Language/locallang_mod_web_list.xlf:defaultLanguage';
154  $defaultLanguageLabel = $this->‪getLanguageService()->‪sL($defaultLanguageLabel);
155  if (isset($pageTs['defaultLanguageLabel'])) {
156  $defaultLanguageLabel = $pageTs['defaultLanguageLabel'] . ' (' . $defaultLanguageLabel . ')';
157  }
158  $defaultLanguageFlag = '';
159  if (isset($pageTs['defaultLanguageFlag'])) {
160  $defaultLanguageFlag = 'flags-' . $pageTs['defaultLanguageFlag'];
161  }
162  $language = new ‪SiteLanguage(0, '', $language->getBase(), [
163  'title' => $defaultLanguageLabel,
164  'flag' => $defaultLanguageFlag,
165  ]);
166  }
167  $availableLanguages[$language->getLanguageId()] = $language;
168  }
169  }
170 
171  return $availableLanguages;
172  }
173 
181  public function ‪getErrorHandler(int $statusCode): ‪PageErrorHandlerInterface
182  {
183  throw new \RuntimeException('No error handler given for the status code "' . $statusCode . '".', 1522495102);
184  }
185 
190  protected function ‪getLanguageService(): ‪LanguageService
191  {
192  return ‪$GLOBALS['LANG'];
193  }
194 }
‪TYPO3\CMS\Core\Site\Entity\SiteInterface
Definition: SiteInterface.php:25
‪TYPO3\CMS\Core\Site\Entity\NullSite\getBase
‪getBase()
Definition: NullSite.php:74
‪TYPO3\CMS\Core\Site\Entity\NullSite\getErrorHandler
‪PageErrorHandlerInterface getErrorHandler(int $statusCode)
Definition: NullSite.php:179
‪TYPO3\CMS\Core\Site\Entity\NullSite\getDefaultLanguage
‪getDefaultLanguage()
Definition: NullSite.php:120
‪TYPO3\CMS\Core\Site\Entity\NullSite
Definition: NullSite.php:31
‪TYPO3\CMS\Core\Site\Entity\NullSite\getLanguageById
‪SiteLanguage getLanguageById(int $languageId)
Definition: NullSite.php:106
‪TYPO3\CMS\Core\Site\Entity\NullSite\getIdentifier
‪string getIdentifier()
Definition: NullSite.php:66
‪TYPO3\CMS\Core\Localization\LanguageService\sL
‪string sL($input)
Definition: LanguageService.php:158
‪TYPO3\CMS\Core\Site\Entity\NullSite\getRootPageId
‪int getRootPageId()
Definition: NullSite.php:84
‪TYPO3\CMS\Core\Site\Entity\NullSite\getAvailableLanguages
‪getAvailableLanguages(BackendUserAuthentication $user, bool $includeAllLanguagesFlag=false, int $pageId=null)
Definition: NullSite.php:131
‪TYPO3\CMS\Core\Http\Uri
Definition: Uri.php:27
‪TYPO3\CMS\Core\Site\Entity\SiteLanguage
Definition: SiteLanguage.php:25
‪TYPO3\CMS\Core\Site\Entity\NullSite\getLanguageService
‪LanguageService getLanguageService()
Definition: NullSite.php:188
‪TYPO3\CMS\Core\Site\Entity\NullSite\getLanguages
‪SiteLanguage[] getLanguages()
Definition: NullSite.php:94
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\checkLanguageAccess
‪bool checkLanguageAccess($langValue)
Definition: BackendUserAuthentication.php:733
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:45
‪TYPO3\CMS\Backend\Utility\BackendUtility
Definition: BackendUtility.php:72
‪TYPO3\CMS\Core\Error\PageErrorHandler\PageErrorHandlerInterface
Definition: PageErrorHandlerInterface.php:28
‪TYPO3\CMS\Core\Site\Entity
Definition: NullSite.php:4
‪TYPO3\CMS\Core\Site\Entity\NullSite\$languages
‪SiteLanguage[] $languages
Definition: NullSite.php:38
‪TYPO3\CMS\Backend\Utility\BackendUtility\getPagesTSconfig
‪static array getPagesTSconfig($id, $rootLine=null, $returnPartArray=false)
Definition: BackendUtility.php:864
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Site\Entity\NullSite\$rootPageId
‪int $rootPageId
Definition: NullSite.php:34
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:29
‪TYPO3\CMS\Core\Site\Entity\NullSite\__construct
‪__construct(array $languages=null, Uri $baseEntryPoint=null)
Definition: NullSite.php:46
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45