[TASK] Remove dependency between SiteLanguage and Site
[Packages/TYPO3.CMS.git] / typo3 / sysext / frontend / Classes / Configuration / TypoScript / ConditionMatching / ConditionMatcher.php
index 0a9cd41..46132b9 100644 (file)
@@ -19,6 +19,7 @@ use Psr\Http\Message\ServerRequestInterface;
 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;
 
@@ -96,9 +97,8 @@ class ConditionMatcher extends AbstractConditionMatcher
                 }
                 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, '=');
@@ -300,4 +300,18 @@ class ConditionMatcher extends AbstractConditionMatcher
         }
         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;
+    }
 }