Parcourir la source

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

Olivier Massot il y a 4 ans
Parent
commit
97c17da298

+ 1 - 2
ot_core/Classes/Controller/SelectedSiteController.php

@@ -37,8 +37,7 @@ class SelectedSiteController extends ActionController
 
         // 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)
-        $mountpoints = $GLOBALS['BE_USER']->returnWebmounts();
-        $mountpoints = array_filter($mountpoints, function($m) { return $m != 0; });
+        $mountpoints = $this->otPageRepository->getCurrentBeUserMountpoints();
 
         if ($mountpoints && count($mountpoints) === 1) {
             $this->currentRootUid = (int)$mountpoints[0];

+ 15 - 0
ot_core/Classes/Page/OtPageRepository.php

@@ -213,6 +213,21 @@ class OtPageRepository
         return $rootUid;
     }
 
+    /**
+     * [Backend Only]
+     *
+     * Return the mountpoint(s) for the current BE User
+     */
+    public function getCurrentBeUserMountpoints(): array
+    {
+        // 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)
+        $mountpoints = $GLOBALS['BE_USER']->returnWebmounts();
+        $mountpoints = array_filter($mountpoints, function($m) { return $m != 0; });
+
+        return $mountpoints;
+    }
+
     public function getPage(int $uid) {
         return $this->pageRepository->getPage($uid);
     }

+ 33 - 0
ot_templating/Classes/XClass/Form/Configuration/ConfigurationManager.php

@@ -0,0 +1,33 @@
+<?php
+
+namespace Opentalent\OtTemplating\XClass\Form\Configuration;
+
+use Opentalent\OtCore\Page\OtPageRepository;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Extbase\Object\ObjectManager;
+
+class ConfigurationManager extends \TYPO3\CMS\Form\Mvc\Configuration\ConfigurationManager
+{
+    /**
+     * Override the default form configuration loader to add the forms directory matching
+     * the current be user mounted organization(s) id(s)
+     *
+     * @param string $extensionName
+     * @return array
+     * @throws \TYPO3\CMS\Form\Mvc\Configuration\Exception\ExtensionNameRequiredException
+     */
+    protected function getConfigurationFromYamlFile(string $extensionName): array
+    {
+        $settings = parent::getConfigurationFromYamlFile($extensionName);
+
+        $otPageRepository = GeneralUtility::makeInstance(ObjectManager::class)->get(OtPageRepository::class);
+        foreach ($otPageRepository->getCurrentBeUserMountpoints() as $rootUid) {
+            $organizationId = $otPageRepository->getPage($rootUid)['tx_opentalent_structure_id'];
+            if ($organizationId) {
+                $settings['persistenceManager']['allowedFileMounts'][] = '1:/form_definitions/' . $organizationId . '/';
+            }
+        }
+
+        return $settings;
+    }
+}

+ 7 - 0
ot_templating/Configuration/TypoScript/setup.txt

@@ -119,6 +119,13 @@ module.tx_form {
         yamlConfigurations {
             100 = EXT:ot_templating/Configuration/Form/CustomFormSetup.yaml
         }
+#        yamlSettingsOverrides {
+#            persistenceManager {
+#                allowedFileMounts {
+#                    10 = 1:/form_definitions/$organizationId
+#                }
+#            }
+#        }
     }
 }
 

+ 5 - 0
ot_templating/ext_localconf.php

@@ -16,3 +16,8 @@ if (!defined('TYPO3_MODE')) {
 );
 
 $GLOBALS['TYPO3_CONF_VARS']['EXT']['news']['Controller/NewsController.php']['createDemandObjectFromSettings'] = ['Opentalent\OtTemplating\News\NewsFilter->createDemandObjectFromSettings'];
+
+// Required to allow the use of multisite with the form extension
+$GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects'][TYPO3\CMS\Form\Mvc\Configuration\ConfigurationManager::class] = [
+    'className' => Opentalent\OtTemplating\XClass\Form\Configuration\ConfigurationManager::class
+];