From 138c9373ff65f9c6fa14d9e30dd8071ed8dc68ac Mon Sep 17 00:00:00 2001 From: Philipp Dieter Date: Wed, 27 Apr 2022 13:28:02 +0200 Subject: [PATCH] [TASK] Enable site config utility to handle references --- Classes/Utility/SiteConfigUtility.php | 18 ++++++++++++++++-- Classes/ViewHelpers/SiteConfigViewHelper.php | 9 ++++++++- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/Classes/Utility/SiteConfigUtility.php b/Classes/Utility/SiteConfigUtility.php index ab88031..76feb6d 100644 --- a/Classes/Utility/SiteConfigUtility.php +++ b/Classes/Utility/SiteConfigUtility.php @@ -15,6 +15,7 @@ namespace Cjel\TemplatesAide\Utility; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface; use TYPO3\CMS\Extbase\Object\ObjectManager; +use TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser; /** * Utility to work with site config @@ -35,20 +36,33 @@ class SiteConfigUtility $objectManager = GeneralUtility::makeInstance( ObjectManager::class ); + $typoScriptParser = GeneralUtility::makeInstance( + TypoScriptParser::class + ); $configurationManager = $objectManager->get( ConfigurationManagerInterface::class ); $typoscript = $configurationManager->getConfiguration( ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT ); - $typoscript = GeneralUtility::removeDotsFromTS($typoscript); $siteConfig = $typoscript; if ($limitToSiteConfig) { - $siteConfig = $typoscript['config']['site']; + $siteConfig = $typoscript['config.']['site.']; } $current = &$siteConfig; foreach ($pathParts as $key) { + if ($current[$key . '.']) { + $key .= '.'; + } $current = &$current[$key]; + if (isset($current[0]) && $current[0] === '<') { + $searchkey = trim(substr($current, 1)); + list($name, $conf) = $typoScriptParser->getVal( + $searchkey, + $typoscript + ); + $current = $conf; + } } if (is_array($current) && array_key_exists('value', $current) diff --git a/Classes/ViewHelpers/SiteConfigViewHelper.php b/Classes/ViewHelpers/SiteConfigViewHelper.php index 3201bd4..1d83ad1 100644 --- a/Classes/ViewHelpers/SiteConfigViewHelper.php +++ b/Classes/ViewHelpers/SiteConfigViewHelper.php @@ -34,6 +34,13 @@ class SiteConfigViewHelper extends AbstractViewHelper 'The config key to get', true ); + $this->registerArgument( + 'siteConfig', + 'bool', + 'Limit the typoscript to the config.site part', + false, + true + ); } /** @@ -51,7 +58,7 @@ class SiteConfigViewHelper extends AbstractViewHelper ) { return SiteConfigUtility::getByPath( $arguments['key'], - false + $arguments['siteConfig'] ); } }