Manual:Hooks/ResourceLoaderRegisterModules
ResourceLoaderRegisterModules | |
---|---|
Available from version 1.17.0 Allows conditionally registering of modules with ResourceLoader | |
Define function: | public static function onResourceLoaderRegisterModules( ResourceLoader $resourceLoader ) { ... }
|
Attach hook: | In extension.json:
{
"Hooks": {
"ResourceLoaderRegisterModules": "MediaWiki\\Extension\\MyExtension\\Hooks::onResourceLoaderRegisterModules"
}
}
|
Called from: | File(s): includes/ServiceWiring.php |
Interface: | ResourceLoaderRegisterModulesHook.php |
For more information about attaching hooks, see Manual:Hooks .
For examples of extensions using this hook, see Category:ResourceLoaderRegisterModules extensions.
Details
[edit]- $resourceLoader - The ResourceLoader object.
Usage
[edit]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.
See also
- ResourceLoader
$wgResourceModules
- Register modules that can later be loaded on a page$wgResourceModuleSkinStyles
- Register skin-provided stylesheets to add to an existing ResourceLoader module$wgResourceLoaderDebug
- Configure the default debug mode for MediaWiki.- Internal configuration settings:
$wgExtensionAssetsPath
,$wgResourceLoaderMaxage
- ResourceLoaderRegisterModules hook
- Developing with ResourceLoader â Learn how to use ResourceLoader in MediaWiki