Feature: #99717 - New PSR-14 ModifyBlindedConfigurationOptionsEvent

See forge#99717

Description

A new PSR-14 event \TYPO3\CMS\Lowlevel\Event\ModifyBlindedConfigurationOptionsEvent has been introduced which serves as a direct replacement for the now deprecated hook $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['TYPO3\CMS\Lowlevel\Controller\ConfigurationController']['modifyBlindedConfigurationOptions'] .

The new PSR-14 event is fired in the \TYPO3\CMS\Lowlevel\ConfigurationModuleProvider\GlobalVariableProvider and the \TYPO3\CMS\Lowlevel\ConfigurationModuleProvider\SitesYamlConfigurationProvider , while building the corresponding configuration array, which should be displayed in the Configuration module. The event therefore allows to blind (hide) any of those configuration options. Usually, such options are passwords or any other sensitive information.

Using the ModifyBlindedConfigurationOptionsEvent::getProviderIdentifier() method, listeners are able to determine the context, the event got dispatched in. This is useful to prevent duplicate code execution, since the event is dispatched for multiple providers. The method returns the identifier of the configuration provider as registered in the service configuration.

Example

Registration of the ModifyBlindedConfigurationOptionsEvent in your extension's Services.yaml:

EXT:my_extension/Configuration/Services.yaml
MyVendor\MyExtension\Backend\MyEventListener:
  tags:
    - name: event.listener
      identifier: 'my-extension/blind-configuration-options'
Copied!

The corresponding event listener class:

EXT:my_extension/Classes/Backend/MyEventListener.php
namespace MyVendor\MyExtension\Backend;

use TYPO3\CMS\Lowlevel\ConfigurationModuleProvider\GlobalVariableProvider;
use TYPO3\CMS\Lowlevel\ConfigurationModuleProvider\SitesYamlConfigurationProvider;
use TYPO3\CMS\Lowlevel\Event\ModifyBlindedConfigurationOptionsEvent;

final class MyEventListener {
    public function __invoke(ModifyBlindedConfigurationOptionsEvent $event): void
    {
        $blindedConfigurationOptions = $event->getBlindedConfigurationOptions();

        if ($event->getProviderIdentifier() === 'sitesYamlConfiguration') {
            $blindedConfigurationOptions['my-site']['settings']['apiKey'] = '***';
        } elseif ($event->getProviderIdentifier() === 'confVars') {
            $blindedConfigurationOptions['TYPO3_CONF_VARS']['EXTENSIONS']['my_extension']['password'] = '******';
        }

        $event->setBlindedConfigurationOptions($blindedConfigurationOptions);
    }
}
Copied!

Impact

With the new ModifyBlindedConfigurationOptionsEvent, it is now possible to modify global configuration options as well as site configuration options, displayed in the Configuration module.

The event might be triggered by more configuration providers in the future.