‪TYPO3CMS  ‪main
NullSite.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 
20 use Psr\Http\Message\UriInterface;
21 use TYPO3\CMS\Backend\Utility\BackendUtility;
27 
31 class ‪NullSite implements ‪SiteInterface
32 {
36  protected ‪$rootPageId = 0;
37 
41  protected ‪$languages;
42 
49  public function ‪__construct(array ‪$languages = null, ‪Uri $baseEntryPoint = null)
50  {
51  if (empty(‪$languages)) {
52  // Create the default language if no language configuration is given
53  $this->languages[0] = new ‪SiteLanguage(
54  0,
55  '',
56  new ‪Uri('/'),
57  ['enabled' => true]
58  );
59  } else {
60  foreach (‪$languages ?? [] as $languageConfiguration) {
61  $languageUid = (int)$languageConfiguration['languageId'];
62  // Language configuration does not have a base defined
63  // So the main site base is used (usually done for default languages)
64  $this->languages[$languageUid] = new ‪SiteLanguage(
65  $languageUid,
66  $languageConfiguration['locale'] ?? '',
67  $baseEntryPoint ?: new ‪Uri('/'),
68  $languageConfiguration
69  );
70  }
71  }
72  }
73 
77  public function ‪getIdentifier(): string
78  {
79  return '#NULL';
80  }
81 
85  public function ‪getBase(): UriInterface
86  {
87  return new ‪Uri('/');
88  }
89 
93  public function ‪getRootPageId(): int
94  {
95  return 0;
96  }
97 
103  public function ‪getLanguages(): array
104  {
105  return ‪$this->languages;
106  }
107 
113  public function ‪getLanguageById(int $languageId): ‪SiteLanguage
114  {
115  if (isset($this->languages[$languageId])) {
116  return $this->languages[$languageId];
117  }
118  throw new \InvalidArgumentException(
119  'Language ' . $languageId . ' does not exist on site ' . $this->‪getIdentifier() . '.',
120  1522965188
121  );
122  }
123 
124  public function ‪getDefaultLanguage(): ‪SiteLanguage
125  {
126  return reset($this->languages);
127  }
128 
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((int)$pageId);
145  $pageTs = $pageTs['mod.']['SHARED.'] ?? [];
146 
147  $disabledLanguages = GeneralUtility::intExplode(',', (string)($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 
179  public function ‪getErrorHandler(int ‪$statusCode): PageErrorHandlerInterface
180  {
181  throw new \RuntimeException('No error handler given for the status code "' . ‪$statusCode . '".', 1522495102);
182  }
183 
184  protected function ‪getLanguageService(): ‪LanguageService
185  {
186  return ‪$GLOBALS['LANG'];
187  }
188 }
‪TYPO3\CMS\Core\Site\Entity\NullSite\getRootPageId
‪getRootPageId()
Definition: NullSite.php:91
‪TYPO3\CMS\Core\Site\Entity\SiteInterface
Definition: SiteInterface.php:26
‪TYPO3\CMS\Core\Site\Entity\NullSite\getBase
‪getBase()
Definition: NullSite.php:83
‪TYPO3\CMS\Core\Site\Entity\NullSite\getDefaultLanguage
‪getDefaultLanguage()
Definition: NullSite.php:122
‪TYPO3\CMS\Core\Site\Entity\NullSite
Definition: NullSite.php:32
‪TYPO3\CMS\Core\Site\Entity\NullSite\getLanguageService
‪getLanguageService()
Definition: NullSite.php:182
‪TYPO3\CMS\Core\Site\Entity\NullSite\getLanguageById
‪getLanguageById(int $languageId)
Definition: NullSite.php:111
‪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:30
‪TYPO3\CMS\Core\Site\Entity\NullSite\getErrorHandler
‪getErrorHandler(int $statusCode)
Definition: NullSite.php:177
‪TYPO3\CMS\Core\Site\Entity\SiteLanguage
Definition: SiteLanguage.php:27
‪TYPO3\CMS\Redirects\Message\$statusCode
‪identifier readonly UriInterface readonly int $statusCode
Definition: RedirectWasHitMessage.php:34
‪TYPO3\CMS\Core\Site\Entity\NullSite\getLanguages
‪SiteLanguage[] getLanguages()
Definition: NullSite.php:101
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\checkLanguageAccess
‪bool checkLanguageAccess($langValue)
Definition: BackendUserAuthentication.php:565
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:64
‪TYPO3\CMS\Core\Site\Entity\NullSite\getIdentifier
‪getIdentifier()
Definition: NullSite.php:75
‪TYPO3\CMS\Core\Error\PageErrorHandler\PageErrorHandlerInterface
Definition: PageErrorHandlerInterface.php:29
‪TYPO3\CMS\Core\Site\Entity
Definition: NullSite.php:18
‪TYPO3\CMS\Core\Site\Entity\NullSite\$languages
‪SiteLanguage[] $languages
Definition: NullSite.php:39
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Site\Entity\NullSite\$rootPageId
‪int $rootPageId
Definition: NullSite.php:35
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:46
‪TYPO3\CMS\Core\Site\Entity\NullSite\__construct
‪__construct(array $languages=null, Uri $baseEntryPoint=null)
Definition: NullSite.php:47
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:51