소스 검색

https://assistance.opentalent.fr/browse/V8-1663

Olivier Massot 4 년 전
부모
커밋
e898f8676d
1개의 변경된 파일19개의 추가작업 그리고 5개의 파일을 삭제
  1. 19 5
      ot_core/Classes/Controller/SelectedSiteController.php

+ 19 - 5
ot_core/Classes/Controller/SelectedSiteController.php

@@ -14,6 +14,8 @@ use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
  * If no page is selected or if this page does not have any root page as an ancestor,
  * the action is forwarded to a page asking the user to select one.
  *
+ * If only one website appears in the page-tree, this site is automatically selected
+ *
  * Class BeOnSiteController
  */
 class SelectedSiteController extends ActionController
@@ -26,13 +28,25 @@ class SelectedSiteController extends ActionController
     protected $currentRootUid;
 
     protected function callActionMethod() {
-        try {
-            $otPageRepository = GeneralUtility::makeInstance(OtPageRepository::class);
-            $this->currentRootUid = $otPageRepository->getCurrentRootUid();
-        } catch (NoSiteSelected $e) {
-            $this->currentRootUid = null;
+
+        // Check if the current be-user has a db_mountpoint, and only has one.
+        // If so, this will be considered as the selected site (since its the only one available)
+        $mp = $GLOBALS['BE_USER']->user['db_mountpoints'];
+
+        if ($mp && count(explode(',', $mp)) === 1) {
+            $this->currentRootUid = (int)$mp;
+        } else {
+            // No db mountpoint has been set up, or more than one.
+            // Now we check if a site's page is selected
+            try {
+                $otPageRepository = GeneralUtility::makeInstance(OtPageRepository::class);
+                $this->currentRootUid = $otPageRepository->getCurrentRootUid();
+            } catch (NoSiteSelected $e) {
+                $this->currentRootUid = null;
+            }
         }
 
+        // No site is selected, redirect to the warning page
         if ($this->actionMethodName != 'displayNoSelectedPageWarningAction' && $this->currentRootUid == null) {
             $this->forward('displayNoSelectedPageWarning', 'SelectedSite', 'OtCore');
         }