ModifyLoadedPageTsConfigEvent

Extensions can modify page TSconfig entries that can be overridden or added, based on the root line.

Changed in version 12.2

The event has moved its namespace from \TYPO3\CMS\Core\Configuration\Event\ModifyLoadedPageTsConfigEvent to \TYPO3\CMS\Core\TypoScript\IncludeTree\Event\ModifyLoadedPageTsConfigEvent. Apart from that no changes were made. TYPO3 v12 triggers both the old and the new event, and TYPO3 v13 will stop calling the old event. See also Compatibility with TYPO3 v11 and v12.

API

class \TYPO3\CMS\Core\TypoScript\IncludeTree\Event\ ModifyLoadedPageTsConfigEvent

Extensions can modify page TSconfig entries that can be overridden or added, based on the root line

getTsConfig ( )
returntype

array

addTsConfig ( string $tsConfig)
param string $tsConfig

the tsConfig

setTsConfig ( array $tsConfig)
param array $tsConfig

the tsConfig

getRootLine ( )
returntype

array

Compatibility with TYPO3 v11 and v12

Extensions that want to stay compatible with both TYPO3 v11 and v12 and prepare v13 compatibility as much as possible should start listening for the new event as well, and suppress handling of the old event in TYPO3 v12 to not handle things twice.

Example from b13/bolt extension:

Registration of both events in the file Services.yaml:

EXT:bolt/Configuration/Services.yaml
services:
  # Place here the default dependency injection configuration

  B13\Bolt\TsConfig\Loader:
    public: true
    tags:
      # Remove when TYPO3 v11 compat is dropped
      - name: event.listener
        identifier: 'add-site-configuration-v11'
        event: TYPO3\CMS\Core\Configuration\Event\ModifyLoadedPageTsConfigEvent
        method: 'addSiteConfigurationCore11'
      # TYPO3 v12 and above
      - name: event.listener
        identifier: 'add-site-configuration'
        event: TYPO3\CMS\Core\TypoScript\IncludeTree\Event\ModifyLoadedPageTsConfigEvent
        method: 'addSiteConfiguration'
Copied!

Read how to configure dependency injection in extensions.

Handle the old event in TYPO3 v11 only, but skip old event with TYPO3 v12:

EXT:bolt/Classes/TsConfig/Loader.php
<?php

declare(strict_types=1);

namespace B13\Bolt\TsConfig;

use TYPO3\CMS\Core\Configuration\Event\ModifyLoadedPageTsConfigEvent as LegacyModifyLoadedPageTsConfigEvent;
use TYPO3\CMS\Core\TypoScript\IncludeTree\Event\ModifyLoadedPageTsConfigEvent;

class Loader
{
    public function addSiteConfigurationCore11(LegacyModifyLoadedPageTsConfigEvent $event): void
    {
        if (class_exists(ModifyLoadedPageTsConfigEvent::class)) {
            // TYPO3 v12 calls both old and new event. Check for class existence of new event to
            // skip handling of old event in v12, but continue to work with < v12.
            // Simplify this construct when v11 compat is dropped, clean up Services.yaml.
            return;
        }
        $this->findAndAddConfiguration($event);
    }

    public function addSiteConfiguration(ModifyLoadedPageTsConfigEvent $event): void
    {
        $this->findAndAddConfiguration($event);
    }

    protected function findAndAddConfiguration($event): void
    {
        // Business code
    }
}
Copied!

See the complete code on GitHub: Loader.php.