SiteConfigurationLoadedEvent

The PSR-14 event \TYPO3\CMS\Core\Configuration\Event\SiteConfigurationLoadedEvent allows the modification of the site configuration array before loading the configuration.

Example

The example adds a route enhancer configuration provided by an extension with an event listener automatically. This way, there is no need to add an import manually to the site configuration.

EXT:my_extension/Classes/Configuration/EventListener/ImportRoutesIntoSiteConfiguration.php
<?php

declare(strict_types=1);

namespace MyVendor\MyExtension\Configuration\EventListener;

use TYPO3\CMS\Core\Attribute\AsEventListener;
use TYPO3\CMS\Core\Configuration\Event\SiteConfigurationLoadedEvent;
use TYPO3\CMS\Core\Configuration\Loader\YamlFileLoader;

#[AsEventListener(
    identifier: 'my-extension/import-routes-into-site-configuration',
)]
final readonly class ImportRoutesIntoSiteConfiguration
{
    private const ROUTES = 'EXT:my_extension/Configuration/Routes/Routes.yaml';

    public function __construct(
        private YamlFileLoader $yamlFileLoader,
    ) {}

    public function __invoke(SiteConfigurationLoadedEvent $event): void
    {
        $routeConfiguration = $this->yamlFileLoader->load(self::ROUTES);

        $configuration = array_merge_recursive(
            $event->getConfiguration(),
            $routeConfiguration,
        );

        $event->setConfiguration($configuration);
    }
}
Copied!

For more sophisticated examples, see also Automatically register route enhancer definitions stored in TYPO3 extensions.

New in version 13.0

The PHP attribute \TYPO3\CMS\Core\Attribute\AsEventListener has been introduced to tag a PHP class as an event listener. Alternatively, or if you need to be compatible with older TYPO3 versions, you can also register an event listener via the Configuration/Services.yaml file. Switch to an older version of this page for an example or have a look at the section Implementing an event listener in your extension.

API

class SiteConfigurationLoadedEvent
Fully qualified name
\TYPO3\CMS\Core\Configuration\Event\SiteConfigurationLoadedEvent

Event after a site configuration has been read from a yaml file before it is cached - allows dynamic modification of the site's configuration.

getSiteIdentifier ( )
Returns
string
getConfiguration ( )
Returns
array
setConfiguration ( array $configuration)
param $configuration

overwrite the configuration array of the site