‪TYPO3CMS  9.5
LanguageAspectFactory.php
Go to the documentation of this file.
1 <?php
2 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 
20 
25 {
36  public static function ‪createFromTypoScript(array $config): ‪LanguageAspect
37  {
38  // Get values from TypoScript, if not set before
39  $languageId = (int)($config['sys_language_uid'] ?? 0);
40  $fallbacks = GeneralUtility::trimExplode(';', $config['sys_language_mode'] ?? '');
41  $fallbackMode = null;
42  if (isset($fallbacks[0])) {
43  $fallbackMode = $fallbacks[0];
44  }
45  $fallbackOrder = null;
46  if (isset($fallbacks[1])) {
47  $fallbackOrder = $fallbacks[1];
48  }
49 
50  // Page resolving
51  switch ($fallbackMode) {
52  case 'strict':
53  $fallBackOrder = [];
54  break;
55  // Ignore anything if a page cannot be found, and resolve pageId=0 instead.
56  case 'ignore':
57  $fallBackOrder = [-1];
58  break;
59  case 'fallback':
60  case 'content_fallback':
61  if (!empty($fallbackOrder)) {
62  $fallBackOrder = GeneralUtility::trimExplode(',', $fallbackOrder);
63  // no strict typing explictly done here
64  if (!in_array(0, $fallBackOrder) && !in_array('pageNotFound', $fallBackOrder)) {
65  $fallBackOrder[] = 'pageNotFound';
66  }
67  } else {
68  $fallBackOrder = [0];
69  }
70  break;
71  case '':
72  $fallBackOrder = ['off'];
73  break;
74  default:
75  $fallBackOrder = [0];
76  }
77 
78  // Content fetching
79  switch ((string)($config['sys_language_overlay'] ?? '')) {
80  case '1':
81  $overlayType = ‪LanguageAspect::OVERLAYS_MIXED;
82  break;
83  case '0':
84  $overlayType = ‪LanguageAspect::OVERLAYS_OFF;
85  break;
86  case 'hideNonTranslated':
87  $overlayType = ‪LanguageAspect::OVERLAYS_ON;
88  break;
89  default:
91  }
92 
93  return GeneralUtility::makeInstance(LanguageAspect::class, $languageId, $languageId, $overlayType, $fallBackOrder);
94  }
95 
103  {
104  $languageId = $language->‪getLanguageId();
105  $fallbackType = $language->‪getFallbackType();
106  $fallbackOrder = $language->‪getFallbackLanguageIds();
107  $fallbackOrder[] = 'pageNotFound';
108  switch ($fallbackType) {
109  // Fall back to other language, if the page does not exist in the requested language
110  // But always fetch only records of this specific (available) language
111  case 'free':
112  $overlayType = ‪LanguageAspect::OVERLAYS_OFF;
113  break;
114 
115  // Fall back to other language, if the page does not exist in the requested language
116  // Do overlays, and keep the ones that are not translated
117  case 'fallback':
118  $overlayType = ‪LanguageAspect::OVERLAYS_MIXED;
119  break;
120 
121  // Same as "fallback" but remove the records that are not translated
122  case 'strict':
124  break;
125 
126  // Ignore, fallback to default language
127  default:
128  $fallbackOrder = [0];
129  $overlayType = ‪LanguageAspect::OVERLAYS_OFF;
130  }
131 
132  return GeneralUtility::makeInstance(LanguageAspect::class, $languageId, $languageId, $overlayType, $fallbackOrder);
133  }
134 }
‪TYPO3\CMS\Core\Site\Entity\SiteLanguage\getLanguageId
‪int getLanguageId()
Definition: SiteLanguage.php:188
‪TYPO3\CMS\Core\Context\LanguageAspectFactory
Definition: LanguageAspectFactory.php:25
‪TYPO3\CMS\Core\Context\LanguageAspect\OVERLAYS_MIXED
‪const OVERLAYS_MIXED
Definition: LanguageAspect.php:73
‪TYPO3\CMS\Core\Site\Entity\SiteLanguage\getFallbackLanguageIds
‪array getFallbackLanguageIds()
Definition: SiteLanguage.php:302
‪TYPO3\CMS\Core\Context
Definition: AspectInterface.php:3
‪TYPO3\CMS\Core\Context\LanguageAspect\OVERLAYS_ON
‪const OVERLAYS_ON
Definition: LanguageAspect.php:74
‪TYPO3\CMS\Core\Context\LanguageAspectFactory\createFromSiteLanguage
‪static LanguageAspect createFromSiteLanguage(SiteLanguage $language)
Definition: LanguageAspectFactory.php:102
‪TYPO3\CMS\Core\Site\Entity\SiteLanguage
Definition: SiteLanguage.php:25
‪TYPO3\CMS\Core\Context\LanguageAspectFactory\createFromTypoScript
‪static LanguageAspect createFromTypoScript(array $config)
Definition: LanguageAspectFactory.php:36
‪TYPO3\CMS\Core\Site\Entity\SiteLanguage\getFallbackType
‪string getFallbackType()
Definition: SiteLanguage.php:294
‪TYPO3\CMS\Core\Context\LanguageAspect
Definition: LanguageAspect.php:55
‪TYPO3\CMS\Core\Context\LanguageAspect\OVERLAYS_OFF
‪const OVERLAYS_OFF
Definition: LanguageAspect.php:72
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Core\Context\LanguageAspect\OVERLAYS_ON_WITH_FLOATING
‪const OVERLAYS_ON_WITH_FLOATING
Definition: LanguageAspect.php:75