Skip to content

Commit

Permalink
[TASK] Add Page TsConfig configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian RIVAL committed Nov 10, 2023
1 parent 972f72c commit e69cb2e
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 29 deletions.
36 changes: 31 additions & 5 deletions Classes/Controller/SiteGeneratorController.php
Expand Up @@ -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;
Expand All @@ -37,8 +36,7 @@
/**
* SiteGeneratorController
*/
//class SiteGeneratorController extends ActionController
class SiteGeneratorController extends ActionController
class SiteGeneratorController extends ActionController
{
/**
* The local configuration array
Expand Down Expand Up @@ -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');

Expand All @@ -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
*
Expand Down Expand Up @@ -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();
}
Expand Down
26 changes: 9 additions & 17 deletions Classes/Wizard/SiteGeneratorWizard.php
Expand Up @@ -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
Expand All @@ -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'];
Expand All @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion Classes/Wizard/StateCreateBeGroup.php
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion Classes/Wizard/StateCreateFeGroup.php
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion Classes/Wizard/StateCreateFileMount.php
Expand Up @@ -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);
Expand Down
9 changes: 7 additions & 2 deletions Documentation/Administrators/Index.rst
Expand Up @@ -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
-------------
Expand All @@ -76,3 +80,4 @@ Configuration
TypoScript/Index
ExtensionManager/Index
UpdateTemplate/Index
TSConfig/Index
43 changes: 43 additions & 0 deletions 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
8 changes: 7 additions & 1 deletion Documentation/Administrators/TypoScript/Index.rst
Expand Up @@ -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:

Expand Down Expand Up @@ -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`
2 changes: 1 addition & 1 deletion ext_emconf.php
Expand Up @@ -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'
Expand Down

0 comments on commit e69cb2e

Please sign in to comment.