SiteConfigurationLoadedEvent
The PSR-14 event
\TYPO3\
allows the modification of the site configuration array
before loading the configuration.
Note
If you need to change the configuration before it is saved to disk, use SiteConfigurationBeforeWriteEvent.
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.
<?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);
}
}
For more sophisticated examples, see also Automatically register route enhancer definitions stored in TYPO3 extensions.
New in version 13.0
The PHP attribute
\TYPO3\
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.