AddJavaScriptModulesEvent

JavaScript events in custom user settings configuration options should not be placed as inline JavaScript. Instead, use a dedicated JavaScript module to handle custom events.

Example

EXT:my_extension/Classes/UserSettings/EventListener/MyEventListener.php
<?php

declare(strict_types=1);

namespace MyVendor\MyExtension\UserSettings\EventListener;

use TYPO3\CMS\Core\Attribute\AsEventListener;
use TYPO3\CMS\Setup\Event\AddJavaScriptModulesEvent;

#[AsEventListener(
    identifier: 'my-extension/my-event-listener',
)]
final readonly class MyEventListener
{
    // The name of JavaScript module to be loaded
    private const MODULE_NAME = 'TYPO3/CMS/MyExtension/CustomUserSettingsModule';

    public function __invoke(AddJavaScriptModulesEvent $event): void
    {
        if (in_array(self::MODULE_NAME, $event->getModules(), true)) {
            return;
        }
        $event->addModule(self::MODULE_NAME);
    }
}
Copied!

New in version 13.0

API

class AddJavaScriptModulesEvent
Fully qualified name
\TYPO3\CMS\Setup\Event\AddJavaScriptModulesEvent

Collects additional JavaScript modules to be loaded in SetupModuleController.

addJavaScriptModule ( string $specifier)
param $specifier

Bare module identifier like @my/package/filename.js

getJavaScriptModules ( )
Returns
string[]