Bug #98081
closedExtensionConfiguration API
0%
Description
Hello,
the ExtensionConfiguration is not written correctly in v11 when using the API.
If I use this example
$extensionConfiguration = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Configuration\ExtensionConfiguration::class);
$extensionConfiguration->set('myext', 'myvar', 'myvalue');
The result in the LocalConfiguration is wrong and even the installtool stops working.
The result looks like:
...
'EXTENSIONS' => [
'myext' => 'myvar'
],
...
This however works as intended
$extensionConfiguration = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Configuration\ExtensionConfiguration::class);
$GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['myext']['myvar'] = 'myvalue';
$extensionConfiguration->setAll($GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']);
The result looks like:
...
'EXTENSIONS' => [
'myext' => [
'myvar' => 'myvalue'
],
],
...
Updated by Johannes Nielsen almost 2 years ago
I do not think, the method is supposed to be called like that. The function signature and the doc block (https://github.com/TYPO3/typo3/blob/v11.5.27/typo3/sysext/core/Classes/Configuration/ExtensionConfiguration.php#L127) suggest it should be called like this:
$extensionConfiguration->set('myext', ['myvar' => 'myvalue']);
resulting in
...
'EXTENSIONS' => [
'myext' => [
'myvar' => 'myvalue'
],
],
...
If you need to keep existing values in the extension's settings, this might work (note, however, that this might throw an exception if the extension has no configuration):
$extensionConfiguration->set(
'myext',
array_merge(
$extensionConfiguration->get('myext'),
['myvar' => 'myvalue']
)
);
resulting in
...
'EXTENSIONS' => [
'myext' => [
// ... whatever was set here before
'myvar' => 'myvalue'
],
],
...
Updated by Susanne Moog over 1 year ago
Please note that `set` is explicitly marked as internal and should not be called in an extension.
If you want to provide extension configuration, you should usually use https://docs.typo3.org/m/typo3/reference-coreapi/11.5/en-us/ExtensionArchitecture/FileStructure/ExtConfTemplate.html
Updated by Franz Holzinger over 1 year ago
The Core PHP Code ExtensionConfiguration.php also says:
"This API is however OK to be called from extension manager hooks."
Updated by Katharina Strasser over 1 year ago
The ext_conf_template.txt was insufficient in this case. The customer needed a solution to set configuration variables from within the extension via a simple form (without access to the entire Typo3 System as an editor-user). Therefore $extensionConfiguration->setAll was choosen.
For example updating an E-Mail address for cronjobs.
But I think this issue can be closed because I used the wrong signature of the set method.
Updated by Benni Mack about 1 year ago
- Status changed from New to Closed
Closing the ticket as suggested by the author of the issue.