‪TYPO3CMS  ‪main
LanguageAspectFactory.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 
22 
27 {
31  public static function ‪createFromSiteLanguage(‪SiteLanguage $language): ‪LanguageAspect
32  {
33  $languageId = $language->‪getLanguageId();
34  $fallbackType = $language->‪getFallbackType();
35  $fallbackOrder = $language->‪getFallbackLanguageIds();
36  $fallbackOrder[] = 'pageNotFound';
37  switch ($fallbackType) {
38  // Fall back to other language, if the page does not exist in the requested language
39  // But always fetch only records of this specific (available) language
40  case 'free':
41  $overlayType = ‪LanguageAspect::OVERLAYS_OFF;
42  break;
43 
44  // Fall back to other language, if the page does not exist in the requested language
45  // Do overlays, and keep the ones that are not translated
46  case 'fallback':
47  $overlayType = ‪LanguageAspect::OVERLAYS_MIXED;
48  break;
49 
50  // Same as "fallback" but remove the records that are not translated
51  case 'strict':
53  break;
54 
55  // Ignore, fallback to default language
56  default:
57  $fallbackOrder = [0];
58  $overlayType = ‪LanguageAspect::OVERLAYS_OFF;
59  }
60 
61  return GeneralUtility::makeInstance(LanguageAspect::class, $languageId, $languageId, $overlayType, $fallbackOrder);
62  }
63 }
‪TYPO3\CMS\Core\Context\LanguageAspectFactory
Definition: LanguageAspectFactory.php:27
‪TYPO3\CMS\Core\Context\LanguageAspect\OVERLAYS_MIXED
‪const OVERLAYS_MIXED
Definition: LanguageAspect.php:75
‪TYPO3\CMS\Core\Site\Entity\SiteLanguage\getFallbackType
‪getFallbackType()
Definition: SiteLanguage.php:262
‪TYPO3\CMS\Core\Context
Definition: AspectInterface.php:18
‪TYPO3\CMS\Core\Context\LanguageAspectFactory\createFromSiteLanguage
‪static createFromSiteLanguage(SiteLanguage $language)
Definition: LanguageAspectFactory.php:31
‪TYPO3\CMS\Core\Site\Entity\SiteLanguage
Definition: SiteLanguage.php:27
‪TYPO3\CMS\Core\Site\Entity\SiteLanguage\getFallbackLanguageIds
‪getFallbackLanguageIds()
Definition: SiteLanguage.php:267
‪TYPO3\CMS\Core\Site\Entity\SiteLanguage\getLanguageId
‪getLanguageId()
Definition: SiteLanguage.php:169
‪TYPO3\CMS\Core\Context\LanguageAspect
Definition: LanguageAspect.php:57
‪TYPO3\CMS\Core\Context\LanguageAspect\OVERLAYS_OFF
‪const OVERLAYS_OFF
Definition: LanguageAspect.php:74
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Core\Context\LanguageAspect\OVERLAYS_ON_WITH_FLOATING
‪const OVERLAYS_ON_WITH_FLOATING
Definition: LanguageAspect.php:77