$base = $this->sanitizeBaseUrl(rtrim($this->base, '/') . '/');
}
$this->languages[$languageUid] = new SiteLanguage(
- $this,
$languageUid,
$languageConfiguration['locale'],
$base,
*/
class SiteLanguage
{
- /**
- * @var SiteInterface
- */
- protected $site;
-
/**
* The language mapped to the sys_language DB entry.
*
/**
* SiteLanguage constructor.
- * @param SiteInterface $site
* @param int $languageId
* @param string $locale
* @param string $base
* @param array $attributes
*/
- public function __construct(SiteInterface $site, int $languageId, string $locale, string $base, array $attributes)
+ public function __construct(int $languageId, string $locale, string $base, array $attributes)
{
- $this->site = $site;
$this->languageId = $languageId;
$this->locale = $locale;
$this->base = $base;
];
}
- /**
- * @return SiteInterface
- */
- public function getSite(): SiteInterface
- {
- return $this->site;
- }
-
/**
* @return int
*/
use TYPO3\CMS\Core\Configuration\TypoScript\ConditionMatching\AbstractConditionMatcher;
use TYPO3\CMS\Core\Context\Context;
use TYPO3\CMS\Core\Context\UserAspect;
+use TYPO3\CMS\Core\Site\Entity\Site;
use TYPO3\CMS\Core\Site\Entity\SiteLanguage;
use TYPO3\CMS\Core\Utility\GeneralUtility;
}
break;
case 'site':
- $siteLanguage = $this->getCurrentSiteLanguage();
- if ($siteLanguage instanceof SiteLanguage) {
- $site = $siteLanguage->getSite();
+ $site = $this->getCurrentSite();
+ if ($site instanceof Site) {
$values = GeneralUtility::trimExplode(',', $value, true);
foreach ($values as $test) {
$point = strcspn($test, '=');
}
return null;
}
+
+ /**
+ * Returns the currently configured site if a site is configured (= resolved) in the current request.
+ *
+ * @internal
+ */
+ protected function getCurrentSite(): ?Site
+ {
+ if ($GLOBALS['TYPO3_REQUEST'] instanceof ServerRequestInterface
+ && $GLOBALS['TYPO3_REQUEST']->getAttribute('site') instanceof Site) {
+ return $GLOBALS['TYPO3_REQUEST']->getAttribute('site');
+ }
+ return null;
+ }
}
{
$site = new Site('angelo', 13, ['languages' => [], 'base' => 'https://typo3.org/']);
$GLOBALS['TYPO3_REQUEST'] = new ServerRequest();
- $GLOBALS['TYPO3_REQUEST'] = $GLOBALS['TYPO3_REQUEST']->withAttribute('language', $site->getLanguageById(0));
+ $GLOBALS['TYPO3_REQUEST'] = $GLOBALS['TYPO3_REQUEST']->withAttribute('site', $site);
$subject = new ConditionMatcher(new Context());
$this->assertTrue($subject->match('[site = identifier = angelo]'));
$this->assertTrue($subject->match('[site = rootPageId = 13]'));
]
]);
$GLOBALS['TYPO3_REQUEST'] = new ServerRequest();
- $GLOBALS['TYPO3_REQUEST'] = $GLOBALS['TYPO3_REQUEST']->withAttribute('language', $site->getLanguageById(0));
+ $GLOBALS['TYPO3_REQUEST'] = $GLOBALS['TYPO3_REQUEST']->withAttribute('site', $site);
$subject = new ConditionMatcher(new Context());
$this->assertFalse($subject->match('[site = identifier = berta]'));
$this->assertFalse($subject->match('[site = rootPageId = 14, rootPageId=23]'));