Manual:Hooks/ResourceLoaderGetConfigVars/de

From mediawiki.org
This page is a translated version of the page Manual:Hooks/ResourceLoaderGetConfigVars and the translation is 27% complete.
ResourceLoaderGetConfigVars
Erhältlich ab Version 1.17.0
Called right before ResourceLoaderStartUpModule::getConfig returns, to set static (not request-specific) configuration variables. Can not depend on current page, current user or current request; see below.
Funktion definieren:
public static function onResourceLoaderGetConfigVars( array &$vars, string $skin, Config $config ) { ... }
Haken anbringen: In extension.json:
{
	"Hooks": {
		"ResourceLoaderGetConfigVars": "MyExtensionHooks::onResourceLoaderGetConfigVars"
	}
}
Angerufen von: Datei(en): resourceloader/ResourceLoaderStartUpModule.php
Interface: ResourceLoaderGetConfigVarsHook.php

For more information about attaching hooks, see Handbuch:Hooks .
For examples of extensions using this hook, see Category:ResourceLoaderGetConfigVars extensions/de.

Details

ResourceLoaderStartUpModule::getConfig() runs this hook. Use it to export static configuration variables to JavaScript. Values that depend on the current page, user or request state must be added through MakeGlobalVariablesScript instead.

  • &$vars - Array of variables to be added into the output of the startup module.
  • $skin - (eingeführt in 1.32) Current skin name to restrict config variables to a certain skin (if needed)
  • $config - (eingeführt in 1.34)

Beispiel

Register the configuration variables from the hook:

class VisualEditorHooks {
	public static function onResourceLoaderGetConfigVars( array &$vars, string $skin, Config $config ) {
		$vars['wgVisualEditor'] = [
			'disableForAnons' => $config->get( 'VisualEditorDisableForAnons' ),
			'enableExperimentalCode' => $config->get( 'VisualEditorEnableExperimentalCode' ),
		];

		return true;
	}
}

Retrieve them using mw.config , like:

conf = mw.config.get( 'wgVisualEditor' );
if ( conf.disableForAnons ) {
	// Do stuff
}

Siehe auch