Project

General

Profile

Actions

Bug #98081

closed

ExtensionConfiguration API

Added by Katharina Strasser over 1 year ago. Updated 3 months ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
-
Target version:
-
Start date:
2022-08-05
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
11
PHP Version:
7.4
Tags:
Complexity:
Is Regression:
Sprint Focus:

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'
        ],
],
...

Actions #1

Updated by Johannes Nielsen 12 months 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'
        ],
],
...

Actions #2

Updated by Susanne Moog 10 months 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

Actions #3

Updated by Franz Holzinger 10 months ago

The Core PHP Code ExtensionConfiguration.php also says:

"This API is however OK to be called from extension manager hooks."
Actions #4

Updated by Katharina Strasser 10 months 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.

Actions #5

Updated by Benni Mack 3 months ago

  • Status changed from New to Closed

Closing the ticket as suggested by the author of the issue.

Actions

Also available in: Atom PDF