Manual:Hooks/ResourceLoaderRegisterModules
ResourceLoaderRegisterModules | |
---|---|
<translate> Available from <tvar name=1><translate> version <tvar </tvar></translate> Allows conditionally registering of modules with ResourceLoader | |
<translate> Define function:</translate> | public static function onResourceLoaderRegisterModules( ResourceLoader $resourceLoader ) { ... }
|
<translate> Attach hook:</translate> | <translate> In <tvar name=1>extension.json</tvar>:</translate>
{
"Hooks": {
"ResourceLoaderRegisterModules": "MediaWiki\\Extension\\MyExtension\\Hooks::onResourceLoaderRegisterModules"
}
}
|
<translate> Called from:</translate> | <translate> File(s):</translate> includes/ServiceWiring.php |
<translate> Interface:</translate> | ResourceLoaderRegisterModulesHook.php |
<translate> For more information about attaching hooks, see <tvar name=1>Manual:Hooks </tvar>.</translate>
<translate> For examples of extensions using this hook, see <tvar name=cat>Category:ResourceLoaderRegisterModules extensions</tvar>.</translate>
Details
- $resourceLoader - The ResourceLoader object.
Usage
ResourceLoaderModule objects, which provide access to scripts, styles, and messages can be added to the ResourceLoader at this point. A common use case is registering a resource with "soft" dependencies on other extensions and classes. For example, a module can depend on an EventLogging schema only if EventLogging is installed. Using this hook allows adding to the dependencies array conditionally before registering the module. For a single registration:
$resourceLoader->register( 'myModule', [ 'scripts' => '...' ] );
You can pass in an array of 'script', 'styles', 'localBasePath', etc. as you do when appending an item to $wgResourceModules.
For multiple registrations:
$resourceLoader->register( array( 'myModule' => [ 'scripts' => '...' ], ... ) );
Note that for MW 1.26 and later, you can not modify $wgResourceModules using this hook listener.