فهرست منبع

use the global ot_website var to avoid db calls

Olivier Massot 4 سال پیش
والد
کامیت
6584657df0

+ 10 - 5
ot_core/Classes/Website/OtWebsiteRepository.php

@@ -260,7 +260,7 @@ class OtWebsiteRepository
     }
 
     /**
-     * Returns the typo3 site matching the current request (FE only)
+     * Returns the typo3 site matching the current request (FE only!)
      *
      * @return array
      * @throws NoSuchWebsiteException
@@ -268,19 +268,24 @@ class OtWebsiteRepository
     public function getCurrentWebsiteFromFEGlobals(): array
     {
         $request = $GLOBALS['TYPO3_REQUEST'];
-        $site = $request->getAttribute('site');
-        return $this->getWebsiteByConfigIdentifier($site->getIdentifier());
+        $ot_website = $GLOBALS['TYPO3_REQUEST']->getAttribute('ot_website');
+        if ($ot_website) {
+            return $ot_website;
+        } else {
+            $site = $request->getAttribute('site');
+            return $this->getWebsiteByConfigIdentifier($site->getIdentifier());
+        }
     }
 
     /**
-     * Returns the typo3 site matching the current request (FE only)
+     * Returns the typo3 site matching the current request (FE only!)
      *
      * @return int
      * @throws NoSuchWebsiteException
      */
     public function getCurrentRootpageUidFromFEGlobals(): int
     {
-        $website = $this->getCurrentWebSiteFromFEGlobals();
+        $website = $this->getCurrentWebsiteFromFEGlobals();
         return $this->getWebsiteRootUid($website['uid']);
     }
 

+ 5 - 1
ot_templating/Classes/ViewHelpers/Request/GetWebsiteViewHelper.php

@@ -4,6 +4,9 @@ namespace Opentalent\OtTemplating\ViewHelpers\Request;
 
 use Closure;
 use Opentalent\OtCore\ViewHelpers\OtAbstractViewHelper;
+use Opentalent\OtCore\Website\OtWebsiteRepository;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Extbase\Object\ObjectManager;
 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
 
 /**
@@ -31,6 +34,7 @@ class GetWebsiteViewHelper extends OtAbstractViewHelper {
         Closure $renderChildrenClosure,
         RenderingContextInterface $renderingContext
     ) {
-        return $GLOBALS['TSFE']->getAttribute('ot_website');
+        $pageRepository = GeneralUtility::makeInstance(ObjectManager::class)->get(OtWebsiteRepository::class);
+        return $pageRepository->getCurrentWebsiteFromFEGlobals();
     }
 }

+ 3 - 1
ot_templating/Classes/ViewHelpers/Template/CurrentViewHelper.php

@@ -36,7 +36,9 @@ class CurrentViewHelper extends OtAbstractViewHelper
         Closure $renderChildrenClosure,
         RenderingContextInterface $renderingContext
     ) {
-        $website = $GLOBALS['TYPO3_REQUEST']->getAttribute('ot_website');
+        $pageRepository = GeneralUtility::makeInstance(ObjectManager::class)->get(OtWebsiteRepository::class);
+        $website = $pageRepository->getCurrentWebsiteFromFEGlobals();
+
         $templateRepository = GeneralUtility::makeInstance(ObjectManager::class)->get(TemplateRepository::class);
         return $templateRepository->getTemplate($website);
     }