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
Registration of the event listener in the extension's Services.
:
services:
# Place here the default dependency injection configuration
MyVendor\MyExtension\UserSettings\EventListener\MyEventListener:
tags:
- name: event.listener
identifier: 'my-extension/my-event-listener'
Read how to configure dependency injection in extensions.
The corresponding event listener class:
<?php
declare(strict_types=1);
namespace MyVendor\MyExtension\UserSettings\EventListener;
use TYPO3\CMS\Setup\Event\AddJavaScriptModulesEvent;
final 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);
}
}
API
- class AddJavaScriptModulesEvent
-
- Fully qualified name
-
\TYPO3\
CMS\ Setup\ Event\ Add Java Script Modules Event
Collects additional JavaScript modules to be loaded in SetupModuleController.
- addJavaScriptModule ( string $specifier)
-
- param $specifier
-
Bare module identifier like @my/package/filename.js