‪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 {
33  protected int ‪$rootPageId = 0;
34 
38  protected array ‪$languages;
39 
46  public function ‪__construct(array ‪$languages = null, ‪Uri $baseEntryPoint = null)
47  {
48  if (empty(‪$languages)) {
49  // Create the default language if no language configuration is given
50  $this->languages[0] = new ‪SiteLanguage(
51  0,
52  '',
53  new ‪Uri('/'),
54  ['enabled' => true]
55  );
56  } else {
57  foreach (‪$languages as $languageConfiguration) {
58  $languageUid = (int)$languageConfiguration['languageId'];
59  // Language configuration does not have a base defined
60  // So the main site base is used (usually done for default languages)
61  $this->languages[$languageUid] = new ‪SiteLanguage(
62  $languageUid,
63  $languageConfiguration['locale'] ?? '',
64  $baseEntryPoint ?: new ‪Uri('/'),
65  $languageConfiguration
66  );
67  }
68  }
69  }
70 
74  public function ‪getIdentifier(): string
75  {
76  return '#NULL';
77  }
78 
82  public function ‪getBase(): UriInterface
83  {
84  return new ‪Uri('/');
85  }
86 
90  public function ‪getRootPageId(): int
91  {
92  return 0;
93  }
94 
100  public function ‪getLanguages(): array
101  {
102  return ‪$this->languages;
103  }
104 
110  public function ‪getLanguageById(int $languageId): ‪SiteLanguage
111  {
112  if (isset($this->languages[$languageId])) {
113  return $this->languages[$languageId];
114  }
115  throw new \InvalidArgumentException(
116  'Language ' . $languageId . ' does not exist on site ' . $this->‪getIdentifier() . '.',
117  1522965188
118  );
119  }
120 
122  {
123  return reset($this->languages);
124  }
125 
130  public function ‪getAvailableLanguages(‪BackendUserAuthentication $user, bool $includeAllLanguagesFlag = false, int $pageId = null): array
131  {
132  $availableLanguages = [];
133 
134  // Check if we need to add language "-1"
135  if ($includeAllLanguagesFlag && $user->‪checkLanguageAccess(-1)) {
136  $availableLanguages[-1] = new ‪SiteLanguage(-1, '', $this->‪getBase(), [
137  'title' => $this->‪getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_mod_web_list.xlf:multipleLanguages'),
138  'flag' => 'flags-multiple',
139  ]);
140  }
141  $pageTs = BackendUtility::getPagesTSconfig((int)$pageId);
142  $pageTs = $pageTs['mod.']['SHARED.'] ?? [];
143 
144  $disabledLanguages = ‪GeneralUtility::intExplode(',', (string)($pageTs['disableLanguages'] ?? ''), true);
145  // Do not add the ones that are not allowed by the user
146  foreach ($this->languages as $language) {
147  if ($user->‪checkLanguageAccess($language) && !in_array($language->getLanguageId(), $disabledLanguages, true)) {
148  if ($language->getLanguageId() === 0) {
149  // 0: "Default" language
150  $defaultLanguageLabel = 'LLL:EXT:core/Resources/Private/Language/locallang_mod_web_list.xlf:defaultLanguage';
151  $defaultLanguageLabel = $this->‪getLanguageService()->sL($defaultLanguageLabel);
152  if (isset($pageTs['defaultLanguageLabel'])) {
153  $defaultLanguageLabel = $pageTs['defaultLanguageLabel'] . ' (' . $defaultLanguageLabel . ')';
154  }
155  $defaultLanguageFlag = '';
156  if (isset($pageTs['defaultLanguageFlag'])) {
157  $defaultLanguageFlag = 'flags-' . $pageTs['defaultLanguageFlag'];
158  }
159  $language = new ‪SiteLanguage(0, '', $language->getBase(), [
160  'title' => $defaultLanguageLabel,
161  'flag' => $defaultLanguageFlag,
162  ]);
163  }
164  $availableLanguages[$language->getLanguageId()] = $language;
165  }
166  }
167 
168  return $availableLanguages;
169  }
170 
175  {
176  throw new \RuntimeException('No error handler given for the status code "' . ‪$statusCode . '".', 1522495102);
177  }
178 
180  {
181  return ‪$GLOBALS['LANG'];
182  }
183 }
‪TYPO3\CMS\Core\Site\Entity\NullSite\getRootPageId
‪getRootPageId()
Definition: NullSite.php:90
‪TYPO3\CMS\Core\Site\Entity\SiteInterface
Definition: SiteInterface.php:26
‪TYPO3\CMS\Core\Site\Entity\NullSite\getBase
‪getBase()
Definition: NullSite.php:82
‪TYPO3\CMS\Core\Site\Entity\NullSite\getDefaultLanguage
‪getDefaultLanguage()
Definition: NullSite.php:121
‪TYPO3\CMS\Core\Site\Entity\NullSite
Definition: NullSite.php:32
‪TYPO3\CMS\Core\Site\Entity\NullSite\getLanguageService
‪getLanguageService()
Definition: NullSite.php:179
‪TYPO3\CMS\Core\Site\Entity\NullSite\getLanguageById
‪getLanguageById(int $languageId)
Definition: NullSite.php:110
‪TYPO3\CMS\Core\Site\Entity\NullSite\getAvailableLanguages
‪getAvailableLanguages(BackendUserAuthentication $user, bool $includeAllLanguagesFlag=false, int $pageId=null)
Definition: NullSite.php:130
‪TYPO3\CMS\Core\Http\Uri
Definition: Uri.php:30
‪TYPO3\CMS\Core\Site\Entity\NullSite\getErrorHandler
‪getErrorHandler(int $statusCode)
Definition: NullSite.php:174
‪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:100
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\checkLanguageAccess
‪bool checkLanguageAccess($langValue)
Definition: BackendUserAuthentication.php:561
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Core\Site\Entity\NullSite\getIdentifier
‪getIdentifier()
Definition: NullSite.php:74
‪TYPO3\CMS\Core\Error\PageErrorHandler\PageErrorHandlerInterface
Definition: PageErrorHandlerInterface.php:29
‪TYPO3\CMS\Core\Site\Entity
Definition: NullSite.php:18
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Site\Entity\NullSite\$languages
‪array $languages
Definition: NullSite.php:38
‪TYPO3\CMS\Core\Site\Entity\NullSite\$rootPageId
‪int $rootPageId
Definition: NullSite.php:33
‪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:46
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Core\Utility\GeneralUtility\intExplode
‪static list< int > intExplode(string $delimiter, string $string, bool $removeEmptyValues=false)
Definition: GeneralUtility.php:756