From 8196593f0745051daaa00f7773f36aa3b94178bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stig=20N=C3=B8rgaard=20F=C3=A6rch?= Date: Mon, 3 Jan 2022 11:08:11 +0100 Subject: [PATCH 1/5] [FEATURE] Add support for groupHomePath feature --- .../Controller/SiteGeneratorController.php | 3 +- Classes/Dto/SiteGeneratorDto.php | 23 +++++++++++ Classes/Wizard/StateBase.php | 5 +++ Classes/Wizard/StateCreateFileMount.php | 10 +++-- Classes/Wizard/StateCreateFolder.php | 38 ++++++++++++++----- Configuration/Services.yaml | 4 ++ Configuration/TypoScript/setup.typoscript | 1 + Resources/Private/Language/fr.locallang.xlf | 4 ++ Resources/Private/Language/locallang.xlf | 3 ++ .../SiteGenerator/GetDataSecondStep.html | 27 ++++++++----- ext_conf_template.txt | 3 ++ 11 files changed, 99 insertions(+), 22 deletions(-) diff --git a/Classes/Controller/SiteGeneratorController.php b/Classes/Controller/SiteGeneratorController.php index 31ce65a..8629ad6 100644 --- a/Classes/Controller/SiteGeneratorController.php +++ b/Classes/Controller/SiteGeneratorController.php @@ -102,9 +102,9 @@ public function __construct( ConfigurationManagerInterface $configurationManager, SiteGeneratorWizard $siteGeneratorWizard ) { + // Get translations $this->getLanguageService()->includeLLFile('EXT:site_generator/Resources/Private/Language/locallang.xlf'); - $this->configurationManager = $configurationManager; $this->settings = $this->configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_SETTINGS, 'SiteGenerator'); @@ -163,6 +163,7 @@ public function storeDtoData(): void $this->siteGeneratorDto->setCommonMountPointUid((int) $this->getExtensionConfiguration('commonMountPointUid')); $this->siteGeneratorDto->setBaseFolderName($this->getExtensionConfiguration('baseFolderName')); $this->siteGeneratorDto->setSubFolderNames($this->getExtensionConfiguration('subFolderNames')); + $this->siteGeneratorDto->setSiteFolderNameSource($this->getExtensionConfiguration('siteFolderName')); } } diff --git a/Classes/Dto/SiteGeneratorDto.php b/Classes/Dto/SiteGeneratorDto.php index 3eee034..648715a 100644 --- a/Classes/Dto/SiteGeneratorDto.php +++ b/Classes/Dto/SiteGeneratorDto.php @@ -63,6 +63,13 @@ class SiteGeneratorDto extends BaseDto */ protected $baseFolderName = ''; + /** + * Folder name + * + * @var string + */ + protected $siteFolderNameSource = ''; + /** * Sub folder names * @@ -190,6 +197,22 @@ public function getBaseFolderName(): string return $this->baseFolderName; } + /** + * @return string + */ + public function getSiteFolderNameSource(): string + { + return $this->siteFolderNameSource; + } + + /** + * @param string $siteFolderNameSource + */ + public function setSiteFolderNameSource(string $siteFolderNameSource): void + { + $this->siteFolderNameSource = $siteFolderNameSource; + } + /** * Set commonMountPointUid * diff --git a/Classes/Wizard/StateBase.php b/Classes/Wizard/StateBase.php index 52bb5f6..9a77641 100644 --- a/Classes/Wizard/StateBase.php +++ b/Classes/Wizard/StateBase.php @@ -68,4 +68,9 @@ public function getExtensionConfiguration(): array { return ($this->extensionConfiguration == null ? $GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['site_generator'] : []); } + + public function getSiteFolderName(): string + { + return $this->getExtensionConfiguration()['siteFolderName'] ?? 'siteTitle'; + } } diff --git a/Classes/Wizard/StateCreateFileMount.php b/Classes/Wizard/StateCreateFileMount.php index c03b922..0b63520 100644 --- a/Classes/Wizard/StateCreateFileMount.php +++ b/Classes/Wizard/StateCreateFileMount.php @@ -31,10 +31,14 @@ class StateCreateFileMount extends StateBase implements SiteGeneratorStateInterf */ public function process(SiteGeneratorWizard $context): void { - // Create file mount for site - $mountId = $this->createFileMount($context->getSiteData()); + if($this->getSiteFolderName() == 'siteTitle') { - $context->getSiteData()->setMountId($mountId); + // Create file mount for site + $mountId = $this->createFileMount($context->getSiteData()); + + $context->getSiteData()->setMountId($mountId); + + } } /** diff --git a/Classes/Wizard/StateCreateFolder.php b/Classes/Wizard/StateCreateFolder.php index be97b1b..1f75889 100644 --- a/Classes/Wizard/StateCreateFolder.php +++ b/Classes/Wizard/StateCreateFolder.php @@ -30,6 +30,8 @@ class StateCreateFolder extends StateBase implements SiteGeneratorStateInterface */ private $resourceFactory; + private string $folderName; + public function __construct(ResourceFactory $resourceFactory) { parent::__construct(); @@ -41,13 +43,32 @@ public function __construct(ResourceFactory $resourceFactory) * * @param SiteGeneratorWizard $context * @return void + * @throws \Exception */ public function process(SiteGeneratorWizard $context): void { + $siteData = $context->getSiteData(); $settings = $context->getSettings(); - - // Create folders in storage - $this->createFolders($context->getSiteData(), (int)$settings['siteGenerator']['wizard']['storageUid']); + $storageUid = (int)$settings['siteGenerator']['wizard']['storageUid']; + if(get_class($this) == 'Oktopuce\SiteGenerator\Wizard\StateCreateGroupHomeFolder' && $this->getSiteFolderName() == 'userGroupUid' ) { + $groupHomePathData = explode(':', $GLOBALS['TYPO3_CONF_VARS']['BE']['groupHomePath']); + if (count($groupHomePathData) === 2 && is_numeric($groupHomePathData[0])) { + $storageUid = $groupHomePathData[0]; + $siteData->setBaseFolderName(trim($groupHomePathData[1], '/')); + } else { + throw new \Exception('The extension configuration siteFolderName was set to userGroupUid, but the Installation-Wide Option [BE][groupHomePath] was not configured correctly. Should be a combined folder identifier. Eg. 2:groups/'); + } + if ($siteData->getBeGroupId()) { + $this->folderName = (string)$siteData->getBeGroupId(); + } else { + throw new \Exception('The extension configuration siteFolderName was set to userGroupUid, but the usergroup uid was not found. Please check order of the states. StateCreateBeGroup should come before StateCreateGroupHomeFolder.'); + } + } else if(get_class($this) == 'Oktopuce\SiteGenerator\Wizard\StateCreateFolder' && $this->getSiteFolderName() == 'siteTitle') { + $this->folderName = strtolower($siteData->getTitleSanitize()); + } + if(isset($this->folderName)) { + $this->createFolders($siteData, (int)$storageUid); + } } /** @@ -83,16 +104,15 @@ protected function createFolders(BaseDto $siteData, int $storageUid): void } } - // Create site folder from site title - $newFolder = strtolower($siteData->getTitleSanitize()); - $currentFolder .= '/' . $newFolder; - if (!$storage->hasFolderInFolder($newFolder, $baseFolder)) { + // Create site folder + $currentFolder .= '/' . $this->folderName; + if (!$storage->hasFolderInFolder($this->folderName, $baseFolder)) { // Create sub-folder for current site - $siteFolder = $storage->createFolder($newFolder, $baseFolder); + $siteFolder = $storage->createFolder($this->folderName, $baseFolder); // @extensionScannerIgnoreLine $siteData->addMessage($this->translate('generate.success.folderCreated', [$currentFolder])); } else { - $siteFolder = $storage->getFolderInFolder($newFolder, $baseFolder); + $siteFolder = $storage->getFolderInFolder($this->folderName, $baseFolder); // @extensionScannerIgnoreLine $siteData->addMessage($this->translate('generate.success.folderExist', [$currentFolder])); } diff --git a/Configuration/Services.yaml b/Configuration/Services.yaml index 8a9b476..609be0d 100644 --- a/Configuration/Services.yaml +++ b/Configuration/Services.yaml @@ -11,6 +11,10 @@ services: public: true shared: false + Oktopuce\SiteGenerator\Wizard\StateCreateGroupHomeFolder: + public: true + shared: false + Oktopuce\SiteGenerator\Hook\BackendControllerHook: public: true shared: false diff --git a/Configuration/TypoScript/setup.typoscript b/Configuration/TypoScript/setup.typoscript index 6af760f..482c918 100644 --- a/Configuration/TypoScript/setup.typoscript +++ b/Configuration/TypoScript/setup.typoscript @@ -23,6 +23,7 @@ module.tx_sitegenerator { 30 = Oktopuce\SiteGenerator\Wizard\StateCreateFileMount 40 = Oktopuce\SiteGenerator\Wizard\StateCreateFeGroup 50 = Oktopuce\SiteGenerator\Wizard\StateCreateBeGroup + 55 = Oktopuce\SiteGenerator\Wizard\StateCreateGroupHomeFolder 60 = Oktopuce\SiteGenerator\Wizard\StateSetPageBeGroup 70 = Oktopuce\SiteGenerator\Wizard\StateSiteConfiguration 80 = Oktopuce\SiteGenerator\Wizard\StateUpdateHomePage diff --git a/Resources/Private/Language/fr.locallang.xlf b/Resources/Private/Language/fr.locallang.xlf index 9caa4eb..1eca536 100644 --- a/Resources/Private/Language/fr.locallang.xlf +++ b/Resources/Private/Language/fr.locallang.xlf @@ -46,6 +46,10 @@ New folders will be created in fileadmin like : "baseFolderName > Titre du site > SubFolderName" De nouveaux dossiers seront créés dans fileadmin comme : "baseFolderName > Site Name > SubFolderName" + + New folders will be created in fileadmin like : "groupHomePath > User group uid > SubFolderName" + De nouveaux dossiers seront créés dans fileadmin comme : "groupHomePath > User group uid > SubFolderName" + Base folder name Nom du dossier de base diff --git a/Resources/Private/Language/locallang.xlf b/Resources/Private/Language/locallang.xlf index 3f8b367..ae75586 100644 --- a/Resources/Private/Language/locallang.xlf +++ b/Resources/Private/Language/locallang.xlf @@ -36,6 +36,9 @@ New folders will be created in fileadmin like : "baseFolderName > Site title > SubFolderName" + + New folders will be created in fileadmin like : "groupHomePath > User group uid > SubFolderName" + Base folder name diff --git a/Resources/Private/Templates/SiteGenerator/GetDataSecondStep.html b/Resources/Private/Templates/SiteGenerator/GetDataSecondStep.html index 24adaf8..b09b9a2 100644 --- a/Resources/Private/Templates/SiteGenerator/GetDataSecondStep.html +++ b/Resources/Private/Templates/SiteGenerator/GetDataSecondStep.html @@ -39,15 +39,24 @@

-
- -
-
- -
- -
-
+ + +
+ +
+
+ +
+ +
+
+
+ +
+ +
+
+
diff --git a/ext_conf_template.txt b/ext_conf_template.txt index b8cdb1a..29548e9 100644 --- a/ext_conf_template.txt +++ b/ext_conf_template.txt @@ -30,6 +30,9 @@ groupPrefix = Group # cat=Folder/140/10_BaseFolderName; type=string; label=Site base folder: The name for sites base folder (can be overridden in form) baseFolderName = Website +# cat=Folder/140/10_SiteFolder; type=options[Website title=siteTitle,Backend usergroup uid=userGroupUid]; label=Site folder: The name for site folder. Site title or group uid for used with grouphomepath feature. +siteFolderName = siteTitle + # cat=Folder/140/10_SubFolderNames; type=string; label=Sub-folders to create: The names of the sub-folders to create (comma separated, can be overridden in form) subFolderNames = documents,images From 738d9c060b97eb2d7b9d8a9ebb5ac85585938754 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stig=20N=C3=B8rgaard=20F=C3=A6rch?= Date: Mon, 3 Jan 2022 13:47:32 +0100 Subject: [PATCH 2/5] [TASK] Add missing wizard state --- Classes/Wizard/StateCreateGroupHomeFolder.php | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 Classes/Wizard/StateCreateGroupHomeFolder.php diff --git a/Classes/Wizard/StateCreateGroupHomeFolder.php b/Classes/Wizard/StateCreateGroupHomeFolder.php new file mode 100644 index 0000000..4814c41 --- /dev/null +++ b/Classes/Wizard/StateCreateGroupHomeFolder.php @@ -0,0 +1,7 @@ + Date: Mon, 3 Jan 2022 16:53:55 +0100 Subject: [PATCH 3/5] [TASK] Refactor to support combined identifier for StateCreateBeGroup --- Classes/Wizard/StateBase.php | 79 +++++++++++++++++++++++++++ Classes/Wizard/StateCreateBeGroup.php | 23 ++++++-- Classes/Wizard/StateCreateFolder.php | 46 +++++----------- 3 files changed, 111 insertions(+), 37 deletions(-) diff --git a/Classes/Wizard/StateBase.php b/Classes/Wizard/StateBase.php index 9a77641..7b09844 100644 --- a/Classes/Wizard/StateBase.php +++ b/Classes/Wizard/StateBase.php @@ -13,6 +13,7 @@ namespace Oktopuce\SiteGenerator\Wizard; +use Oktopuce\SiteGenerator\Dto\BaseDto; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Core\Log\LogManager; use TYPO3\CMS\Extbase\Utility\LocalizationUtility; @@ -73,4 +74,82 @@ public function getSiteFolderName(): string { return $this->getExtensionConfiguration()['siteFolderName'] ?? 'siteTitle'; } + + /** + * @return mixed|string + * @throws \Exception + */ + protected function getStorageUidFromGroupHomePath() { + return $this->getGroupHomePathArray()[0]; + } + + /** + * @return mixed|string + * @throws \Exception + */ + protected function getFolderFromGroupHomePath() { + return trim($this->getGroupHomePathArray()[1], '/'); + } + + /** + * @return false|string[] + * @throws \Exception + */ + protected function getGroupHomePathArray() { + $groupHomePathArray = explode(':', $GLOBALS['TYPO3_CONF_VARS']['BE']['groupHomePath']); + if (count($groupHomePathArray) === 2 && is_numeric($groupHomePathArray[0])) { + return $groupHomePathArray; + } else { + throw new \Exception('The Installation-Wide Option [BE][groupHomePath] was not configured correctly. Should be a combined folder identifier. Eg. 2:groups/'); + } + } + + /** + * @param $siteData + * @return string + * @throws \Exception + */ + public function getSiteFolder($siteData) { + if($this->getSiteFolderName() === 'userGroupUid') { + if($siteData->getBeGroupId()) { + return (string) $siteData->getBeGroupId(); + } else { + throw new \Exception('The extension configuration siteFolderName was set to userGroupUid, but the usergroup uid was not found. Please check order of the states. StateCreateBeGroup should come before StateCreateGroupHomeFolder.'); + } + } else { + return strtolower($siteData->getTitleSanitize()); + } + } + + public function getBaseFolderName(BaseDto $siteData) { + if($this->getSiteFolderName() === 'userGroupUid') { + return $this->getFolderFromGroupHomePath(); + } else { + return $siteData->getBaseFolderName(); + } + } + + /** + * @param SiteGeneratorWizard $context + * @return int|void + * @throws \Exception + */ + public function getStorageUid(SiteGeneratorWizard $context) { + if($this->getSiteFolderName() === 'userGroupUid') { + return $this->getStorageUidFromGroupHomePath(); + } else { + $settings = $context->getSettings(); + return (int)$settings['siteGenerator']['wizard']['storageUid']; + } + } + + /** + * @param SiteGeneratorWizard $context + * @return string + * @throws \Exception + */ + public function getSiteFolderCombinedIdentifier(SiteGeneratorWizard $context) { + $siteData = $context->getSiteData(); + return $this->getStorageUid($context) . ':' . $this->getBaseFolderName($siteData) . '/' . $this->getSiteFolder($siteData) . '/'; + } } diff --git a/Classes/Wizard/StateCreateBeGroup.php b/Classes/Wizard/StateCreateBeGroup.php index 31a21d4..de2dafd 100644 --- a/Classes/Wizard/StateCreateBeGroup.php +++ b/Classes/Wizard/StateCreateBeGroup.php @@ -32,20 +32,21 @@ class StateCreateBeGroup extends StateBase implements SiteGeneratorStateInterfac public function process(SiteGeneratorWizard $context): void { // Create BE group - $groupId = $this->createBeGroup($context->getSiteData()); - - $context->getSiteData()->setBeGroupId($groupId); + $groupId = $this->createBeGroup($context); } /** * Create BE group with file mount, DB mount, access lists * - * @param BaseDto $siteData New site data + * @param SiteGeneratorWizard $context * @throws \Exception * @return int The uid of the group created */ - protected function createBeGroup(BaseDto $siteData): int + protected function createBeGroup(SiteGeneratorWizard $context): int { + // New site data + $siteData = $context->getSiteData(); + // Get extension configuration $extensionConfiguration = $this->getExtensionConfiguration(); @@ -61,7 +62,7 @@ protected function createBeGroup(BaseDto $siteData): int 'tables_select' => ($extensionConfiguration['tablesSelect'] ?: null), 'tables_modify' => ($extensionConfiguration['tablesModify'] ?: null), 'explicit_allowdeny' => ($extensionConfiguration['explicitAllowdeny'] ?: null), - 'TSconfig' => 'options.defaultUploadFolder = 1:' . ($siteData->getBaseFolderName() ? $siteData->getBaseFolderName() . '/' : '') . strtolower($siteData->getTitleSanitize()) . '/' +// 'TSconfig' => 'options.defaultUploadFolder = 1:' . ($siteData->getBaseFolderName() ? $siteData->getBaseFolderName() . '/' : '') . strtolower($siteData->getTitleSanitize()) . '/' ]; // Set common mountpoint @@ -83,6 +84,16 @@ protected function createBeGroup(BaseDto $siteData): int // Retrieve uid of user group created $groupId = $tce->substNEWwithIDs[$newUniqueId]; + // Update the TSconfig field + $context->getSiteData()->setBeGroupId($groupId); + unset($data); + $data['be_groups'][$groupId] = [ + 'TSconfig' => 'options.defaultUploadFolder = ' . $this->getSiteFolderCombinedIdentifier($context) + ]; + $tce->start($data, []); + $tce->process_datamap(); + + if ($groupId > 0) { $this->log(LogLevel::NOTICE, 'Create BE group successful (uid = ' . $groupId); // @extensionScannerIgnoreLine diff --git a/Classes/Wizard/StateCreateFolder.php b/Classes/Wizard/StateCreateFolder.php index 1f75889..39f7105 100644 --- a/Classes/Wizard/StateCreateFolder.php +++ b/Classes/Wizard/StateCreateFolder.php @@ -19,6 +19,7 @@ use TYPO3\CMS\Core\Resource\ResourceFactory; use TYPO3\CMS\Core\Log\LogLevel; use Oktopuce\SiteGenerator\Dto\BaseDto; +use function Symfony\Component\String\s; /** * StateCreateFolder @@ -42,32 +43,14 @@ public function __construct(ResourceFactory $resourceFactory) * Create site folder in fileadmin : base Folder / site title / sub folder * * @param SiteGeneratorWizard $context - * @return void * @throws \Exception */ public function process(SiteGeneratorWizard $context): void { - $siteData = $context->getSiteData(); - $settings = $context->getSettings(); - $storageUid = (int)$settings['siteGenerator']['wizard']['storageUid']; - if(get_class($this) == 'Oktopuce\SiteGenerator\Wizard\StateCreateGroupHomeFolder' && $this->getSiteFolderName() == 'userGroupUid' ) { - $groupHomePathData = explode(':', $GLOBALS['TYPO3_CONF_VARS']['BE']['groupHomePath']); - if (count($groupHomePathData) === 2 && is_numeric($groupHomePathData[0])) { - $storageUid = $groupHomePathData[0]; - $siteData->setBaseFolderName(trim($groupHomePathData[1], '/')); - } else { - throw new \Exception('The extension configuration siteFolderName was set to userGroupUid, but the Installation-Wide Option [BE][groupHomePath] was not configured correctly. Should be a combined folder identifier. Eg. 2:groups/'); - } - if ($siteData->getBeGroupId()) { - $this->folderName = (string)$siteData->getBeGroupId(); - } else { - throw new \Exception('The extension configuration siteFolderName was set to userGroupUid, but the usergroup uid was not found. Please check order of the states. StateCreateBeGroup should come before StateCreateGroupHomeFolder.'); - } - } else if(get_class($this) == 'Oktopuce\SiteGenerator\Wizard\StateCreateFolder' && $this->getSiteFolderName() == 'siteTitle') { - $this->folderName = strtolower($siteData->getTitleSanitize()); - } - if(isset($this->folderName)) { - $this->createFolders($siteData, (int)$storageUid); + // Create folders in storage + if ((get_class($this) == 'Oktopuce\SiteGenerator\Wizard\StateCreateGroupHomeFolder' && $this->getSiteFolderName() == 'userGroupUid') or + (get_class($this) == 'Oktopuce\SiteGenerator\Wizard\StateCreateFolder' && $this->getSiteFolderName() == 'siteTitle')) { + $this->createFolders($context->getSiteData(), $context); } } @@ -75,18 +58,18 @@ public function process(SiteGeneratorWizard $context): void * Create folder "fileadmin/base_folder/sites_title", with sub-folders "documents" and "images" * * @param BaseDto $siteData New site data - * @param int $storageUid The uid of storage to use + * @param SiteGeneratorWizard $context The uid of storage to use * @throws \Exception * * @return void */ - protected function createFolders(BaseDto $siteData, int $storageUid): void + protected function createFolders(BaseDto $siteData, SiteGeneratorWizard $context): void { // Get base folder and sub-folders name to create - $baseFolderName = $siteData->getBaseFolderName(); + $baseFolderName = $this->getBaseFolderName($siteData); $subFolderNames = GeneralUtility::trimExplode(',', $siteData->getSubFolderNames(), true); - if ($storageUid) { + if ($storageUid = $this->getStorageUid($context)) { $storage = $this->resourceFactory->getStorageObject($storageUid); try { @@ -104,15 +87,16 @@ protected function createFolders(BaseDto $siteData, int $storageUid): void } } - // Create site folder - $currentFolder .= '/' . $this->folderName; - if (!$storage->hasFolderInFolder($this->folderName, $baseFolder)) { + // Create site folder from site title + $newFolder = $this->getSiteFolder($siteData); + $currentFolder .= '/' . $newFolder; + if (!$storage->hasFolderInFolder($newFolder, $baseFolder)) { // Create sub-folder for current site - $siteFolder = $storage->createFolder($this->folderName, $baseFolder); + $siteFolder = $storage->createFolder($newFolder, $baseFolder); // @extensionScannerIgnoreLine $siteData->addMessage($this->translate('generate.success.folderCreated', [$currentFolder])); } else { - $siteFolder = $storage->getFolderInFolder($this->folderName, $baseFolder); + $siteFolder = $storage->getFolderInFolder($newFolder, $baseFolder); // @extensionScannerIgnoreLine $siteData->addMessage($this->translate('generate.success.folderExist', [$currentFolder])); } From c81d5008f5164718328d51fafe6374f3ab1fa58e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stig=20N=C3=B8rgaard=20F=C3=A6rch?= Date: Mon, 3 Jan 2022 18:14:54 +0100 Subject: [PATCH 4/5] [TASK] Refactor. Add userGroupHome checkbox on second step. --- .../Controller/SiteGeneratorController.php | 5 ++- Classes/Dto/SiteGeneratorDto.php | 43 +++++++++---------- Classes/Wizard/StateBase.php | 11 ++--- Classes/Wizard/StateCreateFileMount.php | 2 +- Classes/Wizard/StateCreateFolder.php | 7 +-- Resources/Private/Layouts/Default.html | 1 + .../SiteGenerator/GetDataSecondStep.html | 27 +++++++++--- Resources/Public/Css/Style.css | 15 +++++++ 8 files changed, 69 insertions(+), 42 deletions(-) create mode 100644 Resources/Public/Css/Style.css diff --git a/Classes/Controller/SiteGeneratorController.php b/Classes/Controller/SiteGeneratorController.php index 8629ad6..ba223cb 100644 --- a/Classes/Controller/SiteGeneratorController.php +++ b/Classes/Controller/SiteGeneratorController.php @@ -163,7 +163,6 @@ public function storeDtoData(): void $this->siteGeneratorDto->setCommonMountPointUid((int) $this->getExtensionConfiguration('commonMountPointUid')); $this->siteGeneratorDto->setBaseFolderName($this->getExtensionConfiguration('baseFolderName')); $this->siteGeneratorDto->setSubFolderNames($this->getExtensionConfiguration('subFolderNames')); - $this->siteGeneratorDto->setSiteFolderNameSource($this->getExtensionConfiguration('siteFolderName')); } } @@ -318,12 +317,16 @@ protected function getDataSecondStepAction(): string { $nextStep = $this->buildUriFromRoute('wizard_sitegenerator'); + $groupHomePathArray = explode(':', $GLOBALS['TYPO3_CONF_VARS']['BE']['groupHomePath']); + $groupHomePathValid = count($groupHomePathArray) === 2 && is_numeric($groupHomePathArray[0]); + $viewVariables = [ 'moduleUrl' => $nextStep, 'siteDto' => $this->siteGeneratorDto, 'siteDtoSaved' => json_encode(serialize($this->siteGeneratorDto)), 'action' => 'generate_site', 'returnurl' => $this->conf['returnurl'], + 'groupHomePathValid' => $groupHomePathValid ]; // Add event to assign more variables to the view (usefull when using your own template) diff --git a/Classes/Dto/SiteGeneratorDto.php b/Classes/Dto/SiteGeneratorDto.php index 648715a..a48b896 100644 --- a/Classes/Dto/SiteGeneratorDto.php +++ b/Classes/Dto/SiteGeneratorDto.php @@ -63,13 +63,6 @@ class SiteGeneratorDto extends BaseDto */ protected $baseFolderName = ''; - /** - * Folder name - * - * @var string - */ - protected $siteFolderNameSource = ''; - /** * Sub folder names * @@ -91,6 +84,11 @@ class SiteGeneratorDto extends BaseDto */ protected $feGroupPid = 0; + /** + * @var bool + */ + protected $groupHomePath = false; + /** * Domain * @@ -197,22 +195,6 @@ public function getBaseFolderName(): string return $this->baseFolderName; } - /** - * @return string - */ - public function getSiteFolderNameSource(): string - { - return $this->siteFolderNameSource; - } - - /** - * @param string $siteFolderNameSource - */ - public function setSiteFolderNameSource(string $siteFolderNameSource): void - { - $this->siteFolderNameSource = $siteFolderNameSource; - } - /** * Set commonMountPointUid * @@ -297,4 +279,19 @@ public function getFeGroupPid(): int return $this->feGroupPid; } + /** + * @return bool + */ + public function getGroupHomePath(): bool + { + return $this->groupHomePath; + } + + /** + * @param bool $groupHomePath + */ + public function setGroupHomePath(bool $groupHomePath): void + { + $this->groupHomePath = $groupHomePath; + } } diff --git a/Classes/Wizard/StateBase.php b/Classes/Wizard/StateBase.php index 7b09844..fa18b2c 100644 --- a/Classes/Wizard/StateBase.php +++ b/Classes/Wizard/StateBase.php @@ -70,11 +70,6 @@ public function getExtensionConfiguration(): array return ($this->extensionConfiguration == null ? $GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['site_generator'] : []); } - public function getSiteFolderName(): string - { - return $this->getExtensionConfiguration()['siteFolderName'] ?? 'siteTitle'; - } - /** * @return mixed|string * @throws \Exception @@ -110,7 +105,7 @@ protected function getGroupHomePathArray() { * @throws \Exception */ public function getSiteFolder($siteData) { - if($this->getSiteFolderName() === 'userGroupUid') { + if($siteData->getGroupHomePath()) { if($siteData->getBeGroupId()) { return (string) $siteData->getBeGroupId(); } else { @@ -122,7 +117,7 @@ public function getSiteFolder($siteData) { } public function getBaseFolderName(BaseDto $siteData) { - if($this->getSiteFolderName() === 'userGroupUid') { + if($siteData->getGroupHomePath()) { return $this->getFolderFromGroupHomePath(); } else { return $siteData->getBaseFolderName(); @@ -135,7 +130,7 @@ public function getBaseFolderName(BaseDto $siteData) { * @throws \Exception */ public function getStorageUid(SiteGeneratorWizard $context) { - if($this->getSiteFolderName() === 'userGroupUid') { + if($context->getSiteData()->getGroupHomePath()) { return $this->getStorageUidFromGroupHomePath(); } else { $settings = $context->getSettings(); diff --git a/Classes/Wizard/StateCreateFileMount.php b/Classes/Wizard/StateCreateFileMount.php index 0b63520..4c6cb39 100644 --- a/Classes/Wizard/StateCreateFileMount.php +++ b/Classes/Wizard/StateCreateFileMount.php @@ -31,7 +31,7 @@ class StateCreateFileMount extends StateBase implements SiteGeneratorStateInterf */ public function process(SiteGeneratorWizard $context): void { - if($this->getSiteFolderName() == 'siteTitle') { + if(!$context->getSiteData()->getGroupHomePath()) { // Create file mount for site $mountId = $this->createFileMount($context->getSiteData()); diff --git a/Classes/Wizard/StateCreateFolder.php b/Classes/Wizard/StateCreateFolder.php index 39f7105..71f77a9 100644 --- a/Classes/Wizard/StateCreateFolder.php +++ b/Classes/Wizard/StateCreateFolder.php @@ -47,10 +47,11 @@ public function __construct(ResourceFactory $resourceFactory) */ public function process(SiteGeneratorWizard $context): void { + $siteData = $context->getSiteData(); // Create folders in storage - if ((get_class($this) == 'Oktopuce\SiteGenerator\Wizard\StateCreateGroupHomeFolder' && $this->getSiteFolderName() == 'userGroupUid') or - (get_class($this) == 'Oktopuce\SiteGenerator\Wizard\StateCreateFolder' && $this->getSiteFolderName() == 'siteTitle')) { - $this->createFolders($context->getSiteData(), $context); + if ((get_class($this) == 'Oktopuce\SiteGenerator\Wizard\StateCreateGroupHomeFolder' && $siteData->getGroupHomePath()) or + (get_class($this) == 'Oktopuce\SiteGenerator\Wizard\StateCreateFolder' && !$siteData->getGroupHomePath())) { + $this->createFolders($siteData, $context); } } diff --git a/Resources/Private/Layouts/Default.html b/Resources/Private/Layouts/Default.html index dae43d7..5fbf133 100644 --- a/Resources/Private/Layouts/Default.html +++ b/Resources/Private/Layouts/Default.html @@ -1,3 +1,4 @@ +
diff --git a/Resources/Private/Templates/SiteGenerator/GetDataSecondStep.html b/Resources/Private/Templates/SiteGenerator/GetDataSecondStep.html index b09b9a2..90c401e 100644 --- a/Resources/Private/Templates/SiteGenerator/GetDataSecondStep.html +++ b/Resources/Private/Templates/SiteGenerator/GetDataSecondStep.html @@ -39,8 +39,28 @@

- + +
+ + +
+ +
+
+
+ +
+
+ +
+ +
+
+
+
+
+
@@ -50,11 +70,6 @@

- - -
- -
diff --git a/Resources/Public/Css/Style.css b/Resources/Public/Css/Style.css new file mode 100644 index 0000000..66cf4b9 --- /dev/null +++ b/Resources/Public/Css/Style.css @@ -0,0 +1,15 @@ +body { + background: black!important; +} +input[name="tx_sitegenerator[groupHomePath]"]:checked ~ .siteFolder-groupHomePath { + display:block; +} +input[name="tx_sitegenerator[groupHomePath]"]:checked ~ .siteFolder-siteTitle { + display:none; +} +input[name="tx_sitegenerator[groupHomePath]"] ~ .siteFolder-groupHomePath { + display:none; +} +input[name="tx_sitegenerator[groupHomePath]"] ~ .siteFolder-siteTitle { + display:block; +} From 5955760c5daa58174bfd2d987bc76224c324fae5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stig=20N=C3=B8rgaard=20F=C3=A6rch?= Date: Tue, 4 Jan 2022 13:55:10 +0100 Subject: [PATCH 5/5] [TASK] Set mountId siteData when groupHomePath is used. --- Classes/Wizard/StateCreateFileMount.php | 29 ++++++++++++++++++++---- Resources/Private/Language/locallang.xlf | 3 +++ 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/Classes/Wizard/StateCreateFileMount.php b/Classes/Wizard/StateCreateFileMount.php index 4c6cb39..c56a426 100644 --- a/Classes/Wizard/StateCreateFileMount.php +++ b/Classes/Wizard/StateCreateFileMount.php @@ -28,17 +28,38 @@ class StateCreateFileMount extends StateBase implements SiteGeneratorStateInterf * * @param SiteGeneratorWizard $context * @return void - */ + * @throws \Exception + */ public function process(SiteGeneratorWizard $context): void { - if(!$context->getSiteData()->getGroupHomePath()) { - + if($context->getSiteData()->getGroupHomePath()) { + // Get file mount id from global 'groupHomePath' + $mountId = $this->getFromHomePath(); + } else { // Create file mount for site $mountId = $this->createFileMount($context->getSiteData()); + } + + $context->getSiteData()->setMountId($mountId); + } - $context->getSiteData()->setMountId($mountId); + /** + * Get file mount id from global 'groupHomePath' + * + * @throws \Exception + * @return int The uid from the groupHomePath + */ + protected function getFromHomePath(): int + { + // Get mount id from global 'groupHomePath' + [$groupHomeStorageUid, $groupHomeFilter] = explode(':', $GLOBALS['TYPO3_CONF_VARS']['BE']['groupHomePath'], 2); + if ((int)$groupHomeStorageUid <= 0 || is_null($groupHomeFilter)) { + $this->log(LogLevel::ERROR, 'Create file mount error. The groupHomePath is not valid.'); + throw new \Exception($this->translate('wizard.fileMount.error.groupHomePathNotValid')); } + + return (int)$groupHomeStorageUid; } /** diff --git a/Resources/Private/Language/locallang.xlf b/Resources/Private/Language/locallang.xlf index ae75586..a563b3b 100644 --- a/Resources/Private/Language/locallang.xlf +++ b/Resources/Private/Language/locallang.xlf @@ -115,6 +115,9 @@ Create file mount error. + + Create file mount error. The groupHomePath is not valid. + Directory creation error for "%s".