diff --git a/Classes/Controller/SiteGeneratorController.php b/Classes/Controller/SiteGeneratorController.php index 982819e..de6de29 100644 --- a/Classes/Controller/SiteGeneratorController.php +++ b/Classes/Controller/SiteGeneratorController.php @@ -20,12 +20,11 @@ use TYPO3\CMS\Backend\Routing\Exception\RouteNotFoundException; use TYPO3\CMS\Core\Localization\LanguageService; use Psr\Http\Message\ResponseInterface; -use Psr\Http\Message\ServerRequestInterface; use TYPO3\CMS\Core\Imaging\IconFactory; +use TYPO3\CMS\Core\Utility\ArrayUtility; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Backend\Template\Components\ButtonBar; use TYPO3\CMS\Backend\Routing\UriBuilder; -use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface; use TYPO3\CMS\Backend\Utility\BackendUtility; use Oktopuce\SiteGenerator\Wizard\SiteGeneratorWizard; use Oktopuce\SiteGenerator\Domain\Repository\PagesRepository; @@ -37,8 +36,7 @@ /** * SiteGeneratorController */ -//class SiteGeneratorController extends ActionController -class SiteGeneratorController extends ActionController +class SiteGeneratorController extends ActionController { /** * The local configuration array @@ -83,6 +81,8 @@ public function __construct( */ protected function initializeAction() { + $this->overrideSettingsWithPageTsConfig(); + // Get translations $this->getLanguageService()->includeLLFile('EXT:site_generator/Resources/Private/Language/locallang.xlf'); @@ -103,6 +103,32 @@ protected function initializeAction() ]); } + /** + * Settings could be overwritten with Page TsConfig + * + * @return void + */ + protected function overrideSettingsWithPageTsConfig(): void + { + $currentPageId = $this->request->getQueryParams()['id'] ?? 0; + + // Retrieve page TSconfig for current page + $pageTsConfig = BackendUtility::getPagesTSconfig($currentPageId); + $settingsOverrule = GeneralUtility::removeDotsFromTS((array)($pageTsConfig['module.']['tx_sitegenerator.']['settings.'] ?? [])); + + if (!empty($settingsOverrule)) { + if (isset($settingsOverrule['siteGenerator']['wizard']['steps']['clear']) + && (int)$settingsOverrule['siteGenerator']['wizard']['steps']['clear'] === 1) { + // Clear all steps + $clearAllSteps['siteGenerator']['wizard']['steps'] = '__UNSET'; + ArrayUtility::mergeRecursiveWithOverrule($this->settings, $clearAllSteps); + unset($settingsOverrule['siteGenerator']['wizard']['steps']['clear']); + } + // Override settings with settings in Page TsConfig + ArrayUtility::mergeRecursiveWithOverrule($this->settings, $settingsOverrule); + } + } + /** * Store DTO Data from form * @@ -243,7 +269,7 @@ protected function generateSiteAction(): ResponseInterface try { // Start the wizard - $this->siteGeneratorWizard->startWizard($this->siteGeneratorDto); + $this->siteGeneratorWizard->startWizard($this->siteGeneratorDto, $this->settings); } catch (\Exception $e) { $errorMessage = $e->getMessage(); } diff --git a/Classes/Wizard/SiteGeneratorWizard.php b/Classes/Wizard/SiteGeneratorWizard.php index 4611e11..9771656 100644 --- a/Classes/Wizard/SiteGeneratorWizard.php +++ b/Classes/Wizard/SiteGeneratorWizard.php @@ -49,20 +49,6 @@ class SiteGeneratorWizard */ protected array $settings = []; - /** - * Constructor of this class : set first wizard step and store site data from forms - * - * @param ConfigurationManagerInterface $configurationManager - * @throws \Exception - */ - public function __construct(ConfigurationManagerInterface $configurationManager) - { - $this->settings = $configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_SETTINGS, 'SiteGenerator'); - - $this->getStates(); - $this->setNextWizardState(); - } - /** * * Get extension settings from TypoScript @@ -79,7 +65,7 @@ public function getSettings(): array * * @return void */ - public function getStates(): void + protected function getStates(): void { ksort($this->settings['siteGenerator']['wizard']['steps']); self::$states = $this->settings['siteGenerator']['wizard']['steps']; @@ -88,14 +74,20 @@ public function getStates(): void /** * Start site generation wizard - * @param BaseDto $siteData Data coming from forms : mandatory and optional data * + * @param BaseDto $siteData Data coming from forms : mandatory and optional data + * @param array $settings Settings from TypoScript configuration (could have been override with Page TsConfig) * @return void * @throws AspectNotFoundException * @throws \Exception */ - public function startWizard(BaseDto $siteData): void + public function startWizard(BaseDto $siteData, array $settings): void { + $this->settings = $settings; + + $this->getStates(); + $this->setNextWizardState(); + // Set data coming from form $this->siteData = $siteData; diff --git a/Classes/Wizard/StateCreateBeGroup.php b/Classes/Wizard/StateCreateBeGroup.php index 4505ad9..88744c1 100644 --- a/Classes/Wizard/StateCreateBeGroup.php +++ b/Classes/Wizard/StateCreateBeGroup.php @@ -84,7 +84,7 @@ protected function createBeGroup(BaseDto $siteData): int $this->dataHandler->process_datamap(); // Retrieve uid of user group created - $groupId = $this->dataHandler->substNEWwithIDs[$newUniqueId]; + $groupId = $this->dataHandler->substNEWwithIDs[$newUniqueId] ?? 0; if ($groupId > 0) { $this->log(LogLevel::NOTICE, 'Create BE group successful (uid = ' . $groupId); diff --git a/Classes/Wizard/StateCreateFeGroup.php b/Classes/Wizard/StateCreateFeGroup.php index ee3636f..fcd77ee 100644 --- a/Classes/Wizard/StateCreateFeGroup.php +++ b/Classes/Wizard/StateCreateFeGroup.php @@ -70,7 +70,7 @@ protected function createFeGroup(BaseDto $siteData, int $pidFeGroup): int $this->dataHandler->process_datamap(); // Retrieve uid of user group created - $groupId = $this->dataHandler->substNEWwithIDs[$newUniqueId]; + $groupId = $this->dataHandler->substNEWwithIDs[$newUniqueId] ?? 0; if ($groupId > 0) { $this->log(LogLevel::NOTICE, 'Create FE group successful (uid = ' . $groupId); diff --git a/Classes/Wizard/StateCreateFileMount.php b/Classes/Wizard/StateCreateFileMount.php index d821e78..9e59d5c 100644 --- a/Classes/Wizard/StateCreateFileMount.php +++ b/Classes/Wizard/StateCreateFileMount.php @@ -68,7 +68,7 @@ protected function createFileMount(BaseDto $siteData): int $this->dataHandler->process_datamap(); // Retrieve uid of mount point created - $mountId = $this->dataHandler->substNEWwithIDs[$newUniqueId]; + $mountId = $this->dataHandler->substNEWwithIDs[$newUniqueId] ?? 0; if ($mountId > 0) { $this->log(LogLevel::NOTICE, 'Create file mount successfull (uid = ' . $mountId); diff --git a/Documentation/Administrators/Index.rst b/Documentation/Administrators/Index.rst index 37ea1d4..4bad46b 100644 --- a/Documentation/Administrators/Index.rst +++ b/Documentation/Administrators/Index.rst @@ -58,9 +58,13 @@ If you only need Tree Duplication, you can change TypoScript Setup like this : } } -.. Important:: +.. Tip:: - Module TypoScript configuration like :typoscript:`module.tx_sitegenerator` can only be changed through custom extension + Before version 3.1 module TypoScript configuration like :typoscript:`module.tx_sitegenerator` can only be changed through custom extension. + +.. Tip:: + + Since version **3.1** TypoScript configuration (setup only) can also be overridden with :ref:`pagets`. Configuration ------------- @@ -76,3 +80,4 @@ Configuration TypoScript/Index ExtensionManager/Index UpdateTemplate/Index + TSConfig/Index diff --git a/Documentation/Administrators/TSConfig/Index.rst b/Documentation/Administrators/TSConfig/Index.rst new file mode 100644 index 0000000..3760482 --- /dev/null +++ b/Documentation/Administrators/TSConfig/Index.rst @@ -0,0 +1,43 @@ +.. include:: /Includes.rst.txt + +.. _pagets: + +Page TSConfig +============= + +Since version **3.1** TypoScript configuration (setup only) can also be overridden with Page TSConfig. + +The configuration set with Page TSConfig will be merged with default configuration and default values will be overridden. + +Sample +------ + +.. code-block:: typoscript + + module.tx_sitegenerator { + settings { + siteGenerator { + wizard { + # Remove all steps + steps.clear = 1 + steps { + 10 = Oktopuce\SiteGenerator\Wizard\StateCopyModelSite + 20 = Oktopuce\SiteGenerator\Wizard\StateUpdateHomePage + 30 = Oktopuce\SiteGenerator\Wizard\StateUpdateTemplateHP + 40 = Oktopuce\SiteGenerator\Wizard\StateUpdatePageTs + 50 = Oktopuce\SiteGenerator\Wizard\StateUpdateSlugs + } + formDto = Oktopuce\SiteGeneratorCustomized\Dto\SiteGeneratorDto + } + } + } + } + +.. Tip:: + Note the use of **steps.clear** to remove all step already defined through TypoScript + +You can also override the backend templates with Page TSConfig : + +.. code-block:: typoscript + + templates.oktopuce/site-generator.templateRootPaths = oktopuce/site-generator:../site_generator_customized/Resources/Private/OtherTemplates diff --git a/Documentation/Administrators/TypoScript/Index.rst b/Documentation/Administrators/TypoScript/Index.rst index 730411d..fa3c984 100644 --- a/Documentation/Administrators/TypoScript/Index.rst +++ b/Documentation/Administrators/TypoScript/Index.rst @@ -7,7 +7,7 @@ TypoScript Here you can find the module configuration available in TypoScript. -Any setting needs to be prefixed with :typoscript:`module.tx_sitegenerator.settings.siteGenerator.wizard.`. +Any setting needs to be prefixed with :typoscript:`module.tx_sitegenerator.settings.siteGenerator.wizard.` .. _formDto: @@ -84,3 +84,9 @@ hideHomePage Description Set this to '1' if you want to set home page as hidden + +.. New:: + Since version 3.1 TypoScript configuration (setup only) can also be overridden with Page TSConfig + +.. seealso:: + * :ref:`pagets` diff --git a/ext_emconf.php b/ext_emconf.php index 784e2d8..f6219e3 100644 --- a/ext_emconf.php +++ b/ext_emconf.php @@ -11,7 +11,7 @@ 'author' => 'Florian Rival', 'author_email' => 'florian.typo3@oktopuce.fr', 'state' => 'stable', - 'version' => '3.0.0', + 'version' => '3.1.0', 'constraints' => [ 'depends' => [ 'typo3' => '12.4.0-12.4.99'