Skip to content

Commit 28202eb

Browse files
committed
Make component settings work in TYPO3 v13
Component settings based on typoscript must be read from the request. Currently there is no clean way to get the request in the component settings object. ComponentSettings should be refactored but this'll we a breaking change as it requires some major changes like removing the singleton pattern.
1 parent 5a6ec86 commit 28202eb

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

Classes/Utility/ComponentSettings.php

+16-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
use ArrayAccess;
66
use ReturnTypeWillChange;
7+
use TYPO3\CMS\Core\Information\Typo3Version;
78
use TYPO3\CMS\Core\TypoScript\TypoScriptService;
9+
use TYPO3\CMS\Core\Utility\GeneralUtility;
810

911
class ComponentSettings implements \TYPO3\CMS\Core\SingletonInterface, ArrayAccess
1012
{
@@ -23,11 +25,22 @@ public function __construct(protected TypoScriptService $typoScriptService)
2325
*/
2426
public function reset(): void
2527
{
28+
if (GeneralUtility::makeInstance(Typo3Version::class)->getMajorVersion() < 13) {
29+
$typoScriptSettings = $GLOBALS['TSFE']->tmpl->setup['config.']['tx_fluidcomponents.']['settings.'] ?? [];
30+
} else {
31+
// This is only a temporary workaround to get the TypoScript settings from the current request.
32+
// Using the global $GLOBALS['TSFE'] is not the correct way to get the TypoScript settings but for now
33+
// the only without a major refactoring and breaking changes.
34+
// ComponentSettings should not be singeltons.
35+
// ComponentSettings should be refactored to use a factory pattern using a request object to build the
36+
// settings with the correct typoscript from the current request.
37+
// The "reset()" method should be removed then as a "clean" component settings object should always be
38+
// created by the factory.
39+
$typoScriptSettings = $GLOBALS['TYPO3_REQUEST']?->getAttribute('frontend.typoscript')->getSetupArray()['config.']['tx_fluidcomponents.']['settings.'] ?? [];
40+
}
2641
$this->settings = array_merge(
2742
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['fluid_components']['settings'] ?? [],
28-
$this->typoScriptService->convertTypoScriptArrayToPlainArray(
29-
$GLOBALS['TSFE']->tmpl->setup['config.']['tx_fluidcomponents.']['settings.'] ?? []
30-
)
43+
$this->typoScriptService->convertTypoScriptArrayToPlainArray($typoScriptSettings)
3144
);
3245
}
3346

0 commit comments

Comments
 (0)