‪TYPO3CMS  10.4
SiteLanguage.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 
26 {
32  protected ‪$languageId;
33 
39  protected ‪$locale;
40 
46  protected ‪$base;
47 
52  protected ‪$title = 'Default';
53 
58  protected ‪$navigationTitle = '';
59 
64  protected ‪$websiteTitle = '';
65 
70  protected ‪$flagIdentifier = '';
71 
76  protected ‪$twoLetterIsoCode = 'en';
77 
84  protected ‪$hreflang = 'en-US';
85 
90  protected ‪$direction = '';
91 
99  protected ‪$typo3Language = 'default';
100 
104  protected ‪$fallbackType = 'strict';
105 
109  protected ‪$fallbackLanguageIds = [];
110 
114  protected ‪$enabled = true;
115 
120  protected ‪$configuration = [];
121 
130  public function ‪__construct(int ‪$languageId, string ‪$locale, UriInterface ‪$base, array ‪$configuration)
131  {
132  $this->languageId = ‪$languageId;
133  $this->locale = ‪$locale;
134  $this->base = ‪$base;
135  $this->configuration = ‪$configuration;
136 
137  if (!empty(‪$configuration['title'])) {
138  $this->title = ‪$configuration['title'];
139  }
140  if (!empty(‪$configuration['navigationTitle'])) {
141  $this->navigationTitle = ‪$configuration['navigationTitle'];
142  }
143  if (!empty(‪$configuration['websiteTitle'])) {
144  $this->websiteTitle = ‪$configuration['websiteTitle'];
145  }
146  if (!empty(‪$configuration['flag'])) {
147  $this->flagIdentifier = ‪$configuration['flag'];
148  }
149  if (!empty(‪$configuration['typo3Language'])) {
150  $this->typo3Language = ‪$configuration['typo3Language'];
151  }
152  if (!empty(‪$configuration['iso-639-1'])) {
153  $this->twoLetterIsoCode = ‪$configuration['iso-639-1'];
154  }
155  if (!empty(‪$configuration['hreflang'])) {
156  $this->hreflang = ‪$configuration['hreflang'];
157  }
158  if (!empty(‪$configuration['direction'])) {
159  $this->direction = ‪$configuration['direction'];
160  }
161  if (!empty(‪$configuration['fallbackType'])) {
162  $this->fallbackType = ‪$configuration['fallbackType'];
163  }
164  if (isset(‪$configuration['fallbacks'])) {
166 
167  // It is important to distinct between "0" and "" so, empty() should not be used here
168  if (is_string(‪$fallbackLanguageIds)) {
169  if (‪$fallbackLanguageIds !== '') {
171  } else {
173  }
174  } elseif (is_scalar(‪$fallbackLanguageIds)) {
176  }
177  $this->fallbackLanguageIds = array_map('intval', ‪$fallbackLanguageIds);
178  }
179  if (isset(‪$configuration['enabled'])) {
180  $this->‪enabled = (bool)‪$configuration['enabled'];
181  }
182  }
183 
190  public function ‪toArray(): array
191  {
192  return array_merge($this->configuration, [
193  'languageId' => $this->‪getLanguageId(),
194  'locale' => $this->‪getLocale(),
195  'base' => (string)$this->‪getBase(),
196  'title' => $this->‪getTitle(),
197  'websiteTitle' => $this->‪getWebsiteTitle(),
198  'navigationTitle' => $this->‪getNavigationTitle(),
199  'twoLetterIsoCode' => $this->‪getTwoLetterIsoCode(),
200  'hreflang' => $this->‪getHreflang(),
201  'direction' => $this->‪getDirection(),
202  'typo3Language' => $this->‪getTypo3Language(),
203  'flagIdentifier' => $this->‪getFlagIdentifier(),
204  'fallbackType' => $this->‪getFallbackType(),
205  'enabled' => $this->‪enabled(),
206  'fallbackLanguageIds' => $this->‪getFallbackLanguageIds(),
207  ]);
208  }
209 
213  public function ‪getLanguageId(): int
214  {
215  return ‪$this->languageId;
216  }
217 
221  public function ‪getLocale(): string
222  {
223  return ‪$this->locale;
224  }
225 
229  public function ‪getBase(): UriInterface
230  {
231  return ‪$this->base;
232  }
233 
237  public function ‪getTitle(): string
238  {
239  return ‪$this->title;
240  }
241 
245  public function ‪getNavigationTitle(): string
246  {
247  return $this->navigationTitle ?: ‪$this->title;
248  }
249 
253  public function ‪getWebsiteTitle(): string
254  {
255  return ‪$this->websiteTitle;
256  }
257 
261  public function ‪getFlagIdentifier(): string
262  {
264  }
265 
269  public function ‪getTypo3Language(): string
270  {
272  }
273 
279  public function ‪getTwoLetterIsoCode(): string
280  {
282  }
283 
289  public function ‪getHreflang(): string
290  {
291  return ‪$this->hreflang;
292  }
293 
299  public function ‪getDirection(): string
300  {
301  return ‪$this->direction;
302  }
303 
309  public function ‪enabled(): bool
310  {
311  return ‪$this->enabled;
312  }
313 
319  public function ‪isEnabled(): bool
320  {
321  return ‪$this->enabled;
322  }
323 
327  public function ‪getFallbackType(): string
328  {
329  return ‪$this->fallbackType;
330  }
331 
335  public function ‪getFallbackLanguageIds(): array
336  {
338  }
339 }
‪TYPO3\CMS\Core\Site\Entity\SiteLanguage\__construct
‪__construct(int $languageId, string $locale, UriInterface $base, array $configuration)
Definition: SiteLanguage.php:115
‪TYPO3\CMS\Core\Site\Entity\SiteLanguage\getLanguageId
‪int getLanguageId()
Definition: SiteLanguage.php:198
‪TYPO3\CMS\Core\Site\Entity\SiteLanguage\$base
‪UriInterface $base
Definition: SiteLanguage.php:43
‪TYPO3\CMS\Core\Site\Entity\SiteLanguage\$locale
‪string $locale
Definition: SiteLanguage.php:37
‪TYPO3\CMS\Core\Site\Entity\SiteLanguage\getFallbackLanguageIds
‪array getFallbackLanguageIds()
Definition: SiteLanguage.php:320
‪TYPO3\CMS\Core\Site\Entity\SiteLanguage\$twoLetterIsoCode
‪string $twoLetterIsoCode
Definition: SiteLanguage.php:68
‪TYPO3\CMS\Core\Site\Entity\SiteLanguage\getTitle
‪string getTitle()
Definition: SiteLanguage.php:222
‪TYPO3\CMS\Core\Site\Entity\SiteLanguage\getTwoLetterIsoCode
‪string getTwoLetterIsoCode()
Definition: SiteLanguage.php:264
‪TYPO3\CMS\Core\Site\Entity\SiteLanguage\$enabled
‪bool $enabled
Definition: SiteLanguage.php:100
‪TYPO3\CMS\Core\Site\Entity\SiteLanguage\$typo3Language
‪string $typo3Language
Definition: SiteLanguage.php:88
‪TYPO3\CMS\Core\Site\Entity\SiteLanguage\getDirection
‪string getDirection()
Definition: SiteLanguage.php:284
‪TYPO3\CMS\Core\Site\Entity\SiteLanguage\$hreflang
‪string $hreflang
Definition: SiteLanguage.php:75
‪TYPO3\CMS\Core\Site\Entity\SiteLanguage
Definition: SiteLanguage.php:26
‪TYPO3\CMS\Core\Site\Entity\SiteLanguage\getLocale
‪string getLocale()
Definition: SiteLanguage.php:206
‪TYPO3\CMS\Core\Site\Entity\SiteLanguage\$flagIdentifier
‪string $flagIdentifier
Definition: SiteLanguage.php:63
‪TYPO3\CMS\Core\Site\Entity\SiteLanguage\$configuration
‪array $configuration
Definition: SiteLanguage.php:105
‪TYPO3\CMS\Core\Site\Entity\SiteLanguage\getFlagIdentifier
‪string getFlagIdentifier()
Definition: SiteLanguage.php:246
‪TYPO3\CMS\Core\Site\Entity\SiteLanguage\$websiteTitle
‪string $websiteTitle
Definition: SiteLanguage.php:58
‪TYPO3\CMS\Core\Site\Entity\SiteLanguage\$fallbackType
‪string $fallbackType
Definition: SiteLanguage.php:92
‪TYPO3\CMS\Core\Site\Entity\SiteLanguage\$direction
‪string $direction
Definition: SiteLanguage.php:80
‪TYPO3\CMS\Core\Site\Entity\SiteLanguage\getFallbackType
‪string getFallbackType()
Definition: SiteLanguage.php:312
‪TYPO3\CMS\Core\Site\Entity\SiteLanguage\isEnabled
‪bool isEnabled()
Definition: SiteLanguage.php:304
‪TYPO3\CMS\Core\Site\Entity\SiteLanguage\$languageId
‪int $languageId
Definition: SiteLanguage.php:31
‪TYPO3\CMS\Core\Site\Entity\SiteLanguage\getHreflang
‪string getHreflang()
Definition: SiteLanguage.php:274
‪TYPO3\CMS\Core\Site\Entity\SiteLanguage\$navigationTitle
‪string $navigationTitle
Definition: SiteLanguage.php:53
‪TYPO3\CMS\Core\Site\Entity\SiteLanguage\$title
‪string $title
Definition: SiteLanguage.php:48
‪TYPO3\CMS\Core\Site\Entity
Definition: NullSite.php:18
‪TYPO3\CMS\Core\Site\Entity\SiteLanguage\getBase
‪UriInterface getBase()
Definition: SiteLanguage.php:214
‪TYPO3\CMS\Core\Site\Entity\SiteLanguage\getNavigationTitle
‪string getNavigationTitle()
Definition: SiteLanguage.php:230
‪TYPO3\CMS\Core\Site\Entity\SiteLanguage\toArray
‪array toArray()
Definition: SiteLanguage.php:175
‪TYPO3\CMS\Core\Site\Entity\SiteLanguage\$fallbackLanguageIds
‪array $fallbackLanguageIds
Definition: SiteLanguage.php:96
‪TYPO3\CMS\Core\Site\Entity\SiteLanguage\enabled
‪bool enabled()
Definition: SiteLanguage.php:294
‪TYPO3\CMS\Core\Site\Entity\SiteLanguage\getWebsiteTitle
‪string getWebsiteTitle()
Definition: SiteLanguage.php:238
‪TYPO3\CMS\Core\Site\Entity\SiteLanguage\getTypo3Language
‪string getTypo3Language()
Definition: SiteLanguage.php:254