Manual:Hooks/SidebarBeforeOutput
SidebarBeforeOutput | |
---|---|
Available from version 1.24.0 Called at the end of Skin::buildSidebar(), done to be used in order to alter the sidebar content just before the display | |
Define function: | public static function onSidebarBeforeOutput( Skin $skin, &$sidebar ) { ... }
|
Attach hook: | In extension.json:
{
"Hooks": {
"SidebarBeforeOutput": "MediaWiki\\Extension\\MyExtension\\Hooks::onSidebarBeforeOutput"
}
}
|
Called from: | File(s): skins/Skin.php |
Interface: | SidebarBeforeOutputHook.php |
For more information about attaching hooks, see Manual:Hooks .
For examples of extensions using this hook, see Category:SidebarBeforeOutput extensions.
Details
[edit]$skin
: Skin object&$sidebar
: Sidebar contents, in the same format as SkinBuildSidebar
Modify $sidebar
to add or modify sidebar portlets.
Warning: You should probably use SkinBuildSidebar instead, in order to use the caching system. This hook is run on each display and should only be used if the contents of the sidebar vary on a per-request basis (e.g. Extension:DynamicSidebar).
Caveats
[edit]Currently languages and toolbox menus are available for modification in this hook, however whether they display or not will be determined by the skin that is rendering.
More information can be found in task T253783.
Examples
[edit]The following example allows you to add a new menu to the sidebar:
$wgHooks['SidebarBeforeOutput'][] = function ( $skin, &$bar ) {
# note: heading can be either a message key. If no message exists it will be treated as a plain text.
$heading = 'msg-heading';
$bar[ $heading ] = [
[
'msg' => 'my-label-message',
'href' => '//example.com'
]
];
};
To add a new menu
$wgHooks['SidebarBeforeOutput'][] = function ( Skin $skin, &$sidebar ) {
foreach ( $sidebar as $key => $data ) {
$sidebar[$key][] = [
"text" => "SidebarBeforeOutput link",
"href" => '#SidebarBeforeOutputLocalSettings.php',
];
}
};
If you want append a single item in the default 'toolbox' section, use 'TOOLBOX' string as the array key
$wgHooks['SidebarBeforeOutput'][] = function ( Skin $skin, &$sidebar ) {
$sidebar['TOOLBOX'][] = [
"text" => "My custom label",
"href" => '#SidebarBeforeOutputLocalSettings.php',
];
};