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¶
<?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);
}
}
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/
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 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
- getJavaScriptModules ( ) ¶
-
- Returns
-
string
[]