‪TYPO3CMS  10.4
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;
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 
79  public function ‪getIdentifier(): string
80  {
81  return '#NULL';
82  }
83 
87  public function ‪getBase(): UriInterface
88  {
89  return new ‪Uri('/');
90  }
91 
97  public function ‪getRootPageId(): int
98  {
99  return 0;
100  }
101 
107  public function ‪getLanguages(): array
108  {
109  return ‪$this->languages;
110  }
111 
119  public function ‪getLanguageById(int $languageId): ‪SiteLanguage
120  {
121  if (isset($this->languages[$languageId])) {
122  return $this->languages[$languageId];
123  }
124  throw new \InvalidArgumentException(
125  'Language ' . $languageId . ' does not exist on site ' . $this->‪getIdentifier() . '.',
126  1522965188
127  );
128  }
129 
133  public function ‪getDefaultLanguage(): ‪SiteLanguage
134  {
135  return reset($this->languages);
136  }
137 
144  public function ‪getAvailableLanguages(‪BackendUserAuthentication $user, bool $includeAllLanguagesFlag = false, int $pageId = null): array
145  {
146  $availableLanguages = [];
147 
148  // Check if we need to add language "-1"
149  if ($includeAllLanguagesFlag && $user->‪checkLanguageAccess(-1)) {
150  $availableLanguages[-1] = new ‪SiteLanguage(-1, '', $this->‪getBase(), [
151  'title' => $this->‪getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_mod_web_list.xlf:multipleLanguages'),
152  'flag' => 'flags-multiple'
153  ]);
154  }
155  $pageTs = ‪BackendUtility::getPagesTSconfig((int)$pageId);
156  $pageTs = $pageTs['mod.']['SHARED.'] ?? [];
157 
158  $disabledLanguages = ‪GeneralUtility::intExplode(',', $pageTs['disableLanguages'] ?? '', true);
159  // Do not add the ones that are not allowed by the user
160  foreach ($this->languages as $language) {
161  if ($user->‪checkLanguageAccess($language->getLanguageId()) && !in_array($language->getLanguageId(), $disabledLanguages, true)) {
162  if ($language->getLanguageId() === 0) {
163  // 0: "Default" language
164  $defaultLanguageLabel = 'LLL:EXT:core/Resources/Private/Language/locallang_mod_web_list.xlf:defaultLanguage';
165  $defaultLanguageLabel = $this->‪getLanguageService()->‪sL($defaultLanguageLabel);
166  if (isset($pageTs['defaultLanguageLabel'])) {
167  $defaultLanguageLabel = $pageTs['defaultLanguageLabel'] . ' (' . $defaultLanguageLabel . ')';
168  }
169  $defaultLanguageFlag = '';
170  if (isset($pageTs['defaultLanguageFlag'])) {
171  $defaultLanguageFlag = 'flags-' . $pageTs['defaultLanguageFlag'];
172  }
173  $language = new ‪SiteLanguage(0, '', $language->getBase(), [
174  'title' => $defaultLanguageLabel,
175  'flag' => $defaultLanguageFlag,
176  ]);
177  }
178  $availableLanguages[$language->getLanguageId()] = $language;
179  }
180  }
181 
182  return $availableLanguages;
183  }
184 
192  public function ‪getErrorHandler(int $statusCode): ‪PageErrorHandlerInterface
193  {
194  throw new \RuntimeException('No error handler given for the status code "' . $statusCode . '".', 1522495102);
195  }
196 
201  protected function ‪getLanguageService(): ‪LanguageService
202  {
203  return ‪$GLOBALS['LANG'];
204  }
205 }
‪TYPO3\CMS\Core\Site\Entity\SiteInterface
Definition: SiteInterface.php:26
‪TYPO3\CMS\Core\Site\Entity\NullSite\getBase
‪getBase()
Definition: NullSite.php:85
‪TYPO3\CMS\Core\Site\Entity\NullSite\getErrorHandler
‪PageErrorHandlerInterface getErrorHandler(int $statusCode)
Definition: NullSite.php:190
‪TYPO3\CMS\Core\Site\Entity\NullSite\getDefaultLanguage
‪getDefaultLanguage()
Definition: NullSite.php:131
‪TYPO3\CMS\Core\Site\Entity\NullSite
Definition: NullSite.php:32
‪TYPO3\CMS\Core\Site\Entity\NullSite\getLanguageById
‪SiteLanguage getLanguageById(int $languageId)
Definition: NullSite.php:117
‪TYPO3\CMS\Core\Site\Entity\NullSite\getIdentifier
‪string getIdentifier()
Definition: NullSite.php:77
‪TYPO3\CMS\Core\Localization\LanguageService\sL
‪string sL($input)
Definition: LanguageService.php:194
‪TYPO3\CMS\Core\Site\Entity\NullSite\getRootPageId
‪int getRootPageId()
Definition: NullSite.php:95
‪TYPO3\CMS\Core\Site\Entity\NullSite\getAvailableLanguages
‪getAvailableLanguages(BackendUserAuthentication $user, bool $includeAllLanguagesFlag=false, int $pageId=null)
Definition: NullSite.php:142
‪TYPO3\CMS\Core\Http\Uri
Definition: Uri.php:29
‪TYPO3\CMS\Core\Site\Entity\SiteLanguage
Definition: SiteLanguage.php:26
‪TYPO3\CMS\Core\Site\Entity\NullSite\getLanguageService
‪LanguageService getLanguageService()
Definition: NullSite.php:199
‪TYPO3\CMS\Backend\Utility\BackendUtility\getPagesTSconfig
‪static array getPagesTSconfig($id)
Definition: BackendUtility.php:698
‪TYPO3\CMS\Core\Site\Entity\NullSite\getLanguages
‪SiteLanguage[] getLanguages()
Definition: NullSite.php:105
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\checkLanguageAccess
‪bool checkLanguageAccess($langValue)
Definition: BackendUserAuthentication.php:709
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Backend\Utility\BackendUtility
Definition: BackendUtility.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:5
‪TYPO3\CMS\Core\Utility\GeneralUtility\intExplode
‪static int[] intExplode($delimiter, $string, $removeEmptyValues=false, $limit=0)
Definition: GeneralUtility.php:988
‪TYPO3\CMS\Core\Site\Entity\NullSite\$rootPageId
‪int $rootPageId
Definition: NullSite.php:35
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:42
‪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:46